From: Richard Smith Date: Fri, 22 Jun 2018 19:50:19 +0000 (+0000) Subject: Restore pre-r335182 behavior for naming inherited constructors as X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=257046ff24322a46dd7b74649f16d559fadf4a29;p=clang Restore pre-r335182 behavior for naming inherited constructors as members of dependent contexts. This permits cases where the names before and after the '::' in a dependent inherited constructor using-declaration do not match, but where we can nonetheless tell when parsing the template that a constructor is being named. Under (open) core language DR 2070, such cases will probably be ill-formed, but r335182 does not quite give that result and didn't intend to change this, so restore the old behavior for now. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@335381 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 5d2f4f0811..5780cc01d7 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -4985,7 +4985,8 @@ public: IdentifierInfo &Name); ParsedType getConstructorName(IdentifierInfo &II, SourceLocation NameLoc, - Scope *S, CXXScopeSpec &SS); + Scope *S, CXXScopeSpec &SS, + bool EnteringContext); ParsedType getDestructorName(SourceLocation TildeLoc, IdentifierInfo &II, SourceLocation NameLoc, Scope *S, CXXScopeSpec &SS, diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp index 26b8a0f779..12aee8cff3 100644 --- a/lib/Parse/ParseExprCXX.cpp +++ b/lib/Parse/ParseExprCXX.cpp @@ -2505,7 +2505,8 @@ bool Parser::ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext, if (AllowConstructorName && Actions.isCurrentClassName(*Id, getCurScope(), &SS)) { // We have parsed a constructor name. - ParsedType Ty = Actions.getConstructorName(*Id, IdLoc, getCurScope(), SS); + ParsedType Ty = Actions.getConstructorName(*Id, IdLoc, getCurScope(), SS, + EnteringContext); if (!Ty) return true; Result.setConstructorName(Ty, IdLoc, IdLoc); @@ -2555,7 +2556,8 @@ bool Parser::ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext, << FixItHint::CreateRemoval( SourceRange(TemplateId->LAngleLoc, TemplateId->RAngleLoc)); ParsedType Ty = Actions.getConstructorName( - *TemplateId->Name, TemplateId->TemplateNameLoc, getCurScope(), SS); + *TemplateId->Name, TemplateId->TemplateNameLoc, getCurScope(), SS, + EnteringContext); if (!Ty) return true; Result.setConstructorName(Ty, TemplateId->TemplateNameLoc, diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index d977ea3453..59066ee34f 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -82,11 +82,20 @@ ParsedType Sema::getInheritingConstructorName(CXXScopeSpec &SS, ParsedType Sema::getConstructorName(IdentifierInfo &II, SourceLocation NameLoc, - Scope *S, CXXScopeSpec &SS) { + Scope *S, CXXScopeSpec &SS, + bool EnteringContext) { CXXRecordDecl *CurClass = getCurrentClass(S, &SS); assert(CurClass && &II == CurClass->getIdentifier() && "not a constructor name"); + // When naming a constructor as a member of a dependent context (eg, in a + // friend declaration or an inherited constructor declaration), form an + // unresolved "typename" type. + if (CurClass->isDependentContext() && !EnteringContext) { + QualType T = Context.getDependentNameType(ETK_None, SS.getScopeRep(), &II); + return ParsedType::make(T); + } + if (SS.isNotEmpty() && RequireCompleteDeclContext(SS, CurClass)) return ParsedType(); diff --git a/test/CXX/basic/basic.lookup/basic.lookup.qual/class.qual/p2.cpp b/test/CXX/basic/basic.lookup/basic.lookup.qual/class.qual/p2.cpp index cf58a85d84..73e0369e60 100644 --- a/test/CXX/basic/basic.lookup/basic.lookup.qual/class.qual/p2.cpp +++ b/test/CXX/basic/basic.lookup/basic.lookup.qual/class.qual/p2.cpp @@ -199,5 +199,20 @@ namespace InhCtor { using T::T; // expected-error {{type 'int' cannot be used prior to '::' because it has no members}} }; UsingIntTemplate uit; // expected-note {{here}} + + // This case is odd: we don't name the constructor of a dependent base as + // Base::Base, but we still happen to have enough information to identify + // when parsing the template that we're inheriting constructors. + // + // FIXME: Once CWG 2070 is resolved, check whether this case should be + // accepted or not. + namespace DependentCtorName { + template struct B { B(int); }; + template struct A : B { + using X = B; + using X::B; + }; + A ab = 0; + } #endif }