https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97132
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to Jakub Jelinek from comment #2) > I think there is no compliant way to test alignment assumptions during > constant evaluations and after all, one should always see the actual objects > and therefore can check the exact alignment, rather than needing any > assumptions. Right, during CE unaligned objects are UB anyway and not allowed. And the function is only supposed to benefit the optimiser, which isn't relevant during CE. > So, I think it doesn't really matter if this is done on the libstdc++ say > through not using __builtin_assume_aligned if std::is_constant_evaluated() > or on the C++ FE side (folding __builtin_assume_aligned to the first > argument during manifestly constant evaluation). I'll test this: { static_assert(std::has_single_bit(_Align)); _GLIBCXX_DEBUG_ASSERT((std::uintptr_t)__ptr % _Align == 0); - return static_cast<_Tp*>(__builtin_assume_aligned(__ptr, _Align)); + if (std::is_constant_evaluated()) + return __ptr; + else + return static_cast<_Tp*>(__builtin_assume_aligned(__ptr, _Align)); } #endif // C++2a