1 // RUN: %clang_cc1 -fsyntax-only -std=c++98 -verify %s
2 // RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
3 // RUN: not %clang_cc1 -fsyntax-only -std=c++98 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck --check-prefix=CXX98 %s
4 // RUN: not %clang_cc1 -fsyntax-only -std=c++11 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck --check-prefix=CXX11 %s
5 // C++0x N2914.
6
7 struct X {
8 int i;
9 static int a;
10 enum E { e };
11 };
12
13 using X::i; // expected-error{{using declaration cannot refer to class member}}
14 using X::s; // expected-error{{using declaration cannot refer to class member}}
15 using X::e; // expected-error{{using declaration cannot refer to class member}}
16 using X::E::e; // expected-error{{using declaration cannot refer to class member}} expected-warning 0-1{{C++11}}
17 #if __cplusplus < 201103L
18 // expected-note@-3 {{use a const variable}}
19 // expected-note@-3 {{use a const variable}}
20 // CXX98-NOT: fix-it:"{{.*}}":{[[@LINE-5]]:
21 // CXX98-NOT: fix-it:"{{.*}}":{[[@LINE-5]]:
22 #else
23 // expected-note@-8 {{use a constexpr variable}}
24 // expected-note@-8 {{use a constexpr variable}}
25 // CXX11: fix-it:"{{.*}}":{[[@LINE-10]]:1-[[@LINE-10]]:6}:"constexpr auto e = "
26 // CXX11: fix-it:"{{.*}}":{[[@LINE-10]]:1-[[@LINE-10]]:6}:"constexpr auto e = "
27 #endif
28
f()29 void f() {
30 using X::i; // expected-error{{using declaration cannot refer to class member}}
31 using X::s; // expected-error{{using declaration cannot refer to class member}}
32 using X::e; // expected-error{{using declaration cannot refer to class member}}
33 using X::E::e; // expected-error{{using declaration cannot refer to class member}} expected-warning 0-1{{C++11}}
34 #if __cplusplus < 201103L
35 // expected-note@-3 {{use a const variable}}
36 // expected-note@-3 {{use a const variable}}
37 // CXX98-NOT: fix-it:"{{.*}}":{[[@LINE-5]]:
38 // CXX98-NOT: fix-it:"{{.*}}":{[[@LINE-5]]:
39 #else
40 // expected-note@-8 {{use a constexpr variable}}
41 // expected-note@-8 {{use a constexpr variable}}
42 // CXX11: fix-it:"{{.*}}":{[[@LINE-10]]:3-[[@LINE-10]]:8}:"constexpr auto e = "
43 // CXX11: fix-it:"{{.*}}":{[[@LINE-10]]:3-[[@LINE-10]]:8}:"constexpr auto e = "
44 #endif
45 }
46
47 template <typename T>
48 struct PR21933 : T {
StaticFunPR2193349 static void StaticFun() { using T::member; } // expected-error{{using declaration cannot refer to class member}}
50 };
51
52 struct S {
53 static int n;
54 struct Q {};
55 enum E {};
56 typedef Q T;
57 void f();
58 static void g();
59 };
60
61 using S::n; // expected-error{{class member}} expected-note {{use a reference instead}}
62 #if __cplusplus < 201103L
63 // CXX98-NOT: fix-it:"{{.*}}":{[[@LINE-2]]
64 #else
65 // CXX11: fix-it:"{{.*}}":{[[@LINE-4]]:1-[[@LINE-4]]:6}:"auto &n = "
66 #endif
67
68 using S::Q; // expected-error{{class member}}
69 #if __cplusplus < 201103L
70 // expected-note@-2 {{use a typedef declaration instead}}
71 // CXX98: fix-it:"{{.*}}":{[[@LINE-3]]:1-[[@LINE-3]]:6}:"typedef"
72 // CXX98: fix-it:"{{.*}}":{[[@LINE-4]]:11-[[@LINE-4]]:11}:" Q"
73 #else
74 // expected-note@-6 {{use an alias declaration instead}}
75 // CXX11: fix-it:"{{.*}}":{[[@LINE-7]]:7-[[@LINE-7]]:7}:"Q = "
76 #endif
77
78 using S::E; // expected-error{{class member}}
79 #if __cplusplus < 201103L
80 // expected-note@-2 {{use a typedef declaration instead}}
81 // CXX98: fix-it:"{{.*}}":{[[@LINE-3]]:1-[[@LINE-3]]:6}:"typedef"
82 // CXX98: fix-it:"{{.*}}":{[[@LINE-4]]:11-[[@LINE-4]]:11}:" E"
83 #else
84 // expected-note@-6 {{use an alias declaration instead}}
85 // CXX11: fix-it:"{{.*}}":{[[@LINE-7]]:7-[[@LINE-7]]:7}:"E = "
86 #endif
87
88 using S::T; // expected-error{{class member}}
89 #if __cplusplus < 201103L
90 // expected-note@-2 {{use a typedef declaration instead}}
91 // CXX98: fix-it:"{{.*}}":{[[@LINE-3]]:1-[[@LINE-3]]:6}:"typedef"
92 // CXX98: fix-it:"{{.*}}":{[[@LINE-4]]:11-[[@LINE-4]]:11}:" T"
93 #else
94 // expected-note@-6 {{use an alias declaration instead}}
95 // CXX11: fix-it:"{{.*}}":{[[@LINE-7]]:7-[[@LINE-7]]:7}:"T = "
96 #endif
97
98 using S::f; // expected-error{{class member}}
99 using S::g; // expected-error{{class member}}
100
h()101 void h() {
102 using S::n; // expected-error{{class member}} expected-note {{use a reference instead}}
103 #if __cplusplus < 201103L
104 // CXX98-NOT: fix-it:"{{.*}}":{[[@LINE-2]]
105 #else
106 // CXX11: fix-it:"{{.*}}":{[[@LINE-4]]:3-[[@LINE-4]]:8}:"auto &n = "
107 #endif
108
109 using S::Q; // expected-error{{class member}}
110 #if __cplusplus < 201103L
111 // expected-note@-2 {{use a typedef declaration instead}}
112 // CXX98: fix-it:"{{.*}}":{[[@LINE-3]]:3-[[@LINE-3]]:8}:"typedef"
113 // CXX98: fix-it:"{{.*}}":{[[@LINE-4]]:13-[[@LINE-4]]:13}:" Q"
114 #else
115 // expected-note@-6 {{use an alias declaration instead}}
116 // CXX11: fix-it:"{{.*}}":{[[@LINE-7]]:9-[[@LINE-7]]:9}:"Q = "
117 #endif
118
119 using S::E; // expected-error{{class member}}
120 #if __cplusplus < 201103L
121 // expected-note@-2 {{use a typedef declaration instead}}
122 // CXX98: fix-it:"{{.*}}":{[[@LINE-3]]:3-[[@LINE-3]]:8}:"typedef"
123 // CXX98: fix-it:"{{.*}}":{[[@LINE-4]]:13-[[@LINE-4]]:13}:" E"
124 #else
125 // expected-note@-6 {{use an alias declaration instead}}
126 // CXX11: fix-it:"{{.*}}":{[[@LINE-7]]:9-[[@LINE-7]]:9}:"E = "
127 #endif
128
129 using S::T; // expected-error{{class member}}
130 #if __cplusplus < 201103L
131 // expected-note@-2 {{use a typedef declaration instead}}
132 // CXX98: fix-it:"{{.*}}":{[[@LINE-3]]:3-[[@LINE-3]]:8}:"typedef"
133 // CXX98: fix-it:"{{.*}}":{[[@LINE-4]]:13-[[@LINE-4]]:13}:" T"
134 #else
135 // expected-note@-6 {{use an alias declaration instead}}
136 // CXX11: fix-it:"{{.*}}":{[[@LINE-7]]:9-[[@LINE-7]]:9}:"T = "
137 #endif
138
139 using S::f; // expected-error{{class member}}
140 using S::g; // expected-error{{class member}}
141 }
142