diff options
Diffstat (limited to 'clang/lib/Parse/ParseDeclCXX.cpp')
| -rw-r--r-- | clang/lib/Parse/ParseDeclCXX.cpp | 79 |
1 files changed, 63 insertions, 16 deletions
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index 4002b09d2bc..d31d1142374 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -560,9 +560,7 @@ bool Parser::ParseUsingDeclarator(unsigned Context, UsingDeclarator &D) { // nested-name-specifier, the name is [...] considered to name the // constructor. if (getLangOpts().CPlusPlus11 && Context == Declarator::MemberContext && - Tok.is(tok::identifier) && - (NextToken().is(tok::semi) || NextToken().is(tok::comma) || - NextToken().is(tok::ellipsis)) && + Tok.is(tok::identifier) && NextToken().is(tok::semi) && D.SS.isNotEmpty() && LastII == Tok.getIdentifierInfo() && !D.SS.getScopeRep()->getAsNamespace() && !D.SS.getScopeRep()->getAsNamespaceAlias()) { @@ -580,10 +578,7 @@ bool Parser::ParseUsingDeclarator(unsigned Context, UsingDeclarator &D) { return true; } - if (TryConsumeToken(tok::ellipsis, D.EllipsisLoc)) - Diag(Tok.getLocation(), getLangOpts().CPlusPlus1z ? - diag::warn_cxx1z_compat_using_declaration_pack : - diag::ext_using_declaration_pack); + // FIXME: Parse optional ellipsis return false; } @@ -683,9 +678,9 @@ Parser::ParseUsingDeclaration(unsigned Context, D.TypenameLoc = SourceLocation(); } - Decl *UD = Actions.ActOnUsingDeclaration(getCurScope(), AS, UsingLoc, - D.TypenameLoc, D.SS, D.Name, - D.EllipsisLoc, Attrs.getList()); + Decl *UD = + Actions.ActOnUsingDeclaration(getCurScope(), AS, UsingLoc, D.SS, + D.Name, Attrs.getList(), D.TypenameLoc); if (UD) DeclsInGroup.push_back(UD); } @@ -713,6 +708,62 @@ Parser::ParseUsingDeclaration(unsigned Context, return Actions.BuildDeclaratorGroup(DeclsInGroup, /*MayContainAuto*/false); } +Decl *Parser::ParseAliasTemplate(const ParsedTemplateInfo &TemplateInfo, + SourceLocation &DeclEnd, AccessSpecifier AS, + ParsedAttributesWithRange &MisplacedAttrs1) { + assert(Tok.is(tok::kw_using) && "Not using token"); + ObjCDeclContextSwitch ObjCDC(*this); + + // Eat 'using'. + SourceLocation UsingLoc = ConsumeToken(); + if (Tok.is(tok::code_completion)) { + Actions.CodeCompleteUsing(getCurScope()); + cutOffParsing(); + return nullptr; + } + + // 'using namespace' means this is a using-directive. + if (Tok.is(tok::kw_namespace)) { + SourceRange R = TemplateInfo.getSourceRange(); + Diag(UsingLoc, diag::err_templated_using_directive_declaration) + << 0 /* directive */ << R; + SkipUntil(tok::semi); + return nullptr; + } + + // Check for misplaced attributes before the identifier. + ParsedAttributesWithRange MisplacedAttrs2(AttrFactory); + MaybeParseCXX11Attributes(MisplacedAttrs2); + + // FIXME: Just parse an identifier here? + UsingDeclarator D; + if (ParseUsingDeclarator(Declarator::FileContext, D)) { + SkipUntil(tok::semi); + return nullptr; + } + + ParsedAttributesWithRange Attrs(AttrFactory); + + // If we had any misplaced attributes from earlier, this is where they + // should have been written. + for (auto *MisplacedAttrs : {&MisplacedAttrs1, &MisplacedAttrs2}) { + if (MisplacedAttrs->Range.isValid()) { + Diag(MisplacedAttrs->Range.getBegin(), diag::err_attributes_not_allowed) + << FixItHint::CreateInsertionFromRange( + Tok.getLocation(), + CharSourceRange::getTokenRange(MisplacedAttrs->Range)) + << FixItHint::CreateRemoval(MisplacedAttrs->Range); + Attrs.takeAllFrom(*MisplacedAttrs); + } + } + + MaybeParseGNUAttributes(Attrs); + MaybeParseCXX11Attributes(Attrs); + + return ParseAliasDeclarationAfterDeclarator(TemplateInfo, UsingLoc, D, + DeclEnd, AS, Attrs); +} + Decl *Parser::ParseAliasDeclarationAfterDeclarator( const ParsedTemplateInfo &TemplateInfo, SourceLocation UsingLoc, UsingDeclarator &D, SourceLocation &DeclEnd, AccessSpecifier AS, @@ -762,9 +813,6 @@ Decl *Parser::ParseAliasDeclarationAfterDeclarator( else if (D.SS.isNotEmpty()) Diag(D.SS.getBeginLoc(), diag::err_alias_declaration_not_identifier) << FixItHint::CreateRemoval(D.SS.getRange()); - if (D.EllipsisLoc.isValid()) - Diag(D.EllipsisLoc, diag::err_alias_declaration_pack_expansion) - << FixItHint::CreateRemoval(SourceRange(D.EllipsisLoc)); Decl *DeclFromDeclSpec = nullptr; TypeResult TypeAlias = @@ -2439,9 +2487,8 @@ Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS, } return DeclGroupPtrTy::make(DeclGroupRef(Actions.ActOnUsingDeclaration( - getCurScope(), AS, /*UsingLoc*/ SourceLocation(), - /*TypenameLoc*/ SourceLocation(), SS, Name, - /*EllipsisLoc*/ SourceLocation(), /*AttrList*/ nullptr))); + getCurScope(), AS, /*UsingLoc*/SourceLocation(), SS, Name, + /*AttrList*/nullptr, /*TypenameLoc*/SourceLocation()))); } } |

