| 1 |
// Check that the compiler warns about inner-style forward declarations in |
| 2 |
// contexts where they're not actually illegal, but merely useless. |
| 3 |
|
| 4 |
// Verify warnings for and within classes, and by extension, struct and union. |
| 5 |
class C1; |
| 6 |
class C1::C2; // { dg-error "incomplete" } |
| 7 |
class C1::C2::C3; // { dg-error "has not been declared" } |
| 8 |
|
| 9 |
class C1 { |
| 10 |
public: |
| 11 |
class C2; |
| 12 |
class C2::C3; // { dg-error "incomplete" } |
| 13 |
class C2 { |
| 14 |
public: |
| 15 |
class C3; |
| 16 |
class C3 { }; |
| 17 |
class C3; |
| 18 |
}; |
| 19 |
class C2; |
| 20 |
class C2::C3; // { dg-warning "declaration 'class C1::C2::C3' does not declare anything" } |
| 21 |
}; |
| 22 |
|
| 23 |
class C1; |
| 24 |
class C1::C2; // { dg-warning "declaration 'class C1::C2' does not declare anything" } |
| 25 |
class C1::C2::C3; // { dg-warning "declaration 'class C1::C2::C3' does not declare anything" } |
| 26 |
|
| 27 |
|
| 28 |
// Verify warnings for namespace scopes. |
| 29 |
class N1::C4; // { dg-error "has not been declared" } |
| 30 |
class N1::N2::C5; // { dg-error "has not been declared" } |
| 31 |
|
| 32 |
namespace N1 { |
| 33 |
class C4; |
| 34 |
class C4 { }; |
| 35 |
class C4; |
| 36 |
|
| 37 |
class N2::C5; // { dg-error "has not been declared" } |
| 38 |
namespace N2 { |
| 39 |
class C5; |
| 40 |
class C5 { }; |
| 41 |
class C5; |
| 42 |
} |
| 43 |
class N2::C5; // { dg-warning "declaration 'class N1::N2::C5' does not declare anything" } |
| 44 |
} |
| 45 |
|
| 46 |
class N1::C4; // { dg-warning "declaration 'class N1::C4' does not declare anything" } |
| 47 |
class N1::N2::C5; // { dg-warning "declaration 'class N1::N2::C5' does not declare anything" } |
| 48 |
|
| 49 |
|
| 50 |
// Verify that using declarations related to namespaces don't generate a |
| 51 |
// warning. |
| 52 |
using namespace N1; |
| 53 |
using namespace N1::N2; |
| 54 |
|
| 55 |
namespace N3 { |
| 56 |
using N1::C4; // Valid using declaration, no warning |
| 57 |
using N1::N2::C5; // Valid using declaration, no warning |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
// Verify that explicit template instantiations, easy to confuse with |
| 62 |
// forward declarations, don't generate a warning. |
| 63 |
template<class C> |
| 64 |
class TC6 { |
| 65 |
public: |
| 66 |
class TC7 { }; |
| 67 |
}; |
| 68 |
|
| 69 |
template class TC6<int>::TC7; // Valid explicit instantiation, no warning |
| 70 |
|
| 71 |
|
| 72 |
// Verify that friend declarations, also easy to confuse with forward |
| 73 |
// declarations, are similarly not warned about. |
| 74 |
class C8 { |
| 75 |
public: |
| 76 |
class C9 { }; |
| 77 |
}; |
| 78 |
class C10 { |
| 79 |
public: |
| 80 |
friend class C8::C9; // Valid friend declaration, no warning |
| 81 |
}; |
| 82 |
|
| 83 |
#if __cplusplus >= 201103L |
| 84 |
// Verify that alias-declarations using an elaborated-type-specifier and |
| 85 |
// nested-name-specifier are not warned about (PR c++/66159). |
| 86 |
struct C11; |
| 87 |
using A1 = struct ::C11; // Valid alias-decl, no warning |
| 88 |
#endif |