1 | // RUN: %clang_cc1 -std=c++98 -fsyntax-only -verify %s |
2 | // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s |
3 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
4 | |
5 | struct B { |
6 | void f(char); |
7 | void g(char); |
8 | enum E { e }; |
9 | union { int x; }; |
10 | |
11 | enum class EC { ec }; // expected-warning 0-1 {{C++11}} |
12 | |
13 | void f2(char); |
14 | void g2(char); |
15 | enum E2 { e2 }; |
16 | union { int x2; }; |
17 | }; |
18 | |
19 | class C { |
20 | int g(); |
21 | }; |
22 | |
23 | struct D : B {}; |
24 | |
25 | class D2 : public B { |
26 | using B::f; |
27 | using B::E; |
28 | using B::e; |
29 | using B::x; |
30 | using C::g; // expected-error{{using declaration refers into 'C::', which is not a base class of 'D2'}} |
31 | |
32 | // These are valid in C++98 but not in C++11. |
33 | using D::f2; |
34 | using D::E2; |
35 | using D::e2; |
36 | using D::x2; |
37 | #if __cplusplus >= 201103L |
38 | // expected-error@-5 {{using declaration refers into 'D::', which is not a base class of 'D2'}} |
39 | // expected-error@-5 {{using declaration refers into 'D::', which is not a base class of 'D2'}} |
40 | // expected-error@-5 {{using declaration refers into 'D::', which is not a base class of 'D2'}} |
41 | // expected-error@-5 {{using declaration refers into 'D::', which is not a base class of 'D2'}} |
42 | #endif |
43 | |
44 | using B::EC; |
45 | using B::EC::ec; // expected-error {{not a class}} expected-warning 0-1 {{C++11}} |
46 | }; |
47 | |
48 | namespace test1 { |
49 | struct Base { |
50 | int foo(); |
51 | }; |
52 | |
53 | struct Unrelated { |
54 | int foo(); |
55 | }; |
56 | |
57 | struct Subclass : Base { |
58 | }; |
59 | |
60 | namespace InnerNS { |
61 | int foo(); |
62 | } |
63 | |
64 | struct B : Base { |
65 | }; |
66 | |
67 | // We should be able to diagnose these without instantiation. |
68 | template <class T> struct C : Base { |
69 | using InnerNS::foo; // expected-error {{not a class}} |
70 | using Base::bar; // expected-error {{no member named 'bar'}} |
71 | using Unrelated::foo; // expected-error {{not a base class}} |
72 | |
73 | // In C++98, it's hard to see that these are invalid, because indirect |
74 | // references to base class members are permitted. |
75 | using C::foo; |
76 | using Subclass::foo; |
77 | #if __cplusplus >= 201103L |
78 | // expected-error@-3 {{refers to its own class}} |
79 | // expected-error@-3 {{not a base class}} |
80 | #endif |
81 | }; |
82 | } |
83 | |