public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jason Merrill <jason@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-8151] c++: constexpr, inheritance, and local class [PR91933] Date: Tue, 13 Apr 2021 12:26:45 +0000 (GMT) [thread overview] Message-ID: <20210413122645.086693854804@sourceware.org> (raw) https://gcc.gnu.org/g:0851ac6df0596df1e3b640e58094cf94ebb790b8 commit r11-8151-g0851ac6df0596df1e3b640e58094cf94ebb790b8 Author: Jason Merrill <jason@redhat.com> Date: Mon Apr 12 17:43:51 2021 -0400 c++: constexpr, inheritance, and local class [PR91933] Here we complained about referring to nm3 from the local class member function because referring to the base class subobject involved taking the variable's address. Let's shortcut this case to avoid that. gcc/cp/ChangeLog: PR c++/91933 * class.c (build_base_path): Shortcut simple non-pointer case. gcc/testsuite/ChangeLog: PR c++/91933 * g++.dg/cpp0x/constexpr-base7.C: New test. Diff: --- gcc/cp/class.c | 13 ++++++++++--- gcc/testsuite/g++.dg/cpp0x/constexpr-base7.C | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 4bffec4a707..90b343803a0 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -330,6 +330,15 @@ build_base_path (enum tree_code code, return error_mark_node; } + bool uneval = (cp_unevaluated_operand != 0 + || processing_template_decl + || in_template_function ()); + + /* For a non-pointer simple base reference, express it as a COMPONENT_REF + without taking its address (and so causing lambda capture, 91933). */ + if (code == PLUS_EXPR && !v_binfo && !want_pointer && !has_empty && !uneval) + return build_simple_base_path (expr, binfo); + if (!want_pointer) { rvalue = !lvalue_p (expr); @@ -357,9 +366,7 @@ build_base_path (enum tree_code code, template (even in instantiate_non_dependent_expr), we don't have vtables set up properly yet, and the value doesn't matter there either; we're just interested in the result of overload resolution. */ - if (cp_unevaluated_operand != 0 - || processing_template_decl - || in_template_function ()) + if (uneval) { expr = build_nop (ptr_target_type, expr); goto indout; diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-base7.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-base7.C new file mode 100644 index 00000000000..14e026ec202 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-base7.C @@ -0,0 +1,15 @@ +// PR c++/91933 +// { dg-do compile { target c++11 } } + +struct NoMut1 { int a, b; }; +struct NoMut3 : NoMut1 { + constexpr NoMut3(int a, int b) : NoMut1{a, b} {} +}; +void mutable_subobjects() { + constexpr NoMut3 nm3 = {1, 2}; + struct A { + void f() { + static_assert(nm3.a == 1, ""); + } + }; +}
reply other threads:[~2021-04-13 12:26 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=20210413122645.086693854804@sourceware.org \ --to=jason@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).