https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119150
Bug ID: 119150 Summary: Optimization causes function call arguments to consteval functions to not be manifestly constant-evaluated Product: gcc Version: 14.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: aapomeranz at yahoo dot com Target Milestone: --- #include <iostream> auto consteval CONSTEVAL(auto x) { return x; } constexpr bool isconstant() { return std::is_constant_evaluated(); } int main() { // Tested via godbolt.org using the following compilers/flags: // GCC x86-64 -std=c++20 (13.3.0, 14.1.0, and 15.0.1 20250306) // Clang x86-64 -std=c++20 (head) // MSVC x64 /std:c++20 (head) // Working case: // GCC (all tested versions), Clang, MSVC: prints 1 constexpr int n { CONSTEVAL(isconstant()) }; std::cout << n << '\n'; // Broken case: // Clang and MSVC: prints 1 // GCC: -Ox (when x == 0) prints 1 on GCC (all tested versions) // GCC: -Ox (when x != 0) prints 1 on GCC 13.3.0 // GCC: -Ox (when x != 0) prints 0 on GCC 14.1.0 and 15.0.1 20250306 std::cout << CONSTEVAL(isconstant()) << '\n'; return 0; }