https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108052
Bug ID: 108052 Summary: forward-declared constexpr variable template unusable in constexpr context Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: webrown.cpp at gmail dot com Target Milestone: --- Similar to bug 59123, the following code compiles with no complaint: extern const double e; // a fwd-declaration constexpr double e = 2.71; // its corresponding def'n static_assert( e == 2.71 ); // verification But the following analogous, templatized, code...: template< class T > extern const T pi; // a fwd-declaration template< class T > constexpr T pi = 3.14; // its corresponding def'n static_assert( pi<double> == 3.14 ); // verification ... produces the following unexpected diagnostics: error: non-constant condition for static assertion error: the value of 'pi<double>' is not usable in a constant expression note: 'pi<double>' was not declared 'constexpr' ...when compiling with gcc version 13.0.0 20221122 and any of: -std=c++17, -std=c++20, or -std=c++23. However, further experimentation reveals that the following int variation of the above static_assert does compile (although an expected float-conversion warning is produced if enabled): template< class T > extern const T pi; // a fwd-declaration Finally, bug 92576 and bug 68012 seem tangentially related. template< class T > constexpr T pi = 3.14; // its corresponding def'n static_assert( pi<int> == 3 ); // verification A knowledgeable CWG colleague conjectures that the double-vs-int difference may be "somehow related to the special rule for 'const integral types' vs. 'constexpr any type'." Finally, bug 68012, bug 84255, and bug 92576 seem tangentially related, although these do not involve any extern declaration.