Added checks to make sure the return type and parameter types for functions
declared as extern "C" have external linkage.
Details
- Reviewers
- None
Diff Detail
Event Timeline
Here's an example of when this will cause a crash:
namespace {
Struct G;
extern "C" G *f(); has external linkage
G *f(); will assert since it has internal linkage because of G and doesn't match previous declaration
}
This also causes a few other test failures (~8) which will need to be fixed if this patch is accepted.
This change breaks a couple tests in test/SemaCXX/linkage.cpp where we no longer allow mixing internal and external linkage, i.e., extern "C" functions have external linkage no matter where they are declared, but return types and parameters declared in anonymous namespaces have internal linkage.
Not yet sure how to go about fixing those, but one was based on PR9316, however, the test is more complicated and is invalid -- so we don't generate code.
Why do you think this is ill-formed? Using a type with internal linkage as the type of an extern "C" function is explicitly permitted by the C++ standard. [basic.link]p8 says:
"A type without linkage shall not be used as the type of a variable or function with external linkage unless the entity has C language linkage [...]."