]> granicus.if.org Git - clang/commitdiff
In some situations, TemplateArgumentLoc wasn't setting TypeSourceLoc (see
authorCraig Silverstein <csilvers2000@yahoo.com>
Thu, 18 Nov 2010 08:32:02 +0000 (08:32 +0000)
committerCraig Silverstein <csilvers2000@yahoo.com>
Thu, 18 Nov 2010 08:32:02 +0000 (08:32 +0000)
http://llvm.org/bugs/show_bug.cgi?id=8558).  This patch fixes it.  Thanks to
rjmccall for all the coaching!

Approved by rjmccall

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@119697 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/TypeLoc.h
include/clang/Sema/Sema.h
lib/AST/TypeLoc.cpp
lib/Parse/ParseDeclCXX.cpp
lib/Sema/SemaTemplate.cpp

index 35bba03d77357d6ff375e2094dd6977a7c821bf6..a290017076cce917f2e6e20e3aea42a5a5b4cb70 100644 (file)
@@ -124,6 +124,12 @@ public:
     initializeImpl(*this, Loc);
   }
 
+  /// \brief Initializes this by copying its information from another
+  /// TypeLoc of the same type.
+  void initializeFullCopy(TypeLoc Other) const {
+    initializeFullCopyImpl(*this, Other);
+  }
+
   friend bool operator==(const TypeLoc &LHS, const TypeLoc &RHS) {
     return LHS.Ty == RHS.Ty && LHS.Data == RHS.Data;
   }
@@ -136,6 +142,7 @@ public:
 
 private:
   static void initializeImpl(TypeLoc TL, SourceLocation Loc);
+  static void initializeFullCopyImpl(TypeLoc TL, TypeLoc Other);
   static TypeLoc getNextTypeLocImpl(TypeLoc TL);
   static SourceRange getLocalSourceRangeImpl(TypeLoc TL);
 };
index 26c775fcfad250332732d9cb7c93fc6b7fc43e2d..aa3d790b8e641afc855a0847fd015822866e56d2 100644 (file)
@@ -2869,10 +2869,11 @@ public:
                       ASTTemplateArgsPtr TemplateArgs,
                       SourceLocation RAngleLoc);
 
-  TypeResult ActOnTagTemplateIdType(TypeResult Type,
-                                            TagUseKind TUK,
-                                            TypeSpecifierType TagSpec,
-                                            SourceLocation TagLoc);
+  TypeResult ActOnTagTemplateIdType(CXXScopeSpec &SS,
+                                    TypeResult Type,
+                                    TagUseKind TUK,
+                                    TypeSpecifierType TagSpec,
+                                    SourceLocation TagLoc);
 
   ExprResult BuildTemplateIdExpr(const CXXScopeSpec &SS,
                                  LookupResult &R,
index 66578fb3dc498349e540a8e4f217b3b6104a586d..0ba9fc00876e6dcadd65ad516aae1783a34c79ac 100644 (file)
@@ -94,6 +94,13 @@ void TypeLoc::initializeImpl(TypeLoc TL, SourceLocation Loc) {
   }
 }
 
+/// \brief Initializes a type location by copying all its data from
+/// another type location of the same type.
+void TypeLoc::initializeFullCopyImpl(TypeLoc TL, TypeLoc Other) {
+  assert(TL.getType() == Other.getType() && "Must copy from same type");
+  memcpy(TL.getOpaqueData(), Other.getOpaqueData(), TL.getFullDataSize());
+}
+
 SourceLocation TypeLoc::getBeginLoc() const {
   TypeLoc Cur = *this;
   while (true) {
index 140f149101724ebacd966dbcf1b20c04d5e0aa6c..1bc5815f21e657e26c784ac1aeba999065c4c9e9 100644 (file)
@@ -908,7 +908,7 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind,
                                       TemplateArgsPtr,
                                       TemplateId->RAngleLoc);
 
-      TypeResult = Actions.ActOnTagTemplateIdType(TypeResult, TUK,
+      TypeResult = Actions.ActOnTagTemplateIdType(SS, TypeResult, TUK,
                                                   TagType, StartLoc);
     } else {
       // This is an explicit specialization or a class template
index 4c25bc32df5e67e4778ee23f4708635db3fb43eb..daa1e726a06a525a6e3582d673f54aa328648a7b 100644 (file)
@@ -1646,14 +1646,14 @@ Sema::ActOnTemplateIdType(TemplateTy TemplateD, SourceLocation TemplateLoc,
   return CreateParsedType(Result, DI);
 }
 
-TypeResult Sema::ActOnTagTemplateIdType(TypeResult TypeResult,
+TypeResult Sema::ActOnTagTemplateIdType(CXXScopeSpec &SS,
+                                        TypeResult TypeResult,
                                         TagUseKind TUK,
                                         TypeSpecifierType TagSpec,
                                         SourceLocation TagLoc) {
   if (TypeResult.isInvalid())
     return ::TypeResult();
 
-  // FIXME: preserve source info, ideally without copying the DI.
   TypeSourceInfo *DI;
   QualType Type = GetTypeFromParser(TypeResult.get(), &DI);
 
@@ -1678,7 +1678,12 @@ TypeResult Sema::ActOnTagTemplateIdType(TypeResult TypeResult,
     = TypeWithKeyword::getKeywordForTagTypeKind(TagKind);
   QualType ElabType = Context.getElaboratedType(Keyword, /*NNS=*/0, Type);
 
-  return ParsedType::make(ElabType);
+  TypeSourceInfo *ElabDI = Context.CreateTypeSourceInfo(ElabType);
+  ElaboratedTypeLoc TL = cast<ElaboratedTypeLoc>(ElabDI->getTypeLoc());
+  TL.setKeywordLoc(TagLoc);
+  TL.setQualifierRange(SS.getRange());
+  TL.getNamedTypeLoc().initializeFullCopy(DI->getTypeLoc());
+  return CreateParsedType(ElabType, ElabDI);
 }
 
 ExprResult Sema::BuildTemplateIdExpr(const CXXScopeSpec &SS,