[PATCH] [Review Request] PR15466 - clang accepts incorrect explicit instantiation

Serge Pavlov sepavloff at gmail.com
Thu May 2 05:37:10 PDT 2013


sepavloff added you to the CC list for the revision "[Review Request] PR15466 - clang accepts incorrect explicit instantiation".

Hi rsmith,

This patch fixes the problem described in http://llvm.org/bugs/show_bug.cgi?id=15466 , - clang accepted invalid code:
template struct x { int a; };


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

Files:
  include/clang/Basic/DiagnosticParseKinds.td
  lib/Parse/ParseDeclCXX.cpp
  test/Parser/cxx-template-decl.cpp

Index: include/clang/Basic/DiagnosticParseKinds.td
===================================================================
--- include/clang/Basic/DiagnosticParseKinds.td
+++ include/clang/Basic/DiagnosticParseKinds.td
@@ -589,6 +589,7 @@
 def err_explicit_instantiation_enum : Error<
     "enumerations cannot be explicitly instantiated">;
 def err_expected_template_parameter : Error<"expected template parameter">;
+def err_missed_templ_params : Error<"template parameter list is missed">;
 
 def err_missing_dependent_template_keyword : Error<
   "use 'template' keyword to treat '%0' as a dependent template name">;
Index: lib/Parse/ParseDeclCXX.cpp
===================================================================
--- lib/Parse/ParseDeclCXX.cpp
+++ lib/Parse/ParseDeclCXX.cpp
@@ -1536,6 +1536,10 @@
                                       MultiTemplateParamsArg(
                                     TemplateParams? &(*TemplateParams)[0] : 0,
                                  TemplateParams? TemplateParams->size() : 0));
+  } else if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation &&
+             TUK == Sema::TUK_Definition) {
+    if (!TemplateParams)
+      Diag (TemplateInfo.TemplateLoc, diag::err_missed_templ_params);
   } else {
     if (TUK != Sema::TUK_Declaration && TUK != Sema::TUK_Definition)
       ProhibitAttributes(attrs);
Index: test/Parser/cxx-template-decl.cpp
===================================================================
--- test/Parser/cxx-template-decl.cpp
+++ test/Parser/cxx-template-decl.cpp
@@ -113,3 +113,9 @@
   template <typename T>
   void N::bar(typename T::x) { }
 }
+
+// PR15466
+template struct pr15466 { int a; }; // expected-error {{template parameter list is missed}}
+
+template <class T> struct pr15466a;
+template struct pr15466a { int a; }; // expected-error {{template parameter list is missed}}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D731.1.patch
Type: text/x-patch
Size: 1872 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130502/eefd8708/attachment.bin>


More information about the cfe-commits mailing list