https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115902
Bug ID: 115902 Summary: Can't call immediate function within "if consteval" when optimizing Product: gcc Version: 14.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: gcc at nospam dot scs.stanford.edu Target Milestone: --- When optimizing, g++ seems to try calling immediate functions inside "if consteval" and then reject what should be valid code. Here is a simple example (which I place in the public domain): ``` // g++ -std=c++23 -c -O2 consteval.cc consteval int plusone(int n) { return n + 1; } constexpr int maybeplusone(int n) { if consteval { return plusone(n); } else { return n; } } int not_consteval() { return maybeplusone(1); } ``` It gives the following error: ``` $ g++ -std=c++23 -c -O2 consteval.cc consteval.cc: In function 'int not_consteval()': consteval.cc:23:22: in 'constexpr' expansion of 'maybeplusone(1)' consteval.cc:13:19: error: call to consteval function 'plusone(n)' is not a constant expression 13 | return plusone(n); | ~~~~~~~^~~ consteval.cc:13:20: error: 'n' is not a constant expression 13 | return plusone(n); | ^ $ ``` The code compiles fine without optimization, and also works with clang 18.