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-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9ccc3495766116ea4ae8e4cd8129beca60e30445;p=gcc.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. --- diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 6fd081463f7..71107e03010 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -5588,16 +5588,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)) { @@ -5613,6 +5603,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 00000000000..62111df310e --- /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);