]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/34485 (ICE with undefined type in template parameter)
authorPaolo Carlini <paolo.carlini@oracle.com>
Thu, 14 Aug 2008 19:04:05 +0000 (19:04 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Thu, 14 Aug 2008 19:04:05 +0000 (19:04 +0000)
/cp
2008-08-14  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/34485
* pt.c (check_template_shadow): Change to return a bool.
* name-lookup.c (push_class_level_binding): Early return if
check_template_shadow returns false.
* cp-tree.h (check_template_shadow): Adjust declaration.

/testsuite
2008-08-14  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/34485
* g++.dg/template/crash81.C: New.
* g++.old-deja/g++.benjamin/tem03.C: Adjust.
* g++.old-deja/g++.benjamin/tem04.C: Likewise.
* g++.old-deja/g++.brendan/crash7.C: Likewise.

From-SVN: r139114

gcc/cp/ChangeLog
gcc/cp/cp-tree.h
gcc/cp/name-lookup.c
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/crash81.C [new file with mode: 0644]
gcc/testsuite/g++.old-deja/g++.benjamin/tem03.C
gcc/testsuite/g++.old-deja/g++.benjamin/tem04.C
gcc/testsuite/g++.old-deja/g++.brendan/crash7.C

index 48aab06d2453602102e1fd8e5d9c95328f751c76..29159480da5b116bacd72911bac3435678529618 100644 (file)
@@ -1,3 +1,11 @@
+2008-08-14  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/34485
+       * pt.c (check_template_shadow): Change to return a bool.
+       * name-lookup.c (push_class_level_binding): Early return if
+       check_template_shadow returns false.
+       * cp-tree.h (check_template_shadow): Adjust declaration.
+
 2008-08-14  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/34600
index 4b4bf335836f6b0be3be8e7ece63e286012b53f6..a80027ef27dd559aea123136c8dbd436b3d97437 100644 (file)
@@ -4450,7 +4450,7 @@ extern tree locate_dtor                           (tree, void *);
 extern bool maybe_clone_body                   (tree);
 
 /* in pt.c */
-extern void check_template_shadow              (tree);
+extern bool check_template_shadow              (tree);
 extern tree get_innermost_template_args                (tree, int);
 extern void maybe_begin_member_template_processing (tree);
 extern void maybe_end_member_template_processing (void);
index 9b456d54c575fb841a0cb676a51dd699b41b853b..60050b8f3393262143b277708ade00bb8c922351 100644 (file)
@@ -2753,7 +2753,8 @@ push_class_level_binding (tree name, tree x)
       && TREE_TYPE (decl) == error_mark_node)
     decl = TREE_VALUE (decl);
 
-  check_template_shadow (decl);
+  if (!check_template_shadow (decl))
+    POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, false);
 
   /* [class.mem]
 
index 6e4f0ba447b36357b22e05ca70b71853008b5d56..4a9e571a70aaf5f889c505c5777523982d2e7571 100644 (file)
@@ -2809,12 +2809,15 @@ expand_template_argument_pack (tree args)
   return result_args;
 }
 
-/* Complain if DECL shadows a template parameter.
+/* Checks if DECL shadows a template parameter.
 
    [temp.local]: A template-parameter shall not be redeclared within its
-   scope (including nested scopes).  */
+   scope (including nested scopes).
 
