Skip to content

C++20#6606

Merged
ax3l merged 7 commits intoBLAST-WarpX:developmentfrom
ax3l:topic-cxx20
Apr 24, 2026
Merged

C++20#6606
ax3l merged 7 commits intoBLAST-WarpX:developmentfrom
ax3l:topic-cxx20

Conversation

@ax3l
Copy link
Copy Markdown
Member

@ax3l ax3l commented Feb 24, 2026

Switch to C++20. AMReX is making the switch soon (AMReX-Codes/amrex#4840) and is preparing CI in AMReX-Codes/amrex#4976 so we can also generally pull up the requirements.

@ax3l ax3l requested a review from a team February 24, 2026 07:30
@ax3l ax3l added the install label Feb 24, 2026
Comment thread Docs/source/install/dependencies.rst Outdated
Comment thread Docs/source/developers/faq.rst Outdated
@ax3l
Copy link
Copy Markdown
Member Author

ax3l commented Feb 24, 2026

GCC 12 in C++20 mode might have a false positive here (cc @lucafedeli88 ?):

                 from /home/runner/work/warpx/warpx/Source/ablastr/utils/TextMsg.H:11,
                 from /home/runner/work/warpx/warpx/Source/ablastr/utils/TextMsg.cpp:8:
In static member function ‘static constexpr std::char_traits<char>::char_type* std::char_traits<char>::copy(char_type*, const char_type*, std::size_t)’,
    inlined from ‘static constexpr void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_S_copy(_CharT*, const _CharT*, size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:431:21,
    inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Allocator>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_replace(size_type, size_type, const _CharT*, size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ at /usr/include/c++/12/bits/basic_string.tcc:532:22,
    inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::replace(size_type, size_type, const _CharT*, size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:2179:19,
    inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::insert(size_type, const _CharT*) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:1936:22,
    inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const _CharT*, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&) [with _CharT = char; _Traits = char_traits<char>; _Alloc = allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:3549:36,
    inlined from ‘void ablastr::utils::TextMsg::Assert(const char*, const char*, int, const std::string&)’ at /home/runner/work/warpx/warpx/Source/ablastr/utils/TextMsg.cpp:79:38:
/usr/include/c++/12/bits/char_traits.h:435:56: error: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ accessing 9223372036854775810 or more bytes at offsets [2, 9223372036854775807] and 1 may overlap up to 9223372036854775813 bytes at offset -3 [-Werror=restrict]
  435 |         return static_cast<char_type*>(__builtin_memcpy(__s1, __s2, __n));
      |                                        ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~

@RemiLehe RemiLehe changed the title C++20 [WIP] C++20 Feb 24, 2026
@lucafedeli88
Copy link
Copy Markdown
Member

GCC 12 in C++20 mode might have a false positive here (cc @lucafedeli88 ?):

                 from /home/runner/work/warpx/warpx/Source/ablastr/utils/TextMsg.H:11,
                 from /home/runner/work/warpx/warpx/Source/ablastr/utils/TextMsg.cpp:8:
In static member function ‘static constexpr std::char_traits<char>::char_type* std::char_traits<char>::copy(char_type*, const char_type*, std::size_t)’,
    inlined from ‘static constexpr void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_S_copy(_CharT*, const _CharT*, size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:431:21,
    inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Allocator>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_replace(size_type, size_type, const _CharT*, size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ at /usr/include/c++/12/bits/basic_string.tcc:532:22,
    inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::replace(size_type, size_type, const _CharT*, size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:2179:19,
    inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::insert(size_type, const _CharT*) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:1936:22,
    inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const _CharT*, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&) [with _CharT = char; _Traits = char_traits<char>; _Alloc = allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:3549:36,
    inlined from ‘void ablastr::utils::TextMsg::Assert(const char*, const char*, int, const std::string&)’ at /home/runner/work/warpx/warpx/Source/ablastr/utils/TextMsg.cpp:79:38:
/usr/include/c++/12/bits/char_traits.h:435:56: error: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ accessing 9223372036854775810 or more bytes at offsets [2, 9223372036854775807] and 1 may overlap up to 9223372036854775813 bytes at offset -3 [-Werror=restrict]
  435 |         return static_cast<char_type*>(__builtin_memcpy(__s1, __s2, __n));
      |                                        ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~

ah, that's really weird...

@lucafedeli88
Copy link
Copy Markdown
Member

GCC 12 in C++20 mode might have a false positive here (cc @lucafedeli88 ?):

                 from /home/runner/work/warpx/warpx/Source/ablastr/utils/TextMsg.H:11,
                 from /home/runner/work/warpx/warpx/Source/ablastr/utils/TextMsg.cpp:8:
In static member function ‘static constexpr std::char_traits<char>::char_type* std::char_traits<char>::copy(char_type*, const char_type*, std::size_t)’,
    inlined from ‘static constexpr void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_S_copy(_CharT*, const _CharT*, size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:431:21,
    inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Allocator>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_replace(size_type, size_type, const _CharT*, size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ at /usr/include/c++/12/bits/basic_string.tcc:532:22,
    inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::replace(size_type, size_type, const _CharT*, size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:2179:19,
    inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::insert(size_type, const _CharT*) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:1936:22,
    inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const _CharT*, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&) [with _CharT = char; _Traits = char_traits<char>; _Alloc = allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:3549:36,
    inlined from ‘void ablastr::utils::TextMsg::Assert(const char*, const char*, int, const std::string&)’ at /home/runner/work/warpx/warpx/Source/ablastr/utils/TextMsg.cpp:79:38:
/usr/include/c++/12/bits/char_traits.h:435:56: error: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ accessing 9223372036854775810 or more bytes at offsets [2, 9223372036854775807] and 1 may overlap up to 9223372036854775813 bytes at offset -3 [-Werror=restrict]
  435 |         return static_cast<char_type*>(__builtin_memcpy(__s1, __s2, __n));
      |                                        ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~

ah, that's really weird...

I've tried compiling this branch on my machine (GCC 15.2.0) and the issue does not show up. So it may be a false positive.

@lucafedeli88
Copy link
Copy Markdown
Member

@ax3l , I am increasingly convinced that the g++12 warning is a false positive (see google/googletest#4570). Maybe we can write a workaround if we need to use that version of the compiler. FYI, with v12.5.0 I don't see the issue on my machine. Which specific version of g++ are you using ?

@ax3l ax3l requested a review from WeiqunZhang March 31, 2026 04:04
@ax3l ax3l changed the title [WIP] C++20 C++20 Mar 31, 2026
@WeiqunZhang
Copy link
Copy Markdown
Member

I think for the failed cuda checks, we just need to switch from 11.7 to 12.2.

@EZoni EZoni mentioned this pull request Apr 22, 2026
1 task
Comment thread .github/workflows/dependencies/nvcc.sh Outdated
@ax3l ax3l changed the title C++20 C++20 CI Apr 23, 2026
@ax3l ax3l changed the title C++20 CI C++20 Apr 23, 2026
ax3l and others added 4 commits April 23, 2026 10:44
Switch to C++20. AMReX is making the switch so we can also generally
pull up the requirements.
Comment thread CMakeLists.txt
Comment on lines 221 to +224
# Old GCCs: std::filesystem as a separate library
try_compile(CXX_HAS_STD_FS "${WarpX_BINARY_DIR}/temp"
"${WarpX_SOURCE_DIR}/cmake/has_filesystem.cpp"
CMAKE_FLAGS -DCMAKE_CXX_STANDARD=17 -DCMAKE_CXX_STANDARD_REQUIRED=ON
CMAKE_FLAGS -DCMAKE_CXX_STANDARD=20 -DCMAKE_CXX_STANDARD_REQUIRED=ON
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The old GCC we supported here does probably not support C++20 anyway. But we can remove this another time, does not hurt.

Comment thread CMakeLists.txt
endforeach()
foreach(warpx_tgt IN LISTS _ALL_TARGETS)
target_compile_features(${warpx_tgt} PUBLIC cuda_std_17)
target_compile_features(${warpx_tgt} PUBLIC cuda_std_20)
Copy link
Copy Markdown
Member Author

@ax3l ax3l Apr 23, 2026

Choose a reason for hiding this comment

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

Probably worth bumping minimum CMake eventually:

Image (Source: Google/Gemini. Might need validation when we act on it.)

Co-authored-by: Edoardo Zoni <ezoni@lbl.gov>
Comment thread Docs/source/install/dependencies.rst
@EZoni
Copy link
Copy Markdown
Member

EZoni commented Apr 23, 2026

@lucafedeli88

After merging the Adastra update from #6591, we need to re-update it here (see merge conflict). Do you want to test it manually first or can we go ahead with updating the script trivially?

@lucafedeli88
Copy link
Copy Markdown
Member

@lucafedeli88

After merging the Adastra update from #6591, we need to re-update it here (see merge conflict). Do you want to test it manually first or can we go ahead with updating the script trivially?

@EZoni , I should have fixed the merge conflict. I am 99.9% sure that it will work as it is. To be sure, I will test it tomorrow.

@lucafedeli88
Copy link
Copy Markdown
Member

@ax3l , this may be useful to fix the clang-tidy CI test : #6800 .

@lucafedeli88
Copy link
Copy Markdown
Member

@ax3l , I've ported my clang-tidy fix to your PR (see #6803) in order to test that everything is OK. Feel free to merge the changes in .clang-tidy , github/workflows/clang_tidy.yml, Docs/source/developers/how_to_run_clang_tidy.rst, and Tools/Linter/runClangTidy.sh into your PR.
In essence the changes are:

  • bump clang-tidy from v17 to v18 because the clang-diagnostic-unknown-pragmas issue that you are observing is a false positive. Updating the tool makes it go away.
  • disable the new checks in v18 and the checks relevant to C++20 (we may want to enable many of them in the future, but certainly not in this PR)
  • update the documentation and a tool to take the version change into account

@EZoni EZoni requested review from EZoni and lucafedeli88 April 24, 2026 16:23
Copy link
Copy Markdown
Member

@lucafedeli88 lucafedeli88 left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for this!

@ax3l
Copy link
Copy Markdown
Member Author

ax3l commented Apr 24, 2026

Thank you both for your help! 🎉 ✨

@ax3l ax3l enabled auto-merge (squash) April 24, 2026 17:07
@ax3l ax3l merged commit 44f7bc1 into BLAST-WarpX:development Apr 24, 2026
47 of 48 checks passed
@ax3l ax3l deleted the topic-cxx20 branch April 25, 2026 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants