void mergeDeclAttributes(NamedDecl *New, Decl *Old,
AvailabilityMergeKind AMK = AMK_Redeclaration);
void MergeTypedefNameDecl(TypedefNameDecl *New, LookupResult &OldDecls);
- bool MergeFunctionDecl(FunctionDecl *New, Decl *Old, Scope *S,
+ bool MergeFunctionDecl(FunctionDecl *New, NamedDecl *&Old, Scope *S,
bool MergeTypeWithOld);
bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old,
Scope *S, bool MergeTypeWithOld);
/// merged with.
///
/// Returns true if there was an error, false otherwise.
-bool Sema::MergeFunctionDecl(FunctionDecl *New, Decl *OldD, Scope *S,
- bool MergeTypeWithOld) {
+bool Sema::MergeFunctionDecl(FunctionDecl *New, NamedDecl *&OldD,
+ Scope *S, bool MergeTypeWithOld) {
// Verify the old decl was also a function.
FunctionDecl *Old = OldD->getAsFunction();
if (!Old) {
return true;
}
- Diag(New->getLocation(), diag::err_using_decl_conflict_reverse);
- Diag(Shadow->getTargetDecl()->getLocation(),
- diag::note_using_decl_target);
- Diag(Shadow->getUsingDecl()->getLocation(),
- diag::note_using_decl) << 0;
+ // C++11 [namespace.udecl]p14:
+ // If a function declaration in namespace scope or block scope has the
+ // same name and the same parameter-type-list as a function introduced
+ // by a using-declaration, and the declarations do not declare the same
+ // function, the program is ill-formed.
+
+ // Check whether the two declarations might declare the same function.
+ Old = dyn_cast<FunctionDecl>(Shadow->getTargetDecl());
+ if (Old &&
+ !Old->getDeclContext()->getRedeclContext()->Equals(
+ New->getDeclContext()->getRedeclContext()) &&
+ !(Old->isExternC() && New->isExternC()))
+ Old = 0;
+
+ if (!Old) {
+ Diag(New->getLocation(), diag::err_using_decl_conflict_reverse);
+ Diag(Shadow->getTargetDecl()->getLocation(),
+ diag::note_using_decl_target);
+ Diag(Shadow->getUsingDecl()->getLocation(), diag::note_using_decl) << 0;
+ return true;
+ }
+ OldD = Old;
+ } else {
+ Diag(New->getLocation(), diag::err_redefinition_different_kind)
+ << New->getDeclName();
+ Diag(OldD->getLocation(), diag::note_previous_definition);
return true;
}
-
- Diag(New->getLocation(), diag::err_redefinition_different_kind)
- << New->getDeclName();
- Diag(OldD->getLocation(), diag::note_previous_definition);
- return true;
}
// If the old declaration is invalid, just give up here.
case Ovl_NonFunction:
Diag(Using->getLocation(), diag::err_using_decl_conflict);
break;
-
+
// We found a decl with the exact signature.
case Ovl_Match:
// If we're in a record, we want to hide the target, so we
// RUN: %clang_cc1 -fsyntax-only -verify %s
-// C++03 [namespace.udecl]p11:
+// C++03 [namespace.udecl]p11: (per DR101)
// If a function declaration in namespace scope or block scope has
// the same name and the same parameter types as a function
-// introduced by a using-declaration, the program is
-// ill-formed. [Note: two using-declarations may introduce functions
-// with the same name and the same parameter types. If, for a call
-// to an unqualified function name, function overload resolution
-// selects the functions introduced by such using-declarations, the
-// function call is ill-formed.
+// introduced by a using-declaration, and the declarations do not declare the
+// same function, the program is ill-formed. [Note: two using-declarations may
+// introduce functions with the same name and the same parameter types. If,
+// for a call to an unqualified function name, function overload resolution
+// selects the functions introduced by such using-declarations, the function
+// call is ill-formed.]
+//
+// FIXME: DR565 introduces parallel wording here for function templates.
namespace test0 {
namespace ns { void foo(); } // expected-note {{target of using declaration}}
template class Test0<int>;
template class Test1<int>;
}
+
+namespace test6 {
+ namespace ns { void foo(); } // expected-note {{target of using declaration}}
+ using ns::foo; // expected-note {{using declaration}}
+ namespace ns {
+ using test6::foo;
+ void foo() {}
+ }
+ void foo(); // expected-error {{declaration conflicts with target of using declaration already in scope}}
+}
B<"bar"> b; // expected-error {{does not refer to any declaration}}
}
-namespace dr101 { // dr101: yes
+namespace dr101 { // dr101: 3.5
extern "C" void dr101_f();
typedef unsigned size_t;
namespace X {
}
using X::dr101_f;
using X::size_t;
+ extern "C" void dr101_f();
+ typedef unsigned size_t;
}
namespace dr102 { // dr102: yes
int f(int);
static void g(int);
-// expected-error@-1 {{declaration conflicts with target of using declaration already in scope}}
-// expected-note@Inputs/linkage-merge-foo.h:2 {{target of using declaration}}
-// expected-note@Inputs/linkage-merge-bar.h:3 {{using declaration}}
+// expected-error@-1 {{functions that differ only in their return type cannot be overloaded}}
+// expected-note@Inputs/linkage-merge-foo.h:2 {{previous declaration is here}}
<td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#101">101</a></td>
<td>TC1</td>
<td>Redeclaration of extern "C" names via using-declarations</td>
- <td class="full" align="center">Yes</td>
+ <td class="svn" align="center">SVN</td>
</tr>
<tr>
<td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_closed.html#102">102</a></td>