[cfe-commits] r132208 - /cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp

Sean Hunt scshunt at csclub.uwaterloo.ca
Fri May 27 13:00:14 PDT 2011


Author: coppro
Date: Fri May 27 15:00:14 2011
New Revision: 132208

URL: http://llvm.org/viewvc/llvm-project?rev=132208&view=rev
Log:
Add assertions to verify that we are not trying to instantiate a
nontemplate in Sema::InstantiateTemplateDecl.

This should make the issue in PR10026 more visible, although it's not
going to fix it because something is violating this precondition.

Modified:
    cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=132208&r1=132207&r2=132208&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Fri May 27 15:00:14 2011
@@ -2317,16 +2317,18 @@
 
   // Find the function body that we'll be substituting.
   const FunctionDecl *PatternDecl = Function->getTemplateInstantiationPattern();
-  Stmt *Pattern = 0;
-  if (PatternDecl) {
-    Pattern = PatternDecl->getBody(PatternDecl);
-    if (!Pattern)
-      // Try to find a defaulted definition
-      PatternDecl->isDefined(PatternDecl);
+  assert(PatternDecl && "instantiating a non-template");
+
+  Stmt *Pattern = PatternDecl->getBody(PatternDecl);
+  assert(PatternDecl && "template definition is not a template");
+  if (!Pattern) {
+    // Try to find a defaulted definition
+    PatternDecl->isDefined(PatternDecl);
   }
+  assert(PatternDecl && "template definition is not a template");
 
   // Postpone late parsed template instantiations.
-  if (PatternDecl && PatternDecl->isLateTemplateParsed() &&
+  if (PatternDecl->isLateTemplateParsed() &&
       !LateTemplateParser) {
     PendingInstantiations.push_back(
       std::make_pair(Function, PointOfInstantiation));
@@ -2335,13 +2337,13 @@
 
   // Call the LateTemplateParser callback if there a need to late parse
   // a templated function definition. 
-  if (!Pattern && PatternDecl && PatternDecl->isLateTemplateParsed() &&
+  if (!Pattern && PatternDecl->isLateTemplateParsed() &&
       LateTemplateParser) {
     LateTemplateParser(OpaqueParser, PatternDecl);
     Pattern = PatternDecl->getBody(PatternDecl);
   }
 
-  if (!Pattern && PatternDecl && !PatternDecl->isDefaulted()) {
+  if (!Pattern && !PatternDecl->isDefaulted()) {
     if (DefinitionRequired) {
       if (Function->getPrimaryTemplate())
         Diag(PointOfInstantiation, 





More information about the cfe-commits mailing list