]> granicus.if.org Git - clang/commitdiff
Make sure to give an error for template argument lists followed by junk.
authorEli Friedman <eli.friedman@gmail.com>
Sun, 27 Dec 2009 22:31:18 +0000 (22:31 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Sun, 27 Dec 2009 22:31:18 +0000 (22:31 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92177 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseTemplate.cpp
test/Parser/cxx-template-argument.cpp [new file with mode: 0644]

index cc28541b01fed588024816f314bd2b48c79d0643..8b8af99ec6d773fab543f13483fa5d820ac7d5c2 100644 (file)
@@ -643,8 +643,10 @@ Parser::ParseTemplateIdAfterTemplateName(TemplateTy Template,
     }
   }
 
-  if (Tok.isNot(tok::greater) && Tok.isNot(tok::greatergreater))
+  if (Tok.isNot(tok::greater) && Tok.isNot(tok::greatergreater)) {
+    Diag(Tok.getLocation(), diag::err_expected_greater);
     return true;
+  }
 
   // Determine the location of the '>' or '>>'. Only consume this
   // token if the caller asked us to.
@@ -989,7 +991,7 @@ Parser::ParseTemplateArgumentList(TemplateArgList &TemplateArgs) {
     ConsumeToken();
   }
 
-  return Tok.isNot(tok::greater) && Tok.isNot(tok::greatergreater);
+  return false;
 }
 
 /// \brief Parse a C++ explicit template instantiation
diff --git a/test/Parser/cxx-template-argument.cpp b/test/Parser/cxx-template-argument.cpp
new file mode 100644 (file)
index 0000000..80389a0
--- /dev/null
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template<typename T> struct A {};
+
+// Check for template argument lists followed by junk
+// FIXME: The diagnostics here aren't great...
+A<int+> int x; // expected-error {{expected '>'}} expected-error {{expected unqualified-id}}
+A<int x; // expected-error {{expected '>'}} expected-error {{C++ requires a type specifier for all declarations}}
+