[cfe-commits] r65924 - in /cfe/trunk: include/clang/AST/DeclTemplate.h include/clang/Basic/DiagnosticSemaKinds.def lib/AST/DeclCXX.cpp lib/Sema/Sema.h lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclCXX.cpp lib/Sema/SemaTemplate.cpp lib/Sema/SemaTemplateInstantiate.cpp lib/Sema/SemaType.cpp test/SemaTemplate/class-template-id-2.cpp test/SemaTemplate/class-template-spec.cpp test/SemaTemplate/instantiation-default-2.cpp

Douglas Gregor dgregor at apple.com
Mon Mar 9 09:45:48 PDT 2009


On Mar 2, 2009, at 9:33 PM, Chris Lattner wrote:

> On Mar 2, 2009, at 8:44 PM, Douglas Gregor wrote:
>> URL: http://llvm.org/viewvc/llvm-project?rev=65924&view=rev
>> Log:
>> Implement the basics of implicit instantiation of class templates, in
>> response to attempts to diagnose an "incomplete" type. This will  
>> force
>> us to use DiagnoseIncompleteType more regularly (rather than  
>> looking at
>> isIncompleteType), but that's also a good thing.
>
> Nice!
>
> It might make sense to rename DiagnoseIncompleteType to be  
> DiagnoseOrInstantiateIncompleteType or RequireCompleteType etc, to  
> make it more clear that it does more than emit a diagnostic.

RequireCompleteType is an excellent name.

>> +++ cfe/trunk/include/clang/AST/DeclTemplate.h Mon Mar  2 22:44:36  
>> 2009
>> @@ -590,6 +590,10 @@
>>    return template_arg_begin() + NumTemplateArgs;
>>  }
>>
>> +  const TemplateArgument *getTemplateArgs() const {
>> +    return template_arg_begin();
>> +  }
>> +
>
> The fact that template_iterator is a pointer seems like an  
> implementation detail, is this method needed?

getTemplateArgs/getNumTemplateArgs are used to provide access to the  
template arguments in the same form that the parser passes them into  
Sema, because many routines that deal with template arguments can  
either be called directly from the parser and from the template- 
instantiation logic.

>>
>>  }
>>
>> +  T = CheckNonTypeTemplateParameterType(T, D.getIdentifierLoc());
>> +  if (T.isNull())
>> +    T = Context.IntTy; // Recover with an 'int' type.
>
> Does this need to mark the NonTypeTemplateParmDecl 'invalid' to  
> avoid cascades of error recovery diagnostics?

Yes, good catch.

>> +++ cfe/trunk/lib/Sema/SemaType.cpp Mon Mar  2 22:44:36 2009
>> @@ -14,6 +14,7 @@
>> #include "Sema.h"
>> #include "clang/AST/ASTContext.h"
>> #include "clang/AST/DeclObjC.h"
>> +#include "clang/AST/DeclTemplate.h"
>> #include "clang/AST/Expr.h"
>> #include "clang/Parse/DeclSpec.h"
>> using namespace clang;
>> @@ -1033,6 +1034,21 @@
>>  if (!T->isIncompleteType())
>>    return false;
>>
>> +  // If we have a class template specialization, try to instantiate
>> +  // it.
>> +  if (const RecordType *Record = T->getAsRecordType())
>> +    if (ClassTemplateSpecializationDecl *ClassTemplateSpec
>> +          = dyn_cast<ClassTemplateSpecializationDecl>(Record- 
>> >getDecl()))
>
> Can this be split out to a helper function in DeclTemplate?  It  
> would be nice for SemaType.cpp to not #include DeclTemplate.h


It could, but I don't see a way to make the split clean. The  
"instantiate this if it is a class template specialization" operation  
needs a three-state return type ("there's nothing to instantiate",  
"the instantiation failed", or "the instantiation succeeded"), and I  
found the resulting code uglier than the status quo.

	- Doug



More information about the cfe-commits mailing list