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