From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id 98133385781A; Tue, 12 Apr 2022 23:44:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 98133385781A MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Patrick Palka To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-9841] c++: var tmpl w/ dependent constrained auto type [PR103341] X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: 1429db66619d2b801ac0b586b5eed74ab54a35b0 X-Git-Newrev: 12b11107edfcde6a16ec397a9120687a14254215 Message-Id: <20220412234418.98133385781A@sourceware.org> Date: Tue, 12 Apr 2022 23:44:18 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Apr 2022 23:44:18 -0000 https://gcc.gnu.org/g:12b11107edfcde6a16ec397a9120687a14254215 commit r11-9841-g12b11107edfcde6a16ec397a9120687a14254215 Author: Patrick Palka Date: Fri Jan 28 08:18:28 2022 -0500 c++: var tmpl w/ dependent constrained auto type [PR103341] When deducing the type of a variable template (or templated static data member) with a constrained auto type, we might need its template arguments for satisfaction since the constraint could depend on them. PR c++/103341 gcc/cp/ChangeLog: * decl.c (cp_finish_decl): Pass the template arguments of a variable template specialization or a templated static data member to do_auto_deduction when the auto is constrained. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-class4.C: New test. * g++.dg/cpp2a/concepts-var-templ2.C: New test. (cherry picked from commit e272cf95ba048fde60b21aee046c9ca9c9264425) Diff: --- gcc/cp/decl.c | 13 ++++++++++++- gcc/testsuite/g++.dg/cpp2a/concepts-class4.C | 11 +++++++++++ gcc/testsuite/g++.dg/cpp2a/concepts-var-templ2.C | 13 +++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 8d7d71d0590..bffbd004167 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -7860,9 +7860,20 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, enum auto_deduction_context adc = adc_variable_type; if (VAR_P (decl) && DECL_DECOMPOSITION_P (decl)) adc = adc_decomp_type; + tree outer_targs = NULL_TREE; + if (flag_concepts + && PLACEHOLDER_TYPE_CONSTRAINTS_INFO (auto_node) + && VAR_P (decl) + && DECL_LANG_SPECIFIC (decl) + && DECL_TEMPLATE_INFO (decl) + && !DECL_FUNCTION_SCOPE_P (decl)) + /* The outer template arguments might be needed for satisfaction. + (For function scope variables, do_auto_deduction will obtain the + outer template arguments from current_function_decl.) */ + outer_targs = DECL_TI_ARGS (decl); type = TREE_TYPE (decl) = do_auto_deduction (type, d_init, auto_node, tf_warning_or_error, adc, - NULL_TREE, flags); + outer_targs, flags); if (type == error_mark_node) return; if (TREE_CODE (type) == FUNCTION_TYPE) diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-class4.C b/gcc/testsuite/g++.dg/cpp2a/concepts-class4.C new file mode 100644 index 00000000000..90395f11025 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-class4.C @@ -0,0 +1,11 @@ +// PR c++/103341 +// { dg-do compile { target c++20 } } + +template concept same_as = __is_same(T, U); +template +struct A { + static inline same_as auto value = 0; // { dg-error "constraint" } +}; + +template struct A; // { dg-bogus "" } +template struct A; // { dg-message "required from here" } diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-var-templ2.C b/gcc/testsuite/g++.dg/cpp2a/concepts-var-templ2.C new file mode 100644 index 00000000000..e1802aca75f --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-var-templ2.C @@ -0,0 +1,13 @@ +// PR c++/103341 +// { dg-do compile { target c++20 } } + +template concept same_as = __is_same(T, U); +template same_as auto v1a = 1; +template same_as auto v1b = T(); +template same_as auto v2a = 1; // { dg-error "constraints" } +template same_as auto v2b = T(); // { dg-error "constraints" } + +template int v1a; +template int v1b; +template int v2a; // { dg-message "required from here" } +template int v2b; // { dg-message "required from here" }