From 09a63c97b95eb4dc6fd6b2323929e8cf12af03ff Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Tue, 24 Aug 2010 14:14:45 +0000 Subject: [PATCH] Parse all kinds of declarations as part of a linkage-specification, from Francois Pichet! Fixes PR7754. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111912 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Parse/Parser.h | 3 ++- lib/Parse/ParseDeclCXX.cpp | 2 +- lib/Parse/Parser.cpp | 8 ++++++-- test/SemaCXX/linkage-spec.cpp | 9 +++++++++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h index cc82c0b0a5..ceaeb34ee5 100644 --- a/include/clang/Parse/Parser.h +++ b/include/clang/Parse/Parser.h @@ -859,7 +859,8 @@ private: //===--------------------------------------------------------------------===// // C99 6.9: External Definitions. - DeclGroupPtrTy ParseExternalDeclaration(CXX0XAttributeList Attr); + DeclGroupPtrTy ParseExternalDeclaration(CXX0XAttributeList Attr, + ParsingDeclSpec *DS = 0); bool isDeclarationAfterDeclarator() const; bool isStartOfFunctionDefinition(const ParsingDeclarator &Declarator); DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(AttributeList *Attr, diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp index e412f25dbb..d80410c9ee 100644 --- a/lib/Parse/ParseDeclCXX.cpp +++ b/lib/Parse/ParseDeclCXX.cpp @@ -197,7 +197,7 @@ Decl *Parser::ParseLinkage(ParsingDeclSpec &DS, if (Tok.isNot(tok::l_brace)) { DS.setExternInLinkageSpec(true); - ParseDeclarationOrFunctionDefinition(DS, Attr.AttrList); + ParseExternalDeclaration(Attr, &DS); return Actions.ActOnFinishLinkageSpecification(getCurScope(), LinkageSpec, SourceLocation()); } diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp index 2f5070c4c3..8fd1e48994 100644 --- a/lib/Parse/Parser.cpp +++ b/lib/Parse/Parser.cpp @@ -405,7 +405,8 @@ void Parser::ParseTranslationUnit() { /// ';' /// /// [C++0x/GNU] 'extern' 'template' declaration -Parser::DeclGroupPtrTy Parser::ParseExternalDeclaration(CXX0XAttributeList Attr) { +Parser::DeclGroupPtrTy Parser::ParseExternalDeclaration(CXX0XAttributeList Attr, + ParsingDeclSpec *DS) { ParenBraceBracketBalancer BalancerRAIIObj(*this); Decl *SingleDecl = 0; @@ -494,7 +495,10 @@ Parser::DeclGroupPtrTy Parser::ParseExternalDeclaration(CXX0XAttributeList Attr) default: // We can't tell whether this is a function-definition or declaration yet. - return ParseDeclarationOrFunctionDefinition(Attr.AttrList); + if (DS) + return ParseDeclarationOrFunctionDefinition(*DS, Attr.AttrList); + else + return ParseDeclarationOrFunctionDefinition(Attr.AttrList); } // This routine returns a DeclGroup, if the thing we parsed only contains a diff --git a/test/SemaCXX/linkage-spec.cpp b/test/SemaCXX/linkage-spec.cpp index b2e8eb2ee8..86c3d3e87a 100644 --- a/test/SemaCXX/linkage-spec.cpp +++ b/test/SemaCXX/linkage-spec.cpp @@ -77,3 +77,12 @@ extern "C" { s0(const s0 &); }; } + +//PR7754 +extern "C++" template int pr7754(T param); + +namespace N { + int value; +} + +extern "C++" using N::value; -- 2.40.0