-void
+   Emits an error and returns TRUE if the DECL shadows a parameter,
+   returns FALSE otherwise.  */
+
+bool
 check_template_shadow (tree decl)
 {
   tree olddecl;
@@ -2822,7 +2825,7 @@ check_template_shadow (tree decl)
   /* If we're not in a template, we can't possibly shadow a template
      parameter.  */
   if (!current_template_parms)
-    return;
+    return true;
 
   /* Figure out what we're shadowing.  */
   if (TREE_CODE (decl) == OVERLOAD)
@@ -2832,24 +2835,25 @@ check_template_shadow (tree decl)
   /* If there's no previous binding for this name, we're not shadowing
      anything, let alone a template parameter.  */
   if (!olddecl)
-    return;
+    return true;
 
   /* If we're not shadowing a template parameter, we're done.  Note
      that OLDDECL might be an OVERLOAD (or perhaps even an
      ERROR_MARK), so we can't just blithely assume it to be a _DECL
      node.  */
   if (!DECL_P (olddecl) || !DECL_TEMPLATE_PARM_P (olddecl))
-    return;
+    return true;
 
   /* We check for decl != olddecl to avoid bogus errors for using a
      name inside a class.  We check TPFI to avoid duplicate errors for
      inline member templates.  */
   if (decl == olddecl
       || TEMPLATE_PARMS_FOR_INLINE (current_template_parms))
-    return;
+    return true;
 
   error ("declaration of %q+#D", decl);
   error (" shadows template parm %q+#D", olddecl);
+  return false;
 }
 
 /* Return a new TEMPLATE_PARM_INDEX with the indicated INDEX, LEVEL,
index 1947b43aee80d104203731b1f78c08944570cb5d..9a8f5f5b87692949abc805a0d9d65c9871f57fc7 100644 (file)
@@ -1,3 +1,11 @@
+2008-08-14  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/34485
+       * g++.dg/template/crash81.C: New.
+       * g++.old-deja/g++.benjamin/tem03.C: Adjust.
+       * g++.old-deja/g++.benjamin/tem04.C: Likewise.
+       * g++.old-deja/g++.brendan/crash7.C: Likewise.
+
 2008-08-14  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        PR libfortran/36886
diff --git a/gcc/testsuite/g++.dg/template/crash81.C b/gcc/testsuite/g++.dg/template/crash81.C
new file mode 100644 (file)
index 0000000..f2b7674
--- /dev/null
@@ -0,0 +1,6 @@
+// PR c++/34485
+
+struct A
+{
+  template<T::X> struct X; // { dg-error "error: 'T' has not been declared|error: declaration of 'template<int X> struct A::X'|error:  shadows template parm 'int X'" }
+};
index 73b99659e121d4264c6b6bec7af185e933d9b907..8f7459f17fb4d58537175d3a22e16c51ec535cb3 100644 (file)
@@ -83,7 +83,7 @@ public:
 template <class T10, int i> struct Xfour {// { dg-error "" } .*
   int T10; // { dg-error "" } .*
   void f(){
-    char T10;
+    char T10; // { dg-error "error: declaration of 'char T10'" }
   }
 };
 
@@ -123,11 +123,11 @@ public:
   template <class U>
   friend bool fooy(U u);
 
-  template <class T161>
+  template <class T161> // { dg-error "error: declaration of 'class T161'" }
   friend bool foo(T161 u)
     {
-      Xseven<T161, 5, int> obj; // { dg-error "" } .*
-      return (obj.inst == u.inst); // { dg-error "" } .*
+      Xseven<T161, 5, int> obj;
+      return (obj.inst == u.inst);
     }
 
 };
index d486efbbaefed3b1c9fc8db4cfb8b59220cb30b8..7dd7462c334be46c5d23c9c38a31962af8ad09af 100644 (file)
@@ -91,7 +91,7 @@ public:
 template <typename T14, template <typename T15> class C12>// { dg-error "" } .*
 class Xeighteen {
 protected:
-  C12<T14> value; // { dg-error "" }
+  C12<T14> value;
   int C12; // { dg-error "" } .*
 };
 
index 99fee519f52f55cc6f903768bb901c7faa3cab94..d53dee77dd3265e54399c8870314171181a270c9 100644 (file)
@@ -44,5 +44,5 @@ void Sort<Comp>::sort (Vector<Comp::T> &v)// { dg-error "" } use of bad T
 void
 f (Vector<int> &vi)
 {
-  Sort<Comparator<int> >::sort (vi);
+  Sort<Comparator<int> >::sort (vi); // { dg-error "error: 'sort' is not a member of 'Sort<Comparator<int> >'" }
 }