// DR 2478 - Properties of explicit specializations of implicitly-instantiated class templates // { dg-do compile { target c++20 } } // Defeat -fimplicit-constexpr int ii; template struct S { int foo () { return ii; } constexpr int bar () { return 0; } int baz () { return ii; } consteval int qux () { return 0; } constexpr S () {} static constinit T x; static T y; }; template T S::x = S ().foo (); // { dg-error "'constinit' variable 'S::x' does not have a constant initializer" } // { dg-error "call to non-'constexpr' function|called in a constant expression" "" { target *-*-* } .-1 } template T S::y = S ().foo (); template <> constexpr int S::foo () { return 0; } template <> int S::bar () { return 0; } template <> consteval int S::baz () { return 0; } template <> int S::qux () { return 0; } template <> long S::x = S ().foo (); // { dg-bogus "'constinit' variable 'S::x' does not have a constant initializer" "" { xfail *-*-* } } // { dg-bogus "call to non-'constexpr' function|called in a constant expression" "" { xfail *-*-* } .-1 } template <> constinit long S::y = S ().foo (); // { dg-error "'constinit' variable 'S::y' does not have a constant initializer" } // { dg-error "call to non-'constexpr' function|called in a constant expression" "" { target *-*-* } .-1 } constinit auto a = S ().foo (); // { dg-error "'constinit' variable 'a' does not have a constant initializer" } // { dg-error "call to non-'constexpr' function|called in a constant expression" "" { target *-*-* } .-1 } constinit auto b = S ().bar (); constinit auto c = S ().foo (); constinit auto d = S ().bar (); // { dg-error "'constinit' variable 'd' does not have a constant initializer" } // { dg-error "call to non-'constexpr' function" "" { target *-*-* } .-1 } constinit auto e = S ().baz (); constinit auto f = S ().qux (); // { dg-error "'constinit' variable 'f' does not have a constant initializer" } // { dg-error "call to non-'constexpr' function" "" { target *-*-* } .-1 } constinit auto g = S ().baz (); // { dg-error "'constinit' variable 'g' does not have a constant initializer" } // { dg-error "call to non-'constexpr' function|called in a constant expression" "" { target *-*-* } .-1 } constinit auto h = S ().qux (); auto i = S::x; auto j = S::x; auto k = S::x; auto l = S::y; auto m = S::y;