"enum %0 was explicitly specialized here">;
def err_member_redeclared : Error<"class member cannot be redeclared">;
+def ext_member_redeclared : ExtWarn<"class member cannot be redeclared">,
+ InGroup<GNU>;
def err_member_redeclared_in_instantiation : Error<
"multiple overloads of %0 instantiate to the same signature %1">;
def err_member_name_of_class : Error<"member %0 has the same name as its class">;
return TUK == TUK_Declaration ? PrevTagDecl : 0;
}
+ // C++11 [class.mem]p1:
+ // A member shall not be declared twice in the member-speciļ¬cation,
+ // except that a nested class or member class template can be declared
+ // and then later defined.
+ if (TUK == TUK_Declaration && PrevDecl->isCXXClassMember() &&
+ S->isDeclScope(PrevDecl)) {
+ Diag(NameLoc, diag::ext_member_redeclared);
+ Diag(PrevTagDecl->getLocation(), diag::note_previous_declaration);
+ }
+
if (!Invalid) {
// If this is a use, just return the declaration we found.
B b = a; // expected-error {{no viable}}
}
-namespace dr85 { // dr85: no
+namespace dr85 { // dr85: yes
struct A {
struct B;
- struct B {};
- // FIXME: This redeclaration is invalid. Per [class.mem]p1,
- // "A member shall not be declared twice in the member-specification,
- // except that a nested class [...] can be declared then later defined"
- // This is not that case.
- struct B;
+ struct B {}; // expected-note{{previous declaration is here}}
+ struct B; // expected-error{{class member cannot be redeclared}}
+
+ union U;
+ union U {}; // expected-note{{previous declaration is here}}
+ union U; // expected-error{{class member cannot be redeclared}}
+
+#if __cplusplus >= 201103L
+ enum E1 : int;
+ enum E1 : int { e1 }; // expected-note{{previous declaration is here}}
+ enum E1 : int; // expected-error{{class member cannot be redeclared}}
+
+ enum class E2;
+ enum class E2 { e2 }; // expected-note{{previous declaration is here}}
+ enum class E2; // expected-error{{class member cannot be redeclared}}
+#endif
+ };
+
+ template <typename T>
+ struct C {
+ struct B {}; // expected-note{{previous declaration is here}}
+ struct B; // expected-error{{class member cannot be redeclared}}
};
}
namespace test1 {
class A {
private:
- class X; // expected-note {{previously declared 'private' here}}
+ class X; // expected-note {{previously declared 'private' here}} \
+ // expected-note {{previous declaration is here}}
public:
- class X; // expected-error {{'X' redeclared with 'public' access}}
+ class X; // expected-error {{'X' redeclared with 'public' access}} \
+ // expected-warning {{class member cannot be redeclared}}
class X {};
};
}
struct A : public B { // expected-note{{'rdar12629723::X::A' declared here}}
virtual void foo() { }
};
- struct B;
struct D : T::foo { };
struct E : D { };
typedef int X;
};
typename Foo::X x;
- class Foo;
};
template class B<int>;
template <typename T> class C {
class Foo;
- class Foo;
};
template <typename T> class C<T>::Foo {
int x;
<td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#85">85</a></td>
<td>TC1</td>
<td>Redeclaration of member class</td>
- <td class="none" align="center">No</td>
+ <td class="full" align="center">Yes</td>
</tr>
<tr>
<td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#86">86</a></td>