https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115171
Bug ID: 115171 Summary: Constant evaluation of math.h functions in C++ against constexpr.functions Product: gcc Version: 15.0 Status: UNCONFIRMED Keywords: accepts-invalid, rejects-valid, wrong-code Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: hstong at ca dot ibm.com Target Milestone: --- It appears GCC implements a non-conforming extension that results in failure to compile a well-formed program. In particular, https://wg21.link/constexpr.functions states that standard library functions are not to be made constexpr by implementations except where the Standard explicitly requires constexpr. Online compiler: https://godbolt.org/z/e8x5jhPMc ### SOURCE (<stdin>): ``` //#include <math.h> extern "C" double fmin(double, double); template <typename T> void f(T, char (*)[fmin(T{}, T{}) ? 1 : 2] = 0); constexpr bool f(int) { return true; } static_assert(f(0.)); ``` ### COMPILER INVOCATION: ``` g++ -fsyntax-only -std=c++20 -xc++ - ``` ### ACTUAL OUTPUT: ``` <stdin>:7:16: error: could not convert 'f<double>(0.0, 0)' from 'void' to 'bool' ``` ### EXPECTED OUTPUT: (Clean compile) ### COMPILER VERSION INFO (g++ -v): ``` Using built-in specs. COLLECT_GCC=/opt/wandbox/gcc-head/bin/g++ COLLECT_LTO_WRAPPER=/opt/wandbox/gcc-head/libexec/gcc/x86_64-pc-linux-gnu/15.0.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../source/configure --prefix=/opt/wandbox/gcc-head --enable-languages=c,c++ --disable-multilib --without-ppl --without-cloog-ppl --enable-checking=release --disable-nls --enable-lto LDFLAGS=-Wl,-rpath,/opt/wandbox/gcc-head/lib,-rpath,/opt/wandbox/gcc-head/lib64,-rpath,/opt/wandbox/gcc-head/lib32 Thread model: posix Supported LTO compression algorithms: zlib gcc version 15.0.0 20240520 (experimental) (GCC) ```