public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: gcc-patches List <gcc-patches@gcc.gnu.org>
Subject: C++ PATCH for c++/54913 (error with static reference member and templates)
Date: Thu, 06 Dec 2012 19:43:00 -0000	[thread overview]
Message-ID: <50C0F567.5050505@redhat.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 368 bytes --]

We build up a SCOPE_REF to remember that we saw a qualified-id in a 
template.  We also want to convert_from_reference so that a use of a 
reference member decays to a non-reference.  But we were doing them in 
the wrong order, so that the second operand of the SCOPE_REF was an 
INDIRECT_REF, which doesn't make sense.

Tested x86_64-pc-linux-gnu, applying to trunk.

[-- Attachment #2: 54913.patch --]
[-- Type: text/x-patch, Size: 1326 bytes --]

commit fde00723eeea410df8f677fe6753c68e7277796d
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Dec 6 10:31:52 2012 -0500

    	PR c++/54913
    	* semantics.c (finish_qualified_id_expr): convert_from_reference
    	after building a SCOPE_REF.

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 53e849a..6c168e4 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -1778,8 +1778,6 @@ finish_qualified_id_expr (tree qualifying_class,
     ;
   else
     {
-      expr = convert_from_reference (expr);
-
       /* In a template, return a SCOPE_REF for most qualified-ids
 	 so that we can check access at instantiation time.  But if
 	 we're looking at a member of the current instantiation, we
@@ -1790,6 +1788,8 @@ finish_qualified_id_expr (tree qualifying_class,
 	expr = build_qualified_name (TREE_TYPE (expr),
 				     qualifying_class, expr,
 				     template_p);
+
+      expr = convert_from_reference (expr);
     }
 
   return expr;
diff --git a/gcc/testsuite/g++.dg/template/qualified-id6.C b/gcc/testsuite/g++.dg/template/qualified-id6.C
new file mode 100644
index 0000000..83be874
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/qualified-id6.C
@@ -0,0 +1,14 @@
+// PR c++/54913
+
+struct E
+{
+  static const int& e;
+};
+
+template<typename>
+struct R
+{
+  R() { E::e; }
+};
+
+R<int> r;

                 reply	other threads:[~2012-12-06 19:43 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=50C0F567.5050505@redhat.com \
    --to=jason@redhat.com \
    --cc=gcc-patches@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).