[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

Chris Lattner clattner at apple.com
Mon Mar 2 21:33:03 PST 2009


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.

> +++ 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?

> +  IdentifierInfo *ParamName = D.getIdentifier();
> +  if (ParamName) {
> +    NamedDecl *PrevDecl = LookupName(S, ParamName, LookupTagName);
> +    if (PrevDecl && PrevDecl->isTemplateParameter())
> +      Invalid = Invalid ||  
> DiagnoseTemplateParameterShadow(D.getIdentifierLoc(),
> +                                                           PrevDecl);

I always thought it funny and sad that C doesn't have a "||="  
operator :)

>
>   }
>
> +  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?

> +++ 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

This is great progress Doug!

-Chris



More information about the cfe-commits mailing list