From: Patrick Palka Date: Wed, 28 Oct 2020 15:47:26 +0000 (-0400) Subject: c++: Check constraints before instantiation from mark_used [PR95132] X-Git-Tag: releases/gcc-10.3.0~713 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=833b180f097e8bae44634e6a31e9c92d661af301;p=thirdparty%2Fgcc.git c++: Check constraints before instantiation from mark_used [PR95132] This makes mark_used check constraints of a function _before_ calling maybe_instantiate_decl, so that we don't try instantiating a function (as part of return type deduction) with unsatisfied constraints. gcc/cp/ChangeLog: PR c++/95132 * decl2.c (mark_used): Move up the constraints_satisfied_p check so that we check constraints before calling maybe_instantiate_decl. gcc/testsuite/ChangeLog: PR c++/95132 * g++.dg/cpp2a/concepts-fn7.C: New test. (cherry picked from commit 9ccc3495766116ea4ae8e4cd8129beca60e30445) --- diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 8d3ac31a0c93..a683ae2d2288 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -5555,16 +5555,6 @@ mark_used (tree decl, tsubst_flags_t complain) if (DECL_ODR_USED (decl)) return true; - /* Normally, we can wait until instantiation-time to synthesize DECL. - However, if DECL is a static data member initialized with a constant - or a constexpr function, we need it right now because a reference to - such a data member or a call to such function is not value-dependent. - For a function that uses auto in the return type, we need to instantiate - it to find out its type. For OpenMP user defined reductions, we need - them instantiated for reduction clauses which inline them by hand - directly. */ - maybe_instantiate_decl (decl); - if (flag_concepts && TREE_CODE (decl) == FUNCTION_DECL && !constraints_satisfied_p (decl)) { @@ -5580,6 +5570,16 @@ mark_used (tree decl, tsubst_flags_t complain) return false; } + /* Normally, we can wait until instantiation-time to synthesize DECL. + However, if DECL is a static data member initialized with a constant + or a constexpr function, we need it right now because a reference to + such a data member or a call to such function is not value-dependent. + For a function that uses auto in the return type, we need to instantiate + it to find out its type. For OpenMP user defined reductions, we need + them instantiated for reduction clauses which inline them by hand + directly. */ + maybe_instantiate_decl (decl); + if (processing_template_decl || in_template_function ()) return true; diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-fn7.C b/gcc/testsuite/g++.dg/cpp2a/concepts-fn7.C new file mode 100644 index 000000000000..62111df310ef --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-fn7.C @@ -0,0 +1,11 @@ +// PR c++/95132 +// { dg-do compile { target c++20 } } + +template struct A { + static auto f() requires false { return T::fail; } +}; + +template +concept C = requires { A::f(); }; + +static_assert(!C);