On 9/10/25 2:13 PM, Nathaniel Shead wrote:
Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk?
OK.
-- >8 --
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 <nathanielosh...@gmail.com>
---
gcc/cp/constraint.cc | 2 +-
gcc/testsuite/g++.dg/cpp2a/concepts-traits5.C | 14 ++++++++++++++
2 files changed, 15 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-traits5.C
diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index 4b20b791e5d..309ebc81324 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -3360,7 +3360,7 @@ maybe_diagnose_standard_trait (location_t loc, tree expr)
}
}
- if (TREE_CODE (expr) == TRAIT_EXPR)
+ if (expr && TREE_CODE (expr) == TRAIT_EXPR)
{
diagnose_trait_expr (loc, expr, args);
return true;
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-traits5.C
b/gcc/testsuite/g++.dg/cpp2a/concepts-traits5.C
new file mode 100644
index 00000000000..de99dcd13c8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-traits5.C
@@ -0,0 +1,14 @@
+// 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" }
+}