aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2013-01-31 03:11:12 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2013-01-31 03:11:12 +0000
commitf2705196d83a162665d4350bf3bb464972974ee3 (patch)
tree3f75012d8f6945e85b517adddd3ee53d7727f6b7
parent0e450cbd94e5936fdecf42b810069e7becd3938d (diff)
Clarify the diagnostic for -Wnested-anon-types.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174032 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/DiagnosticSemaKinds.td4
-rw-r--r--lib/Sema/SemaDecl.cpp3
-rw-r--r--test/SemaCXX/anonymous-union.cpp10
-rw-r--r--test/SemaCXX/constant-expression-cxx11.cpp4
4 files changed, 11 insertions, 10 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index e398da955b..aa6bcd6aa3 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5351,8 +5351,8 @@ def ext_anonymous_record_with_type : Extension<
"types declared in an anonymous %select{struct|union}0 are a Microsoft "
"extension">, InGroup<Microsoft>;
def ext_anonymous_record_with_anonymous_type : Extension<
- "nested anonymous types are an extension">,
- InGroup<DiagGroup<"nested-anon-types">>;
+ "anonymous types declared in an anonymous %select{struct|union}0 "
+ "are an extension">, InGroup<DiagGroup<"nested-anon-types">>;
def err_anonymous_record_with_function : Error<
"functions cannot be declared in an anonymous %select{struct|union}0">;
def err_anonymous_record_with_static : Error<
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 24dffc0299..80543fd532 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -3242,7 +3242,8 @@ Decl *Sema::BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
// This is a popular extension, provided by Plan9, MSVC and GCC, but
// not part of standard C++.
Diag(MemRecord->getLocation(),
- diag::ext_anonymous_record_with_anonymous_type);
+ diag::ext_anonymous_record_with_anonymous_type)
+ << (int)Record->isUnion();
}
} else if (isa<AccessSpecDecl>(*Mem)) {
// Any access specifier is fine.
diff --git a/test/SemaCXX/anonymous-union.cpp b/test/SemaCXX/anonymous-union.cpp
index e77f525147..93b5b0abba 100644
--- a/test/SemaCXX/anonymous-union.cpp
+++ b/test/SemaCXX/anonymous-union.cpp
@@ -9,7 +9,7 @@ struct X {
int i;
float f;
- union { // expected-warning{{nested anonymous types are an extension}}
+ union { // expected-warning{{anonymous types declared in an anonymous union are an extension}}
float f2;
mutable double d;
};
@@ -101,7 +101,7 @@ void g() {
struct BadMembers {
union {
struct X { }; // expected-error {{types cannot be declared in an anonymous union}}
- struct { int x; int y; } y; // expected-warning{{nested anonymous types are an extension}}
+ struct { int x; int y; } y; // expected-warning{{anonymous types declared in an anonymous union are an extension}}
void f(); // expected-error{{functions cannot be declared in an anonymous union}}
private: int x1; // expected-error{{anonymous union cannot contain a private data member}}
@@ -128,7 +128,7 @@ namespace test4 {
struct { // expected-warning{{anonymous structs are a GNU extension}}
int s0; // expected-note {{declared private here}}
double s1; // expected-note {{declared private here}}
- union { // expected-warning{{nested anonymous type}}
+ union { // expected-warning{{anonymous types declared in an anonymous struct are an extension}}
int su0; // expected-note {{declared private here}}
double su1; // expected-note {{declared private here}}
};
@@ -136,7 +136,7 @@ namespace test4 {
union {
int u0; // expected-note {{declared private here}}
double u1; // expected-note {{declared private here}}
- struct { // expected-warning{{anonymous structs are a GNU extension}} expected-warning{{nested anonymous type}}
+ struct { // expected-warning{{anonymous structs are a GNU extension}} expected-warning{{anonymous types declared in an anonymous union are an extension}}
int us0; // expected-note {{declared private here}}
double us1; // expected-note {{declared private here}}
};
@@ -187,7 +187,7 @@ namespace PR8326 {
private:
const union { // expected-warning{{anonymous union cannot be 'const'}}
- struct { // expected-warning{{anonymous structs are a GNU extension}} expected-warning{{nested anonymous type}}
+ struct { // expected-warning{{anonymous structs are a GNU extension}} expected-warning{{declared in an anonymous union}}
T x;
T y;
};
diff --git a/test/SemaCXX/constant-expression-cxx11.cpp b/test/SemaCXX/constant-expression-cxx11.cpp
index 8bb448cab0..30aa7d7b0b 100644
--- a/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/test/SemaCXX/constant-expression-cxx11.cpp
@@ -1153,8 +1153,8 @@ namespace ConvertedConstantExpr {
namespace IndirectField {
struct S {
struct { // expected-warning {{GNU extension}}
- union { // expected-warning {{nested anonymous types are an extension}}
- struct { // expected-warning {{GNU extension}} expected-warning {{nested anonymous types are an extension}}
+ union { // expected-warning {{declared in an anonymous struct}}
+ struct { // expected-warning {{GNU extension}} expected-warning {{declared in an anonymous union}}
int a;
int b;
};