diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2014-02-17 23:25:27 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2014-02-17 23:25:27 +0000 |
commit | 4ee696d55cbb4512b1d3e41ad094b78f32a2025e (patch) | |
tree | c1f7de3bcf218b788459814fc6f8c6f0937045c4 /clang/lib/Parse/ParseDeclCXX.cpp | |
parent | 846a627f5ca4cc72d4256c3b6b2051a49e13eb89 (diff) | |
download | bcm5719-llvm-4ee696d55cbb4512b1d3e41ad094b78f32a2025e.tar.gz bcm5719-llvm-4ee696d55cbb4512b1d3e41ad094b78f32a2025e.zip |
PR18870: Parse language linkage specifiers properly if the string-literal is
spelled in an interesting way.
llvm-svn: 201536
Diffstat (limited to 'clang/lib/Parse/ParseDeclCXX.cpp')
-rw-r--r-- | clang/lib/Parse/ParseDeclCXX.cpp | 37 |
1 files changed, 14 insertions, 23 deletions
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index 5d68453e3fb..b95eb87a6fa 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -279,27 +279,16 @@ Decl *Parser::ParseNamespaceAlias(SourceLocation NamespaceLoc, /// 'extern' string-literal declaration /// Decl *Parser::ParseLinkage(ParsingDeclSpec &DS, unsigned Context) { - assert(Tok.is(tok::string_literal) && "Not a string literal!"); - SmallString<8> LangBuffer; - bool Invalid = false; - StringRef Lang = PP.getSpelling(Tok, LangBuffer, &Invalid); - if (Invalid) - return 0; - - // FIXME: This is incorrect: linkage-specifiers are parsed in translation - // phase 7, so string-literal concatenation is supposed to occur. - // extern "" "C" "" "+" "+" { } is legal. - if (Tok.hasUDSuffix()) - Diag(Tok, diag::err_invalid_string_udl); - SourceLocation Loc = ConsumeStringToken(); + assert(isTokenStringLiteral() && "Not a string literal!"); + ExprResult Lang = ParseStringLiteralExpression(false); ParseScope LinkageScope(this, Scope::DeclScope); - Decl *LinkageSpec - = Actions.ActOnStartLinkageSpecification(getCurScope(), - DS.getSourceRange().getBegin(), - Loc, Lang, - Tok.is(tok::l_brace) ? Tok.getLocation() - : SourceLocation()); + Decl *LinkageSpec = + Lang.isInvalid() + ? 0 + : Actions.ActOnStartLinkageSpecification( + getCurScope(), DS.getSourceRange().getBegin(), Lang.take(), + Tok.is(tok::l_brace) ? Tok.getLocation() : SourceLocation()); ParsedAttributesWithRange attrs(AttrFactory); MaybeParseCXX11Attributes(attrs); @@ -313,8 +302,9 @@ Decl *Parser::ParseLinkage(ParsingDeclSpec &DS, unsigned Context) { // ... but anyway remember that such an "extern" was seen. DS.setExternInLinkageSpec(true); ParseExternalDeclaration(attrs, &DS); - return Actions.ActOnFinishLinkageSpecification(getCurScope(), LinkageSpec, - SourceLocation()); + return LinkageSpec ? Actions.ActOnFinishLinkageSpecification( + getCurScope(), LinkageSpec, SourceLocation()) + : 0; } DS.abort(); @@ -331,8 +321,9 @@ Decl *Parser::ParseLinkage(ParsingDeclSpec &DS, unsigned Context) { } T.consumeClose(); - return Actions.ActOnFinishLinkageSpecification(getCurScope(), LinkageSpec, - T.getCloseLocation()); + return LinkageSpec ? Actions.ActOnFinishLinkageSpecification( + getCurScope(), LinkageSpec, T.getCloseLocation()) + : 0; } /// ParseUsingDirectiveOrDeclaration - Parse C++ using using-declaration or |