A static member template doesn't always have a DECL_INITIAL, as in the
below testcase, and so checking its TREE_CODE performs a null-pointer
dereference. I don't think we need to specially detect this case as
traits we care about are unlikely to be members, so this just adds the
missing null check.
PR c++/121859
gcc/cp/ChangeLog:
* constraint.cc (maybe_diagnose_standard_trait): Check if expr
is non-null.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/concepts-traits5.C: New test.
Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
}
}
- if (TREE_CODE (expr) == TRAIT_EXPR)
+ if (expr && TREE_CODE (expr) == TRAIT_EXPR)
{
diagnose_trait_expr (loc, expr, args);
return true;
--- /dev/null
+// PR c++/121859
+// { dg-do compile { target c++20 } }
+
+template <typename T>
+struct S {
+ template <typename U>
+ static constexpr bool foo = sizeof(T) == sizeof(U);
+};
+
+template <typename U> void bar(U x) requires S<char>::foo<U> {}
+
+int main() {
+ bar(double{}); // { dg-error "no matching function" }
+}