Debian Codegraph @

clang/test/SemaCXX/unqualified-std-call.cpp

raw
1 // RUN: %clang_cc1 -fsyntax-only -verify -Wall -std=c++11 %s -Wno-unused-value
2
3 namespace std {
4
5 template <typename T>
6 void dummy(T &&) {}
7 template <typename T>
8 T &&move(T &&x) { return x; }
9 template <typename T, typename U>
10 void move(T &&, U &&) {}
11
12 inline namespace __1 {
13 template <typename T>
14 T &forward(T &x) { return x; }
15 } // namespace __1
16
17 struct foo {};
18
19 } // namespace std
20
21 namespace global {
22
23 using namespace std;
24
25 void f() {
26 int i = 0;
27 std::move(i);
28 move(i); // expected-warning{{unqualified call to 'std::move'}}
29 (move)(i); // expected-warning{{unqualified call to 'std::move'}}
30 std::dummy(1);
31 dummy(1);
32 std::move(1, 2);
33 move(1, 2);
34 forward<int>(i); // expected-warning{{unqualified call to 'std::forward'}}
35 std::forward<int>(i);
36 }
37
38 template <typename T>
39 void g(T &&foo) {
40 std::move(foo);
41 move(foo); // expected-warning{{unqualified call to 'std::move}}
42
43 std::forward<decltype(foo)>(foo);
44 forward<decltype(foo)>(foo); // expected-warning{{unqualified call to 'std::forward}}
45 move(1, 2);
46 dummy(foo);
47 }
48
49 void call() {
50 g(0); //expected-note {{here}}
51 }
52
53 } // namespace global
54
55 namespace named {
56
57 using std::forward;
58 using std::move;
59
60 void f() {
61 int i = 0;
62 move(i); // expected-warning{{unqualified call to 'std::move}}
63 move(1, 2);
64 forward<int>(i); // expected-warning{{unqualified call to 'std::forward}}
65 }
66
67 template <typename T>
68 void g(T &&foo) {
69 move(foo); // expected-warning{{unqualified call to 'std::move}}
70 forward<decltype(foo)>(foo); // expected-warning{{unqualified call to 'std::forward}}
71 (forward<decltype(foo)>)(foo); // expected-warning{{unqualified call to 'std::forward}}
72 move(1, 2);
73 }
74
75 void call() {
76 g(0); //expected-note {{here}}
77 }
78
79 } // namespace named
80
81 namespace overload {
82 using namespace std;
83 template <typename T>
84 int move(T &&);
85 void f() {
86 int i = 0;
87 move(i);
88 }
89 } // namespace overload
90
91 namespace adl {
92 void f() {
93 move(std::foo{}); // expected-warning{{unqualified call to 'std::move}}
94 }
95
96 } // namespace adl
97
98 namespace std {
99
100 void f() {
101 int i = 0;
102 move(i); // expected-warning{{unqualified call to 'std::move}}
103 forward<int>(i); // expected-warning{{unqualified call to 'std::forward}}
104 }
105
106 } // namespace std
107
108 namespace test_alias {
109 namespace alias = std;
110 using namespace alias;
111 void f() {
112 int i = 0;
113 move(i); // expected-warning{{unqualified call to 'std::move}}
114 move(1, 2);
115 forward<int>(i); // expected-warning{{unqualified call to 'std::forward}}
116 }
117
118 } // namespace test_alias