1a5728872c7702ddd09537c95bc3cbd20e1f2fb09Daniel Dunbar// RUN: %clang_cc1 -fsyntax-only -verify %s 241ce66f8e20159d8bd39fff54ae01608da06c294John McCall 3651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// C++03 [namespace.udecl]p11: (per DR101) 441ce66f8e20159d8bd39fff54ae01608da06c294John McCall// If a function declaration in namespace scope or block scope has 541ce66f8e20159d8bd39fff54ae01608da06c294John McCall// the same name and the same parameter types as a function 6651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// introduced by a using-declaration, and the declarations do not declare the 7651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// same function, the program is ill-formed. [Note: two using-declarations may 8651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// introduce functions with the same name and the same parameter types. If, 9651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// for a call to an unqualified function name, function overload resolution 10651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// selects the functions introduced by such using-declarations, the function 11651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// call is ill-formed.] 12651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// 13651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// FIXME: DR565 introduces parallel wording here for function templates. 1441ce66f8e20159d8bd39fff54ae01608da06c294John McCall 1541ce66f8e20159d8bd39fff54ae01608da06c294John McCallnamespace test0 { 1641ce66f8e20159d8bd39fff54ae01608da06c294John McCall namespace ns { void foo(); } // expected-note {{target of using declaration}} 177984de35644701c0d94336da7f2215d4c26d9f5bRichard Smith int foo(void); // expected-note {{conflicting declaration}} 1841ce66f8e20159d8bd39fff54ae01608da06c294John McCall using ns::foo; // expected-error {{target of using declaration conflicts with declaration already in scope}} 1941ce66f8e20159d8bd39fff54ae01608da06c294John McCall} 2041ce66f8e20159d8bd39fff54ae01608da06c294John McCall 2141ce66f8e20159d8bd39fff54ae01608da06c294John McCallnamespace test1 { 2241ce66f8e20159d8bd39fff54ae01608da06c294John McCall namespace ns { void foo(); } // expected-note {{target of using declaration}} 2341ce66f8e20159d8bd39fff54ae01608da06c294John McCall using ns::foo; //expected-note {{using declaration}} 247984de35644701c0d94336da7f2215d4c26d9f5bRichard Smith int foo(void); // expected-error {{declaration conflicts with target of using declaration already in scope}} 2541ce66f8e20159d8bd39fff54ae01608da06c294John McCall} 2641ce66f8e20159d8bd39fff54ae01608da06c294John McCall 2741ce66f8e20159d8bd39fff54ae01608da06c294John McCallnamespace test2 { 2841ce66f8e20159d8bd39fff54ae01608da06c294John McCall namespace ns { void foo(); } // expected-note 2 {{target of using declaration}} 2941ce66f8e20159d8bd39fff54ae01608da06c294John McCall void test0() { 307984de35644701c0d94336da7f2215d4c26d9f5bRichard Smith int foo(void); // expected-note {{conflicting declaration}} 3141ce66f8e20159d8bd39fff54ae01608da06c294John McCall using ns::foo; // expected-error {{target of using declaration conflicts with declaration already in scope}} 3241ce66f8e20159d8bd39fff54ae01608da06c294John McCall } 3341ce66f8e20159d8bd39fff54ae01608da06c294John McCall 3441ce66f8e20159d8bd39fff54ae01608da06c294John McCall void test1() { 3541ce66f8e20159d8bd39fff54ae01608da06c294John McCall using ns::foo; //expected-note {{using declaration}} 367984de35644701c0d94336da7f2215d4c26d9f5bRichard Smith int foo(void); // expected-error {{declaration conflicts with target of using declaration already in scope}} 3741ce66f8e20159d8bd39fff54ae01608da06c294John McCall } 3841ce66f8e20159d8bd39fff54ae01608da06c294John McCall} 3941ce66f8e20159d8bd39fff54ae01608da06c294John McCall 4041ce66f8e20159d8bd39fff54ae01608da06c294John McCallnamespace test3 { 4141ce66f8e20159d8bd39fff54ae01608da06c294John McCall namespace ns { void foo(); } // expected-note 2 {{target of using declaration}} 4241ce66f8e20159d8bd39fff54ae01608da06c294John McCall class Test0 { 4341ce66f8e20159d8bd39fff54ae01608da06c294John McCall void test() { 447984de35644701c0d94336da7f2215d4c26d9f5bRichard Smith int foo(void); // expected-note {{conflicting declaration}} 4541ce66f8e20159d8bd39fff54ae01608da06c294John McCall using ns::foo; // expected-error {{target of using declaration conflicts with declaration already in scope}} 4641ce66f8e20159d8bd39fff54ae01608da06c294John McCall } 4741ce66f8e20159d8bd39fff54ae01608da06c294John McCall }; 4841ce66f8e20159d8bd39fff54ae01608da06c294John McCall 4941ce66f8e20159d8bd39fff54ae01608da06c294John McCall class Test1 { 5041ce66f8e20159d8bd39fff54ae01608da06c294John McCall void test() { 5141ce66f8e20159d8bd39fff54ae01608da06c294John McCall using ns::foo; //expected-note {{using declaration}} 527984de35644701c0d94336da7f2215d4c26d9f5bRichard Smith int foo(void); // expected-error {{declaration conflicts with target of using declaration already in scope}} 5341ce66f8e20159d8bd39fff54ae01608da06c294John McCall } 5441ce66f8e20159d8bd39fff54ae01608da06c294John McCall }; 5541ce66f8e20159d8bd39fff54ae01608da06c294John McCall} 5641ce66f8e20159d8bd39fff54ae01608da06c294John McCall 5741ce66f8e20159d8bd39fff54ae01608da06c294John McCallnamespace test4 { 5841ce66f8e20159d8bd39fff54ae01608da06c294John McCall namespace ns { void foo(); } // expected-note 2 {{target of using declaration}} 5941ce66f8e20159d8bd39fff54ae01608da06c294John McCall template <typename> class Test0 { 6041ce66f8e20159d8bd39fff54ae01608da06c294John McCall void test() { 617984de35644701c0d94336da7f2215d4c26d9f5bRichard Smith int foo(void); // expected-note {{conflicting declaration}} 6241ce66f8e20159d8bd39fff54ae01608da06c294John McCall using ns::foo; // expected-error {{target of using declaration conflicts with declaration already in scope}} 6341ce66f8e20159d8bd39fff54ae01608da06c294John McCall } 6441ce66f8e20159d8bd39fff54ae01608da06c294John McCall }; 6541ce66f8e20159d8bd39fff54ae01608da06c294John McCall 6641ce66f8e20159d8bd39fff54ae01608da06c294John McCall template <typename> class Test1 { 6741ce66f8e20159d8bd39fff54ae01608da06c294John McCall void test() { 6841ce66f8e20159d8bd39fff54ae01608da06c294John McCall using ns::foo; //expected-note {{using declaration}} 697984de35644701c0d94336da7f2215d4c26d9f5bRichard Smith int foo(void); // expected-error {{declaration conflicts with target of using declaration already in scope}} 7041ce66f8e20159d8bd39fff54ae01608da06c294John McCall } 7141ce66f8e20159d8bd39fff54ae01608da06c294John McCall }; 7241ce66f8e20159d8bd39fff54ae01608da06c294John McCall} 7341ce66f8e20159d8bd39fff54ae01608da06c294John McCall 7435dfab9cb14b7d368e4922dce786a5e046a61420John McCall// FIXME: we should be able to diagnose both of these, but we can't. 7541ce66f8e20159d8bd39fff54ae01608da06c294John McCallnamespace test5 { 761b7f9cbed1b96b58a6e5f7808ebc9345a76a0936Richard Smith namespace ns { void foo(int); } 7741ce66f8e20159d8bd39fff54ae01608da06c294John McCall template <typename T> class Test0 { 7841ce66f8e20159d8bd39fff54ae01608da06c294John McCall void test() { 7941ce66f8e20159d8bd39fff54ae01608da06c294John McCall int foo(T); 8041ce66f8e20159d8bd39fff54ae01608da06c294John McCall using ns::foo; 8141ce66f8e20159d8bd39fff54ae01608da06c294John McCall } 8241ce66f8e20159d8bd39fff54ae01608da06c294John McCall }; 8341ce66f8e20159d8bd39fff54ae01608da06c294John McCall 8441ce66f8e20159d8bd39fff54ae01608da06c294John McCall template <typename T> class Test1 { 8541ce66f8e20159d8bd39fff54ae01608da06c294John McCall void test() { 861b7f9cbed1b96b58a6e5f7808ebc9345a76a0936Richard Smith using ns::foo; 871b7f9cbed1b96b58a6e5f7808ebc9345a76a0936Richard Smith int foo(T); 8841ce66f8e20159d8bd39fff54ae01608da06c294John McCall } 8941ce66f8e20159d8bd39fff54ae01608da06c294John McCall }; 9035dfab9cb14b7d368e4922dce786a5e046a61420John McCall 9135dfab9cb14b7d368e4922dce786a5e046a61420John McCall template class Test0<int>; 921b7f9cbed1b96b58a6e5f7808ebc9345a76a0936Richard Smith template class Test1<int>; 9341ce66f8e20159d8bd39fff54ae01608da06c294John McCall} 94651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 95651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesnamespace test6 { 96651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines namespace ns { void foo(); } // expected-note {{target of using declaration}} 97651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines using ns::foo; // expected-note {{using declaration}} 98651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines namespace ns { 99651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines using test6::foo; 100651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void foo() {} 101651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines } 102651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void foo(); // expected-error {{declaration conflicts with target of using declaration already in scope}} 103651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines} 104651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 105651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesnamespace test7 { 106651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void foo(); 107651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines using test7::foo; 108651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void foo() {} 109651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines} 110