https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116646
Bug ID: 116646 Summary: Compilation of code inside if constexpr with failed condition. Product: gcc Version: 12.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: cas43 at cs dot stanford.edu Target Milestone: --- When compiling the following code (g++ -std=c++20 file.cpp): static const int y=0; void f() {if constexpr(y<0){static_assert(y<0);}} I expect no errors, but I get the following diagnostic with gcc version 12.3.0 (Ubuntu 12.3.0-1ubuntu1~22.04): a.cpp: In function ‘void f()’: a.cpp:2:44: error: static assertion failed 2 | void f() {if constexpr(y<0){static_assert(y<0);}} | ~^~ a.cpp:2:44: note: the comparison reduces to ‘(0 < 0)’ I get similar diagnostics with every compiler I have ready access to: gcc version 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04) gcc version 10.5.0 (Ubuntu 10.5.0-1ubuntu1~22.04) Ubuntu clang version 15.0.7 Ubuntu clang version 14.0.0-1ubuntu1.1 Ubuntu clang version 13.0.1-2ubuntu2.2 Ubuntu clang version 12.0.1-19ubuntu3 Ubuntu clang version 11.1.0-6 This suggests a mistake in my own code, but I don't see it. My understanding is that the "if constexpr" should fail and prevent compilation within its body. Declaring y as "static constexpr" still fails. The static_assert can be replaced with other types of errors, such as a call to a function call that fails to match.