diff mbox

C++ PATCH for c++/54913 (error with static reference member and templates)

Message ID 50C0F567.5050505@redhat.com
State New
Headers show

Commit Message

Jason Merrill Dec. 6, 2012, 7:43 p.m. UTC
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.
diff mbox

Patch

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;