1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
2 | // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s |
3 | // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s |
4 | |
5 | namespace Ints { |
6 | int zero = 0; // expected-note {{candidate found by name lookup is 'Ints::zero'}} |
7 | void f(int); // expected-note 3 {{candidate function}} |
8 | void g(int); |
9 | } |
10 | |
11 | namespace Floats { |
12 | float zero = 0.0f; // expected-note {{candidate found by name lookup is 'Floats::zero'}} |
13 | void f(float); // expected-note 3 {{candidate function}} |
14 | void g(float); |
15 | } |
16 | |
17 | namespace Numbers { |
18 | using namespace Ints; |
19 | using namespace Floats; |
20 | } |
21 | |
22 | void test() { |
23 | int i = Ints::zero; |
24 | Ints::f(i); |
25 | |
26 | float f = Floats::zero; |
27 | Floats::f(f); |
28 | |
29 | double n = Numbers::zero; // expected-error {{reference to 'zero' is ambiguous}} |
30 | Numbers::f(n); // expected-error{{call to 'f' is ambiguous}} |
31 | Numbers::f(i); |
32 | Numbers::f(f); |
33 | } |
34 | |
35 | namespace Numbers { |
36 | struct Number { // expected-note 2 {{candidate constructor (the implicit copy constructor) not viable}} |
37 | #if __cplusplus >= 201103L // C++11 or later |
38 | // expected-note@-2 2 {{candidate constructor (the implicit move constructor) not viable}} |
39 | #endif |
40 | |
41 | explicit Number(double d) : d(d) {} |
42 | double d; |
43 | }; |
44 | Number zero(0.0f); |
45 | void g(Number); // expected-note 2{{passing argument to parameter here}} |
46 | } |
47 | |
48 | void test2() { |
49 | Numbers::Number n = Numbers::zero; |
50 | Numbers::f(n); // expected-error {{no matching function for call to 'f'}} |
51 | Numbers::g(n); |
52 | } |
53 | |
54 | namespace Numbers2 { |
55 | using Numbers::f; |
56 | using Numbers::g; |
57 | } |
58 | |
59 | void test3() { |
60 | Numbers::Number n = Numbers::zero; |
61 | Numbers2::f(n); // expected-error {{no matching function for call to 'f'}} |
62 | Numbers2::g(n); |
63 | |
64 | int i = Ints::zero; |
65 | Numbers2::f(i); |
66 | Numbers2::g(i); // expected-error {{no viable conversion from 'int' to 'Numbers::Number'}} |
67 | |
68 | float f = Floats::zero; |
69 | Numbers2::f(f); |
70 | Numbers2::g(f); // expected-error {{no viable conversion from 'float' to 'Numbers::Number'}} |
71 | } |
72 | |
73 | namespace inline_ns { |
74 | int x; // expected-note 2{{found}} |
75 | inline namespace A { |
76 | #if __cplusplus <= 199711L // C++03 or earlier |
77 | // expected-warning@-2 {{inline namespaces are a C++11 feature}} |
78 | #endif |
79 | |
80 | int x; // expected-note 2{{found}} |
81 | int y; // expected-note 2{{found}} |
82 | } |
83 | int y; // expected-note 2{{found}} |
84 | int k1 = x + y; // expected-error 2{{ambiguous}} |
85 | int k2 = inline_ns::x + inline_ns::y; // expected-error 2{{ambiguous}} |
86 | } |
87 | |