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 r12-7852] c++: member alias declaration [PR103968]
Date: Mon, 28 Mar 2022 13:37:28 +0000 (GMT)	[thread overview]
Message-ID: <20220328133728.319BD3857C50@sourceware.org> (raw)

https://gcc.gnu.org/g:c7361eb36fa50307c9f7cfca36c9f58ce24f8f54

commit r12-7852-gc7361eb36fa50307c9f7cfca36c9f58ce24f8f54
Author: Jason Merrill <jason@redhat.com>
Date:   Sun Mar 27 00:28:30 2022 -0400

    c++: member alias declaration [PR103968]
    
    Here, we were wrongly thinking that (const Options&)Widget<T>::c_options is
    not value-dependent because neither the type nor the (value of) c_options
    are dependent, but since we're binding it to a reference we also need to
    consider that it has a value-dependent address.
    
            PR c++/103968
    
    gcc/cp/ChangeLog:
    
            * pt.cc (value_dependent_expression_p): Check
            has_value_dependent_address for conversion to reference.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp0x/alias-decl-mem1.C: New test.

Diff:
---
 gcc/cp/pt.cc                                 |  4 ++++
 gcc/testsuite/g++.dg/cpp0x/alias-decl-mem1.C | 20 ++++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index b229c9fc739..41f1ef1f64d 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -27449,6 +27449,10 @@ value_dependent_expression_p (tree expression)
 	if (TREE_CODE (expression) == TREE_LIST)
 	  return any_value_dependent_elements_p (expression);
 
+	if (TREE_CODE (type) == REFERENCE_TYPE
+	    && has_value_dependent_address (expression))
+	  return true;
+
 	return value_dependent_expression_p (expression);
       }
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/alias-decl-mem1.C b/gcc/testsuite/g++.dg/cpp0x/alias-decl-mem1.C
new file mode 100644
index 00000000000..3e422de4054
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/alias-decl-mem1.C
@@ -0,0 +1,20 @@
+// PR c++/103968
+// { dg-do compile { target c++11 } }
+
+template <typename Opt, Opt const& options>
+struct trait
+{
+    template <typename T>
+    struct NonInstantiated{};
+};
+
+struct Options {};
+
+template <typename T>
+struct Widget
+{
+    static constexpr auto c_options = Options{};
+    using Trait = trait<decltype(c_options), c_options>;
+};
+
+Widget<int>::Trait b{}; // Crashes GCC > 10.3


                 reply	other threads:[~2022-03-28 13:37 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=20220328133728.319BD3857C50@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: link
Be 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).