r321686 - PR35697: look at the first declaration when determining whether a function or
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 2 18:34:35 PST 2018
Author: rsmith
Date: Tue Jan 2 18:34:35 2018
New Revision: 321686
URL: http://llvm.org/viewvc/llvm-project?rev=321686&view=rev
Log:
PR35697: look at the first declaration when determining whether a function or
variable is extern "C" in linkage calculations.
Modified:
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/test/SemaCXX/extern-c.cpp
Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=321686&r1=321685&r2=321686&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Tue Jan 2 18:34:35 2018
@@ -779,7 +779,7 @@ LinkageComputer::getLVForNamespaceScopeD
// unique-external linkage, it's not legally usable from outside
// this translation unit. However, we should use the C linkage
// rules instead for extern "C" declarations.
- if (Context.getLangOpts().CPlusPlus && !Function->isInExternCContext()) {
+ if (Context.getLangOpts().CPlusPlus && !isFirstInExternCContext(Function)) {
// Only look at the type-as-written. Otherwise, deducing the return type
// of a function could change its linkage.
QualType TypeAsWritten = Function->getType();
@@ -1165,7 +1165,7 @@ LinkageInfo LinkageComputer::getLVForLoc
LVComputationKind computation) {
if (const auto *Function = dyn_cast<FunctionDecl>(D)) {
if (Function->isInAnonymousNamespace() &&
- !Function->isInExternCContext())
+ !isFirstInExternCContext(Function))
return getInternalLinkageFor(Function);
// This is a "void f();" which got merged with a file static.
@@ -1188,7 +1188,7 @@ LinkageInfo LinkageComputer::getLVForLoc
if (const auto *Var = dyn_cast<VarDecl>(D)) {
if (Var->hasExternalStorage()) {
- if (Var->isInAnonymousNamespace() && !Var->isInExternCContext())
+ if (Var->isInAnonymousNamespace() && !isFirstInExternCContext(Var))
return getInternalLinkageFor(Var);
LinkageInfo LV;
Modified: cfe/trunk/test/SemaCXX/extern-c.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/extern-c.cpp?rev=321686&r1=321685&r2=321686&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/extern-c.cpp (original)
+++ cfe/trunk/test/SemaCXX/extern-c.cpp Tue Jan 2 18:34:35 2018
@@ -242,3 +242,20 @@ namespace tag_hiding {
ExternCStruct3 *q3 = p3;
ExternCStruct4 *q4 = p4; // expected-error {{ambiguous}}
}
+
+namespace PR35697 {
+ typedef struct {} *ReturnStruct;
+ extern "C" ReturnStruct PR35697_f();
+ extern "C" ReturnStruct PR35697_v;
+ ReturnStruct PR35697_f();
+ ReturnStruct PR35697_v;
+
+ namespace {
+ extern "C" ReturnStruct PR35697_f();
+ extern "C" ReturnStruct PR35697_v;
+ void q() {
+ extern ReturnStruct PR35697_f();
+ extern ReturnStruct PR35697_v;
+ }
+ }
+}
More information about the cfe-commits
mailing list