18fbe78f6SDaniel Dunbar // RUN: %clang_cc1 -fsyntax-only -verify %s
2e7cbb3edSCharles Li // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
3e7cbb3edSCharles Li // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
46538c930SJohn McCall 
56538c930SJohn McCall namespace Ints {
66538c930SJohn McCall   int zero = 0; // expected-note {{candidate found by name lookup is 'Ints::zero'}}
76538c930SJohn McCall   void f(int); // expected-note 3 {{candidate function}}
86538c930SJohn McCall   void g(int);
96538c930SJohn McCall }
106538c930SJohn McCall 
116538c930SJohn McCall namespace Floats {
126538c930SJohn McCall   float zero = 0.0f; // expected-note {{candidate found by name lookup is 'Floats::zero'}}
136538c930SJohn McCall   void f(float); // expected-note 3 {{candidate function}}
146538c930SJohn McCall   void g(float);
156538c930SJohn McCall }
166538c930SJohn McCall 
176538c930SJohn McCall namespace Numbers {
186538c930SJohn McCall   using namespace Ints;
196538c930SJohn McCall   using namespace Floats;
206538c930SJohn McCall }
216538c930SJohn McCall 
test()226538c930SJohn McCall void test() {
236538c930SJohn McCall   int i = Ints::zero;
246538c930SJohn McCall   Ints::f(i);
256538c930SJohn McCall 
266538c930SJohn McCall   float f = Floats::zero;
276538c930SJohn McCall   Floats::f(f);
286538c930SJohn McCall 
296538c930SJohn McCall   double n = Numbers::zero; // expected-error {{reference to 'zero' is ambiguous}}
306538c930SJohn McCall   Numbers::f(n); // expected-error{{call to 'f' is ambiguous}}
316538c930SJohn McCall   Numbers::f(i);
326538c930SJohn McCall   Numbers::f(f);
336538c930SJohn McCall }
346538c930SJohn McCall 
356538c930SJohn McCall namespace Numbers {
36e7cbb3edSCharles Li   struct Number { // expected-note 2 {{candidate constructor (the implicit copy constructor) not viable}}
37e7cbb3edSCharles Li #if __cplusplus >= 201103L // C++11 or later
38e7cbb3edSCharles Li   // expected-note@-2 2 {{candidate constructor (the implicit move constructor) not viable}}
39e7cbb3edSCharles Li #endif
40e7cbb3edSCharles Li 
NumberNumbers::Number4125195541SRichard Smith     explicit Number(double d) : d(d) {} // expected-note 2{{explicit constructor is not a candidate}}
426538c930SJohn McCall     double d;
436538c930SJohn McCall   };
446538c930SJohn McCall   Number zero(0.0f);
454f4946aaSDouglas Gregor   void g(Number); // expected-note 2{{passing argument to parameter here}}
466538c930SJohn McCall }
476538c930SJohn McCall 
test2()486538c930SJohn McCall void test2() {
496538c930SJohn McCall   Numbers::Number n = Numbers::zero;
506538c930SJohn McCall   Numbers::f(n); // expected-error {{no matching function for call to 'f'}}
516538c930SJohn McCall   Numbers::g(n);
526538c930SJohn McCall }
536538c930SJohn McCall 
546538c930SJohn McCall namespace Numbers2 {
556538c930SJohn McCall   using Numbers::f;
566538c930SJohn McCall   using Numbers::g;
576538c930SJohn McCall }
586538c930SJohn McCall 
test3()596538c930SJohn McCall void test3() {
606538c930SJohn McCall   Numbers::Number n = Numbers::zero;
616538c930SJohn McCall   Numbers2::f(n); // expected-error {{no matching function for call to 'f'}}
626538c930SJohn McCall   Numbers2::g(n);
636538c930SJohn McCall 
646538c930SJohn McCall   int i = Ints::zero;
656538c930SJohn McCall   Numbers2::f(i);
66*888673b6SJonas Devlieghere   Numbers2::g(i); // expected-error {{no viable conversion from 'int' to 'Numbers::Number'}}
676538c930SJohn McCall 
686538c930SJohn McCall   float f = Floats::zero;
696538c930SJohn McCall   Numbers2::f(f);
70*888673b6SJonas Devlieghere   Numbers2::g(f); // expected-error {{no viable conversion from 'float' to 'Numbers::Number'}}
716538c930SJohn McCall }
72baf3ca5cSRichard Smith 
73baf3ca5cSRichard Smith namespace inline_ns {
74baf3ca5cSRichard Smith   int x; // expected-note 2{{found}}
75e7cbb3edSCharles Li   inline namespace A {
76e7cbb3edSCharles Li #if __cplusplus <= 199711L // C++03 or earlier
77e7cbb3edSCharles Li   // expected-warning@-2 {{inline namespaces are a C++11 feature}}
78e7cbb3edSCharles Li #endif
79e7cbb3edSCharles Li 
80baf3ca5cSRichard Smith     int x; // expected-note 2{{found}}
81baf3ca5cSRichard Smith     int y; // expected-note 2{{found}}
82baf3ca5cSRichard Smith   }
83baf3ca5cSRichard Smith   int y; // expected-note 2{{found}}
84baf3ca5cSRichard Smith   int k1 = x + y; // expected-error 2{{ambiguous}}
85baf3ca5cSRichard Smith   int k2 = inline_ns::x + inline_ns::y; // expected-error 2{{ambiguous}}
86baf3ca5cSRichard Smith }
87