]> granicus.if.org Git - clang/commitdiff
Avoid redundant NNS qualification in constructor/destructor names.
authorAbramo Bagnara <abramo.bagnara@gmail.com>
Fri, 27 Jan 2012 08:46:19 +0000 (08:46 +0000)
committerAbramo Bagnara <abramo.bagnara@gmail.com>
Fri, 27 Jan 2012 08:46:19 +0000 (08:46 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149124 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Sema/Sema.h
lib/Parse/ParseDecl.cpp
lib/Parse/ParseDeclCXX.cpp
lib/Parse/ParseExprCXX.cpp
lib/Parse/Parser.cpp
lib/Sema/SemaDecl.cpp
lib/Sema/SemaTemplate.cpp

index 97e09cfd01ce19c17881caa579f7ad18dccdf7ed..69f16d745633ce4811a4b27f839f8f1741f804d9 100644 (file)
@@ -851,6 +851,7 @@ public:
                          bool isClassName = false,
                          bool HasTrailingDot = false,
                          ParsedType ObjectType = ParsedType(),
+                         bool IsCtorOrDtorName = false,
                          bool WantNontrivialTypeSourceInfo = false,
                          IdentifierInfo **CorrectedII = 0);
   TypeSpecifierType isTagName(IdentifierInfo &II, Scope *S);
@@ -3941,7 +3942,8 @@ public:
                       TemplateTy Template, SourceLocation TemplateLoc,
                       SourceLocation LAngleLoc,
                       ASTTemplateArgsPtr TemplateArgs,
-                      SourceLocation RAngleLoc);
+                      SourceLocation RAngleLoc,
+                      bool IsCtorOrDtorName = false);
 
   /// \brief Parsed an elaborated-type-specifier that refers to a template-id,
   /// such as \c class T::template apply<U>.
index b04baa7db88f2fe7104169cebb6a8c993393293f..f6c0ae21d143977d0c306a4a9f6727a7ca43c758 100644 (file)
@@ -1846,6 +1846,7 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
                                                Next.getLocation(),
                                                getCurScope(), &SS,
                                                false, false, ParsedType(),
+                                               /*IsCtorOrDtorName=*/false,
                                                /*NonTrivialSourceInfo=*/true);
 
       // If the referenced identifier is not a type, then this declspec is
