Hi all,

The attached patch makes sure Clang doesn't warn about anonymous
struct/union with -pedantic in C11.

Please let me know if it is ok to land.

Thanks,
Hans
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 696e842..6404464 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -2679,9 +2679,9 @@ Decl *Sema::BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
   DeclContext *Owner = Record->getDeclContext();
 
   // Diagnose whether this anonymous struct/union is an extension.
-  if (Record->isUnion() && !getLangOptions().CPlusPlus)
+  if (Record->isUnion() && !getLangOptions().CPlusPlus && !getLangOptions().C11)
     Diag(Record->getLocation(), diag::ext_anonymous_union);
-  else if (!Record->isUnion())
+  else if (!Record->isUnion() && !getLangOptions().C11)
     Diag(Record->getLocation(), diag::ext_anonymous_struct);
 
   // C and C++ require different kinds of checks for anonymous
diff --git a/test/Sema/anonymous-struct-union-c11.c b/test/Sema/anonymous-struct-union-c11.c
new file mode 100644
index 0000000..7cad0ee
--- /dev/null
+++ b/test/Sema/anonymous-struct-union-c11.c
@@ -0,0 +1,19 @@
+// Check for warnings in non-C11 mode:
+// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
+
+// Expect no warnings in C11 mode:
+// RUN: %clang_cc1 -fsyntax-only -pedantic -Werror -std=c11 %s
+
+struct s {
+  int a;
+  struct { // expected-warning{{anonymous structs are a GNU extension}}
+    int b;
+  };
+};
+
+struct t {
+  int a;
+  union { // expected-warning{{anonymous unions are a GNU extension in C}}
+    int b;
+  };
+};
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to