From 9eb7d0d76eb652caa9186766da4fe965f113b1b8 Mon Sep 17 00:00:00 2001 From: Patrick Palka Date: Wed, 8 Jul 2020 14:17:47 -0400 Subject: [PATCH] c++: ICE in is_really_empty_class [PR95497] We are ICEing in the testcase below because we pass the yet-uninstantiated class type A of the PARM_DECL b to is_really_empty_class from is_rvalue_constant_expression when parsing the requirement t += b. This patch fixes the ICE by guarding the problematic call to is_really_empty_class with a COMPLETE_TYPE_P check, which should also subsume the existing dependent_type_p check. gcc/cp/ChangeLog: PR c++/95497 * constexpr.c (potential_constant_expression_1) : When processing_template_decl, check COMPLETE_TYPE_P before calling is_really_empty_class. Don't check dependent_type_p. gcc/testsuite/ChangeLog: PR c++/95497 * g++.dg/cpp2a/concepts-pr95497.C: New test. --- gcc/cp/constexpr.c | 2 +- gcc/testsuite/g++.dg/cpp2a/concepts-pr95497.C | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-pr95497.C diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 1939166e907..ff78ebda2dc 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -7443,7 +7443,7 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, if (now && want_rval) { tree type = TREE_TYPE (t); - if (dependent_type_p (type) + if ((processing_template_decl && !COMPLETE_TYPE_P (type)) || is_really_empty_class (type, /*ignore_vptr*/false)) /* An empty class has no data to read. */ return true; diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-pr95497.C b/gcc/testsuite/g++.dg/cpp2a/concepts-pr95497.C new file mode 100644 index 00000000000..4d7718ad5e8 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-pr95497.C @@ -0,0 +1,12 @@ +// PR c++/95497 +// { dg-do compile { target c++20 } } + +template +struct A{}; + +template +concept c = + requires(T t, A b) // note that A is independent of T + { + { t += b }; + }; -- 2.30.2