public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Marek Polacek <mpolacek@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-9941] c++: enum in generic lambda at global scope [PR105398] Date: Wed, 27 Apr 2022 17:14:16 +0000 (GMT) [thread overview] Message-ID: <20220427171416.A2235385842B@sourceware.org> (raw) https://gcc.gnu.org/g:3a1358e5f38864bf5688a7b6db1fda482321a77a commit r11-9941-g3a1358e5f38864bf5688a7b6db1fda482321a77a Author: Marek Polacek <polacek@redhat.com> Date: Tue Apr 26 16:12:58 2022 -0400 c++: enum in generic lambda at global scope [PR105398] We crash compiling this test since r11-7993 which changed lookup_template_class_1 so that we only call tsubst_enum when !uses_template_parms (current_nonlambda_scope ()) But here current_nonlambda_scope () is the global NAMESPACE_DECL ::, which doesn't have a type, therefore is considered type-dependent. So we don't call tsubst_enum, and crash in tsubst_copy/CONST_DECL because we didn't find the e1 enumerator. I don't think any namespace can depend on any template parameter, so this patch tweaks uses_template_parms. PR c++/105398 gcc/cp/ChangeLog: * pt.c (uses_template_parms): Return false for any NAMESPACE_DECL. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/lambda-generic-enum2.C: New test. (cherry picked from commit 409edcca331296b53842c50d3b789e1b1ccc05e5) Diff: --- gcc/cp/pt.c | 2 +- gcc/testsuite/g++.dg/cpp1y/lambda-generic-enum2.C | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 318d42d800d..92b2ab412d3 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -10889,7 +10889,7 @@ uses_template_parms (tree t) || uses_template_parms (TREE_CHAIN (t))); else if (TREE_CODE (t) == TYPE_DECL) dependent_p = dependent_type_p (TREE_TYPE (t)); - else if (t == error_mark_node) + else if (t == error_mark_node || TREE_CODE (t) == NAMESPACE_DECL) dependent_p = false; else dependent_p = instantiation_dependent_expression_p (t); diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-enum2.C b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-enum2.C new file mode 100644 index 00000000000..77cf0bb9d02 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-enum2.C @@ -0,0 +1,15 @@ +// PR c++/105398 +// { dg-do compile { target c++14 } } + +auto f = [](auto &&m) { + enum E { _,e3,e2,e1,C4,C3,C2,C1 }; + static constexpr int x_coeffs[3][4] = { + {e1,C2,C3,C4}, + {e2,C1,C3,C4}, + {e3,C1,C2,C4}, + }; +}; + +int main() { + f(0); +}
reply other threads:[~2022-04-27 17:14 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220427171416.A2235385842B@sourceware.org \ --to=mpolacek@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).