Skip to content

Fix std::set for InvalidatableFile in C++20 - #1941

Merged
ax3l merged 4 commits into
openPMD:devfrom
dpgrote:InvalidatableFile_comparison
Sep 15, 2026
Merged

ax3l merged 4 commits into
openPMD:devfrom
dpgrote:InvalidatableFile_comparison

Conversation

@dpgrote

@dpgrote dpgrote commented Sep 14, 2026

Copy link
Copy Markdown
Member

This is needed by AppleClang 21.0.0 to avoid the compiler error shown below. Since InvalidatableFile is used in a std::set, the compiler now requires the comparison operators to be defined for it. The C++20 standard way of doing this is the spaceship operator, <=>. Needs a comparison operator. With the change in this PR, the compilation (of WarpX) is successful.

In file included from /Users/grote1/packages/openPMD-api/src/IO/ADIOS/ADIOS2IOHandler.cpp:23:
In file included from /Users/grote1/packages/openPMD-api/include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp:25:
In file included from /Users/grote1/packages/openPMD-api/include/openPMD/IO/ADIOS/ADIOS2Auxiliary.hpp:25:
In file included from /Users/grote1/packages/openPMD-api/include/openPMD/IO/ADIOS/macros.hpp:27:
In file included from /opt/homebrew/include/adios2.h:11:
In file included from /opt/homebrew/include/adios2/common/ADIOSMacros.h:12:
In file included from /opt/homebrew/include/adios2/common/ADIOSTypes.h:16:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/map:602:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__tree:42:
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__utility/lazy_synth_three_way_comparator.h:45:21: error: no matching function for call to object of type 'const std::less<void>'

Comment thread include/openPMD/IO/InvalidatableFile.hpp Outdated
@ax3l ax3l added the internal label Sep 14, 2026
Codex suggestion
@ax3l ax3l changed the title Add spaceship operator for InvalidatableFile Fix std::set for InvalidatableFile in C++20 Sep 14, 2026
@ax3l
ax3l requested a review from franzpoeschel September 14, 2026 21:57
@ax3l

ax3l commented Sep 14, 2026

Copy link
Copy Markdown
Member

@dpgrote does the change I pushed work for you, too?

@dpgrote

dpgrote commented Sep 14, 2026

Copy link
Copy Markdown
Member Author

@dpgrote does the change I pushed work for you, too?

Yes, this works, WarpX compiles successfully.

@franzpoeschel franzpoeschel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit surprised why your build system decided to compile openPMD-api with the C++20 standard. This missing definition should not matter for inclusion in a C++20 project; the openPMD-api itself can still be compiled with C++17.

Fixing this is simple enough though and we will move to C++20 at some point anyway, so we should go ahead with fixing this. The current state of the PR has two little issues. I will later push a commit with a fix, could you give it another test again then?

Comment thread include/openPMD/IO/InvalidatableFile.hpp Outdated
@ax3l

ax3l commented Sep 15, 2026

Copy link
Copy Markdown
Member

I am a bit surprised why your build system decided to compile openPMD-api with the C++20 standard.

Our CMake logic says in openPMD-api that we use C++17 or newer. So openPMd-api itself can be built with newer standards if the compiler supports it.

Additionally, if a downstream project used a newer C++ std then our public headers naturally will be parsed as such, too.


bool openPMD::InvalidatableFile::operator<(InvalidatableFile const &f) const
{
return operator*() < *f;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at InvalidatableFile::operator*() this sorts by name. ok!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, this does the same. I just wanted to avoid having two distinct implementations.

@ax3l ax3l left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! 👍

@dpgrote does this still compile with XCode & C++20 for you?

@ax3l
ax3l dismissed franzpoeschel’s stale review September 15, 2026 18:20

Self-implemented

@ax3l
ax3l requested a review from franzpoeschel September 15, 2026 18:21
@ax3l ax3l added the machine/system machine & HPC system specific issues label Sep 15, 2026
@ax3l
ax3l merged commit ff91610 into openPMD:dev Sep 15, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants