[PATCH] Avoid spurious error messages if parent template class cannot be instantiated

Serge Pavlov sepavloff at gmail.com
Thu Jun 6 00:47:40 PDT 2013


sepavloff added you to the CC list for the revision "Avoid spurious error messages if parent template class cannot be instantiated".

Hi rsmith,

This patch is a prerequisite for fixing PR16225. It removed spurious errors when parent class is a template instantiation which cannot be resolved.

http://llvm-reviews.chandlerc.com/D924

Files:
  lib/Parse/ParseDeclCXX.cpp
  test/SemaCXX/class.cpp

Index: lib/Parse/ParseDeclCXX.cpp
===================================================================
--- lib/Parse/ParseDeclCXX.cpp
+++ lib/Parse/ParseDeclCXX.cpp
@@ -917,8 +917,11 @@
         << Id;
     }
 
-    if (!Template)
+    if (!Template) {
+      SkipUntil(tok::greater, tok::greatergreater, /*StopAtSemi=*/true,
+                /*DontConsume=*/false);
       return true;
+    }
 
     // Form the template name
     UnqualifiedId TemplateName;
Index: test/SemaCXX/class.cpp
===================================================================
--- test/SemaCXX/class.cpp
+++ test/SemaCXX/class.cpp
@@ -126,12 +126,8 @@
 
 // Don't crash on this bogus code.
 namespace pr6629 {
-  // TODO: most of these errors are spurious
   template<class T1, class T2> struct foo :
-    bogus<foo<T1,T2> > // expected-error {{unknown template name 'bogus'}} \
-                       // BOGUS expected-error {{expected '{' after base class list}} \
-                       // BOGUS expected-error {{expected ';' after struct}} \
-                       // BOGUS expected-error {{expected unqualified-id}}
+    bogus<foo<T1,T2> > // expected-error {{unknown template name 'bogus'}}
   { };
 
   template<> struct foo<unknown,unknown> { // expected-error {{undeclared identifier 'unknown'}}
@@ -142,6 +138,47 @@
   };
 }
 
+// Don't emit spurious messages
+namespace pr16225add {
+
+  template<class T1, typename T2> struct Known { }; // expected-note {{template is declared here}} \
+                                                    // expected-note {{template is declared here}} \
+                                                    // expected-note {{template is declared here}}
+
+  template<class T1, typename T2> struct foo :
+    UnknownBase<T1,T2> // expected-error {{unknown template name 'UnknownBase'}}
+  { };
+
+  template<class T1, typename T2> struct foo2 :
+    UnknownBase<T1,T2>, // expected-error {{unknown template name 'UnknownBase'}}
+    Known<T1>  // expected-error {{too few template arguments for class template 'Known'}}
+  { };
+
+  template<class T1, typename T2> struct foo3 :
+    UnknownBase<T1,T2,ABC<T2,T1> > // expected-error {{unknown template name 'UnknownBase'}}
+  { };
+
+  template<class T1, typename T2> struct foo4 :
+    UnknownBase<T1,ABC<T2> >, // expected-error {{unknown template name 'UnknownBase'}}
+    Known<T1>  // expected-error {{too few template arguments for class template 'Known'}}
+  { };
+
+  template<class T1, typename T2> struct foo5 :
+    UnknownBase<T1,T2,ABC<T2,T1>> // expected-error {{unknown template name 'UnknownBase'}}
+  { };
+
+  template<class T1, typename T2> struct foo6 :
+    UnknownBase<T1,ABC<T2>>, // expected-error {{unknown template name 'UnknownBase'}}
+    Known<T1>  // expected-error {{too few template arguments for class template 'Known'}}
+  { };
+
+  template<class T1, typename T2, int N> struct foo7 :
+    UnknownBase<T1,T2,(N>1)> // expected-error {{unknown template name 'UnknownBase'}}
+  { };
+
+}
+
+
 namespace PR7153 {
   class EnclosingClass {
   public:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D924.1.patch
Type: text/x-patch
Size: 3061 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130606/ca5f71fb/attachment.bin>


More information about the cfe-commits mailing list