From 6d1556ecfae3eff010ef7dc15f3da998403fa196 Mon Sep 17 00:00:00 2001 From: Patrick Palka Date: Sat, 23 May 2020 14:39:28 -0400 Subject: [PATCH] c++: Avoid concept evaluation when uid-sensitive [PR94038] Concept evaluation may entail DECL_UID generation and/or template instantiation, so in general we can't perform it during uid-sensitive constexpr evaluation. gcc/cp/ChangeLog: PR c++/94038 * constexpr.c (cxx_eval_constant_expression) : Don't evaluate the concept when constexpr evaluation is uid-sensitive. gcc/testsuite/ChangeLog: PR c++/94038 * g++.dg/warn/pr94038-3.C: New test. --- gcc/cp/ChangeLog | 7 +++++++ gcc/cp/constexpr.c | 3 ++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/warn/pr94038-3.C | 15 +++++++++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/warn/pr94038-3.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 385bfcd72db..2feeb12bcb0 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2020-05-23 Patrick Palka + + PR c++/94038 + * constexpr.c (cxx_eval_constant_expression) + : Don't evaluate the concept when + constexpr evaluation is uid-sensitive. + 2020-05-21 Patrick Palka PR c++/94038 diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 98c974e657f..4e441ac8d2f 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -6486,7 +6486,8 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, break; } - if (!processing_template_decl) + if (!processing_template_decl + && !uid_sensitive_constexpr_evaluation_p ()) r = evaluate_concept_check (t, tf_warning_or_error); else *non_constant_p = true; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9711a27e29c..80fd33dac18 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-05-23 Patrick Palka + + PR c++/94038 + * g++.dg/warn/pr94038-3.C: New test. + 2020-05-22 Mark Wielaard * gcc.dg/spellcheck-stdint.c: New test. diff --git a/gcc/testsuite/g++.dg/warn/pr94038-3.C b/gcc/testsuite/g++.dg/warn/pr94038-3.C new file mode 100644 index 00000000000..49b6d133f08 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr94038-3.C @@ -0,0 +1,15 @@ +// PR c++/94038 +// { dg-do compile { target c++20 } } +// { dg-additional-options "-Wall" } + +template +constexpr int foo() { + return T::x; +} + +constexpr bool bar(bool a) { return a; } + +template +concept C = foo() == 0; + +static_assert(decltype(bar(C)){} == false); -- 2.30.2