if (dependent_type_p (t))
return false;
- /* We need the complete type otherwise we'd have no fields for class
- templates and thus come up with zilch for things like
- template<typename T>
- struct X : T { };
- which could be consteval-only, depending on T. */
- t = complete_type (t);
-
consteval_only_p_walker walker;
return walker.walk (t).is_true ();
}
tristate
consteval_only_p_walker::walk (tree t)
{
+ if (t == error_mark_node)
+ return false;
+
t = TYPE_MAIN_VARIANT (t);
if (REFLECTION_TYPE_P (t))
--- /dev/null
+// PR c++/125280
+// { dg-do compile { target c++26 } }
+// { dg-additional-options "-freflection" }
+
+struct C { decltype(^^::) i; };
+struct N { int i; };
+
+template<typename T>
+struct X : T { };
+
+auto a = X<C>{}; // { dg-error "outside a constant-evaluated context" }
+auto b = X<N>{};
--- /dev/null
+// PR c++/125280
+// { dg-do compile { target c++26 } }
+// { dg-additional-options "-freflection" }
+
+template <class T, int N>
+struct Array {
+ T mElements[N];
+};
+
+struct Element {
+ static const Array<Element, 9> mData;
+};
+const Array<Element, 9> Element::mData;
+
+struct CE { decltype(^^::) i; };
+
+struct A {
+ static const Array<CE, 10> mData;
+};
+const Array<CE, 10> A::mData{}; // { dg-error "outside a constant-evaluated context" }
+
+struct B {
+ static constexpr Array<CE, 11> mData{};
+};
+
+struct C {
+ static const Array<CE, 12> mData;
+};
--- /dev/null
+// PR c++/125280
+// { dg-do compile { target c++26 } }
+// { dg-additional-options "-freflection" }
+
+template <class T, int N>
+struct Array {
+ T mElements[N]; // { dg-error "incomplete type" }
+};
+
+struct Element {
+ static const Array<Element, 10> mData{}; // { dg-error "initialization of static data member" }
+};
+const Array<Element, 10> Element::mData;