index 14c8955949ea0948f655b6401506cf701afac39c..92a501a8c4a72e6a0ab706ce52412e346694106f 100644 (file)
@@ -857,6 +857,7 @@ Parser::TypeResult Parser::ParseBaseTypeSpecifier(SourceLocation &BaseLoc,
   // We have an identifier; check whether it is actually a type.
   ParsedType Type = Actions.getTypeName(*Id, IdLoc, getCurScope(), &SS, true,
                                         false, ParsedType(),
+                                        /*IsCtorOrDtorName=*/false,
                                         /*NonTrivialTypeSourceInfo=*/true);
   if (!Type) {
     Diag(IdLoc, diag::err_expected_class_name);
index dfab03c1c3e520541f711cf2d39857d61ab1fa6d..d35203e941eb28541b2263c7e3530a707e0d6398 100644 (file)
@@ -1647,12 +1647,12 @@ bool Parser::ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS,
   // Bundle the template arguments together.
   ASTTemplateArgsPtr TemplateArgsPtr(Actions, TemplateArgs.data(),
                                      TemplateArgs.size());
-  
+
   // Constructor and destructor names.
   TypeResult Type
     = Actions.ActOnTemplateIdType(SS, Template, NameLoc,
-                                  LAngleLoc, TemplateArgsPtr,
-                                  RAngleLoc);
+                                  LAngleLoc, TemplateArgsPtr, RAngleLoc,
+                                  /*IsCtorOrDtorName=*/true);
   if (Type.isInvalid())
     return true;
   
@@ -1910,11 +1910,12 @@ bool Parser::ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext,
     if (AllowConstructorName && 
         Actions.isCurrentClassName(*Id, getCurScope(), &SS)) {
       // We have parsed a constructor name.
-      Result.setConstructorName(Actions.getTypeName(*Id, IdLoc, getCurScope(),
-                                                    &SS, false, false,
-                                                    ParsedType(),
-                                            /*NonTrivialTypeSourceInfo=*/true),
-                                IdLoc, IdLoc);
+      ParsedType Ty = Actions.getTypeName(*Id, IdLoc, getCurScope(),
+                                          &SS, false, false,
+                                          ParsedType(),
+                                          /*IsCtorOrDtorName=*/true,
+                                          /*NonTrivialTypeSourceInfo=*/true);
+      Result.setConstructorName(Ty, IdLoc, IdLoc);
     } else {
       // We have parsed an identifier.
       Result.setIdentifier(Id, IdLoc);      
@@ -1947,13 +1948,14 @@ bool Parser::ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext,
           << TemplateId->Name
           << FixItHint::CreateRemoval(
                     SourceRange(TemplateId->LAngleLoc, TemplateId->RAngleLoc));
-        Result.setConstructorName(Actions.getTypeName(*TemplateId->Name,
-                                                  TemplateId->TemplateNameLoc, 
-                                                      getCurScope(),
-                                                      &SS, false, false,
-                                                      ParsedType(),
-                                            /*NontrivialTypeSourceInfo=*/true),
-                                  TemplateId->TemplateNameLoc, 
+        ParsedType Ty = Actions.getTypeName(*TemplateId->Name,
+                                            TemplateId->TemplateNameLoc,
+                                            getCurScope(),
+                                            &SS, false, false,
+                                            ParsedType(),
+                                            /*IsCtorOrDtorName=*/true,
+                                            /*NontrivialTypeSourceInfo=*/true);
+        Result.setConstructorName(Ty, TemplateId->TemplateNameLoc,
                                   TemplateId->RAngleLoc);
         ConsumeToken();
         return false;
index 7f7fdf7c448b503d3d419eadef495f250db72a03..da1424c6b1b80fb6c4ba6706ea4d41dbfc6a490d 100644 (file)
@@ -1279,6 +1279,7 @@ bool Parser::TryAnnotateTypeOrScopeToken(bool EnteringContext, bool NeedType) {
                                             &SS, false, 
                                             NextToken().is(tok::period),
                                             ParsedType(),
+                                            /*IsCtorOrDtorName=*/false,
                                             /*NonTrivialTypeSourceInfo*/true,
                                             NeedType ? &CorrectedII : NULL)) {
       // A FixIt was applied as a result of typo correction
index e7ff5c5400adb1cae09776b86095604bc6a5bd2a..a6e1e401b3ab2dd3c5e40ccb12ce677cfcea45fc 100644 (file)
@@ -94,6 +94,7 @@ ParsedType Sema::getTypeName(IdentifierInfo &II, SourceLocation NameLoc,
                              Scope *S, CXXScopeSpec *SS,
                              bool isClassName, bool HasTrailingDot,
                              ParsedType ObjectTypePtr,
+                             bool IsCtorOrDtorName,
                              bool WantNontrivialTypeSourceInfo,
                              IdentifierInfo **CorrectedII) {
   // Determine where we will perform name lookup.
@@ -194,6 +195,7 @@ ParsedType Sema::getTypeName(IdentifierInfo &II, SourceLocation NameLoc,
                            false, Template, MemberOfUnknownSpecialization))) {
         ParsedType Ty = getTypeName(*NewII, NameLoc, S, NewSSPtr,
                                     isClassName, HasTrailingDot, ObjectTypePtr,
+                                    IsCtorOrDtorName,
                                     WantNontrivialTypeSourceInfo);
         if (Ty) {
           std::string CorrectedStr(Correction.getAsString(getLangOptions()));
@@ -272,8 +274,11 @@ ParsedType Sema::getTypeName(IdentifierInfo &II, SourceLocation NameLoc,
 
     if (T.isNull())
       T = Context.getTypeDeclType(TD);
-    
-    if (SS && SS->isNotEmpty()) {
+
+    // NOTE: avoid constructing an ElaboratedType(Loc) if this is a
+    // constructor or destructor name (in such a case, the scope specifier
+    // will be attached to the enclosing Expr or Decl node).
+    if (SS && SS->isNotEmpty() && !IsCtorOrDtorName) {
       if (WantNontrivialTypeSourceInfo) {
         // Construct a type with type-source information.
         TypeLocBuilder Builder;
@@ -394,6 +399,7 @@ bool Sema::DiagnoseUnknownTypeName(const IdentifierInfo &II,
 
       SuggestedType = getTypeName(*Result->getIdentifier(), IILoc, S, SS,
                                   false, false, ParsedType(),
+                                  /*IsCtorOrDtorName=*/false,
                                   /*NonTrivialTypeSourceInfo=*/true);
     }
     return true;
index 0c66133968099983b24e9a06a250fdda44c93e97..3b1a03d9c508703af30093b29d6d76ec96c5ec9c 100644 (file)
@@ -2045,7 +2045,8 @@ Sema::ActOnTemplateIdType(CXXScopeSpec &SS,
                           TemplateTy TemplateD, SourceLocation TemplateLoc,
                           SourceLocation LAngleLoc,
                           ASTTemplateArgsPtr TemplateArgsIn,
-                          SourceLocation RAngleLoc) {
+                          SourceLocation RAngleLoc,
+                          bool IsCtorOrDtorName) {
   if (SS.isInvalid())
     return true;
 
@@ -2056,12 +2057,12 @@ Sema::ActOnTemplateIdType(CXXScopeSpec &SS,
   translateTemplateArguments(TemplateArgsIn, TemplateArgs);
 
   if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
-    QualType T = Context.getDependentTemplateSpecializationType(ETK_None,
-                                                           DTN->getQualifier(), 
-                                                           DTN->getIdentifier(), 
-                                                                TemplateArgs);
-    
-    // Build type-source information.    
+    QualType T
+      = Context.getDependentTemplateSpecializationType(ETK_None,
+                                                       DTN->getQualifier(),
+                                                       DTN->getIdentifier(),
+                                                       TemplateArgs);
+    // Build type-source information.
     TypeLocBuilder TLB;
     DependentTemplateSpecializationTypeLoc SpecTL
       = TLB.push<DependentTemplateSpecializationTypeLoc>(T);
@@ -2091,7 +2092,10 @@ Sema::ActOnTemplateIdType(CXXScopeSpec &SS,
   for (unsigned i = 0, e = SpecTL.getNumArgs(); i != e; ++i)
     SpecTL.setArgLocInfo(i, TemplateArgs[i].getLocInfo());
 
-  if (SS.isNotEmpty()) {
+  // NOTE: avoid constructing an ElaboratedTypeLoc if this is a
+  // constructor or destructor name (in such a case, the scope specifier
+  // will be attached to the enclosing Decl or Expr node).
+  if (SS.isNotEmpty() && !IsCtorOrDtorName) {
     // Create an elaborated-type-specifier containing the nested-name-specifier.
     Result = Context.getElaboratedType(ETK_None, SS.getScopeRep(), Result);
     ElaboratedTypeLoc ElabTL = TLB.push<ElaboratedTypeLoc>(Result);