This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ PATCH for c++/41972 (static data member argument to reference template parameter)


The code for checking valid template arguments didn't know that X::foo will show up as a SCOPE_REF if we're currently in another template.

Tested x86_64-pc-linux-gnu, applied to trunk; will apply to 4.4 and 4.3 after testing.
commit cbdac18988cbff2268e03364364f6289185d704a
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Nov 9 10:37:40 2009 -0500

    	PR c++/41972
    	* parser.c (cp_parser_template_argument): Accept SCOPE_REF around
    	VAR_DECL.

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 7bafb67..3475723 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -11368,18 +11368,26 @@ cp_parser_template_argument (cp_parser* parser)
 	cp_parser_abort_tentative_parse (parser);
       else
 	{
+	  tree probe;
+
 	  if (TREE_CODE (argument) == INDIRECT_REF)
 	    {
 	      gcc_assert (REFERENCE_REF_P (argument));
 	      argument = TREE_OPERAND (argument, 0);
 	    }
 
-	  if (TREE_CODE (argument) == VAR_DECL)
+	  /* If we're in a template, we represent a qualified-id referring
+	     to a static data member as a SCOPE_REF even if the scope isn't
+	     dependent so that we can check access control later.  */
+	  probe = argument;
+	  if (TREE_CODE (probe) == SCOPE_REF)
+	    probe = TREE_OPERAND (probe, 1);
+	  if (TREE_CODE (probe) == VAR_DECL)
 	    {
 	      /* A variable without external linkage might still be a
 		 valid constant-expression, so no error is issued here
 		 if the external-linkage check fails.  */
-	      if (!address_p && !DECL_EXTERNAL_LINKAGE_P (argument))
+	      if (!address_p && !DECL_EXTERNAL_LINKAGE_P (probe))
 		cp_parser_simulate_error (parser);
 	    }
 	  else if (is_overloaded_fn (argument))
diff --git a/gcc/testsuite/g++.dg/template/ref4.C b/gcc/testsuite/g++.dg/template/ref4.C
new file mode 100644
index 0000000..6d89fa8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/ref4.C
@@ -0,0 +1,12 @@
+// PR c++/41972
+
+struct X {
+  static const double  x;
+};
+template <const double& _test_>
+  class Foo { };
+template <typename _ignore_>
+struct Y {
+  typedef Foo<X::x> type;
+};
+


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]