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]

[PATCH] PR c++/42251


Hello,

When I added typedef stripping from SCOPE_REFs in
convert_template_argument, I did it too early in the function. As a
consequance, I was missing a possible folding that was happening in the final
'else' by calling convert_nontype_argument.

The patch below fixes that by stripping typedefs later in that function.
Also, I now use build_qualified_name as the comment of that functions says
all SCOPE_REFs should be created by using that function.

Tested against trunk on x86_64-unknown-linux-gnu.

        Dodji

commit 99cf9b3f1e897e8088ecaa94632a395d27d8a8f5
Author: Dodji Seketeli <dodji@redhat.com>
Date:   Tue Dec 8 15:36:50 2009 +0100

    Fix PR c++/42251
    
    gcc/cp/ChangeLog:
    	PR c++/42251
    	* pt.c (convert_template_argument): Avoid missing folding of SCOPE_REFs.
    
    gcc/testsuite/ChangeLog:
    	PR c++/42251
    	* g++.dg/template/const3.C: New test.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 97a2f80..d25f49c 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -5526,13 +5526,6 @@ convert_template_argument (tree parm,
       if (TYPE_P (val))
 	val = strip_typedefs (val);
     }
-  else if (TREE_CODE (orig_arg) == SCOPE_REF)
-    {
-      /* Strip typedefs from the SCOPE_REF.  */
-      tree type = strip_typedefs (TREE_TYPE (orig_arg));
-      tree scope = strip_typedefs (TREE_OPERAND (orig_arg, 0));
-      val = build2 (SCOPE_REF, type, scope, TREE_OPERAND (orig_arg, 1));
-    }
   else
     {
       tree t = tsubst (TREE_TYPE (parm), args, complain, in_decl);
@@ -5573,6 +5566,15 @@ convert_template_argument (tree parm,
 	error ("could not convert template argument %qE to %qT",  orig_arg, t);
     }
 
+  if (val && TREE_CODE (val) == SCOPE_REF)
+    {
+      /* Strip typedefs from the SCOPE_REF.  */
+      tree type = strip_typedefs (TREE_TYPE (val));
+      tree scope = strip_typedefs (TREE_OPERAND (val, 0));
+      val = build_qualified_name (type, scope, TREE_OPERAND (val, 1),
+				  QUALIFIED_NAME_IS_TEMPLATE (val));
+    }
+
   return val;
 }
 
diff --git a/gcc/testsuite/g++.dg/template/const3.C b/gcc/testsuite/g++.dg/template/const3.C
new file mode 100644
index 0000000..5ef2731
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/const3.C
@@ -0,0 +1,20 @@
+// Contributed by Dodji Seketeli <dodji@redhat.com>
+// Origin PR c++/42251
+// { dg-do "compile" }
+
+struct foo
+{
+    static const bool b = false;
+};
+
+template<bool x>
+struct S1
+{
+};
+
+template<bool x>
+struct S2
+    : S1<foo::b>
+{
+};
+


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