CheckShadow(S, D, R);
}
+template<typename T>
+static bool mayConflictWithNonVisibleExternC(const T *ND) {
+ VarDecl::StorageClass SC = ND->getStorageClass();
+ if (ND->hasCLanguageLinkage() && (SC == SC_Extern || SC == SC_PrivateExtern))
+ return true;
+ return ND->getDeclContext()->isTranslationUnit();
+}
+
/// \brief Perform semantic checking on a newly-created variable
/// declaration.
///
NewVD->setTypeSourceInfo(FixedTInfo);
}
- if (Previous.empty() && NewVD->isExternC()) {
- // Since we did not find anything by this name and we're declaring
- // an extern "C" variable, look for a non-visible extern "C"
- // declaration with the same name.
+ if (Previous.empty() && mayConflictWithNonVisibleExternC(NewVD)) {
+ // Since we did not find anything by this name, look for a non-visible
+ // extern "C" declaration with the same name.
llvm::DenseMap<DeclarationName, NamedDecl *>::iterator Pos
= findLocallyScopedExternCDecl(NewVD->getDeclName());
if (Pos != LocallyScopedExternCDecls.end())
&& "Variably modified return types are not handled here");
// Check for a previous declaration of this name.
- if (Previous.empty() && NewFD->isExternC()) {
- // Since we did not find anything by this name and we're declaring
- // an extern "C" function, look for a non-visible extern "C"
- // declaration with the same name.
+ if (Previous.empty() && mayConflictWithNonVisibleExternC(NewFD)) {
+ // Since we did not find anything by this name, look for a non-visible
+ // extern "C" declaration with the same name.
llvm::DenseMap<DeclarationName, NamedDecl *>::iterator Pos
= findLocallyScopedExternCDecl(NewFD->getDeclName());
if (Pos != LocallyScopedExternCDecls.end())
}
void Foo::beEvil() {} // expected-error {{out-of-line definition of 'beEvil' does not match any declaration in namespace 'redecl_typo::Foo'; did you mean 'BeEvil'?}}
}
+
+namespace test2 {
+ extern "C" {
+ void f() {
+ void test2_g(int); // expected-note {{previous declaration is here}}
+ }
+ }
+}
+int test2_g(int); // expected-error {{functions that differ only in their return type cannot be overloaded}}
+
+namespace test3 {
+ extern "C" {
+ void f() {
+ extern int test3_x; // expected-note {{previous definition is here}}
+ }
+ }
+}
+float test3_x; // expected-error {{redefinition of 'test3_x' with a different type: 'float' vs 'int'}}