From patchwork Thu Dec 6 19:43:35 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: C++ PATCH for c++/54913 (error with static reference member and templates) Date: Thu, 06 Dec 2012 09:43:35 -0000 From: Jason Merrill X-Patchwork-Id: 204308 Message-Id: <50C0F567.5050505@redhat.com> To: gcc-patches List 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. commit fde00723eeea410df8f677fe6753c68e7277796d Author: Jason Merrill 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 +struct R +{ + R() { E::e; } +}; + +R r;