https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80783
Bug ID: 80783 Summary: Inconsistent constexpr diagnostic for some cstdlib functions Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: victor.nawothnig at gmail dot com Target Milestone: --- A set of functions from cstdlib suffers from incorrect constexpr diagnostic "call to non-constexpr function" #include <cstdlib> constexpr size_t f() { exit(0); return 1; } /* Bad: Silently compiles */ When f() is being evaluated in a constant expression, the diagnostic properly triggers again, this reduces the impact of this bug: #include <cstdlib> constexpr size_t f() { exit(0); return 1; } int arr[f()]; /* Good: triggers diagnostic */ Interestingly the error seems to be tied to specific function signatures, rather than the standard library headers. Given the following (without including any headers): extern "C" void free(int); constexpr void f() { free(0); } /* Good: triggers diagnostic, free has a non-standard signature */ extern "C" void free(void *); constexpr void f() { free(0); } /* Bad: silently compiles, free has a standard signature */ It also is limited to only a particular set of cstdlib functionsincluding but not limited to: free, malloc, exit, atoi. I have not found any other affected headers yet, but I did not do an exhaustive search.