]> granicus.if.org Git - clang/commitdiff
Implement DR2229, which prohibits unnamed bit-fields from having qualifiers in C++.
authorAaron Ballman <aaron@aaronballman.com>
Sat, 17 Mar 2018 21:08:40 +0000 (21:08 +0000)
committerAaron Ballman <aaron@aaronballman.com>
Sat, 17 Mar 2018 21:08:40 +0000 (21:08 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@327781 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDecl.cpp
test/CXX/class/class.bit/p2.cpp
test/CXX/drs/dr22xx.cpp [new file with mode: 0644]

index e58d1c74653141d855b00cf9af09a3f0bbfd2192..99c340775fec537c80d7a6c024272484f9b89ef2 100644 (file)
@@ -1586,6 +1586,8 @@ def err_not_integral_type_bitfield : Error<
   "bit-field %0 has non-integral type %1">;
 def err_not_integral_type_anon_bitfield : Error<
   "anonymous bit-field has non-integral type %0">;
+def err_anon_bitfield_qualifiers : Error<
+  "anonymous bit-field cannot have qualifiers">;
 def err_member_function_initialization : Error<
   "initializer on function does not look like a pure-specifier">;
 def err_non_virtual_pure : Error<
index 612761177cd508d54a689a7abf04e8403923b3e2..ea97135303940b08509b65963a496ffc1a176f86 100644 (file)
@@ -14856,6 +14856,13 @@ FieldDecl *Sema::CheckFieldDecl(DeclarationName Name, QualType T,
     InvalidDecl = true;
   }
 
+  // Anonymous bit-fields cannot be cv-qualified (CWG 2229).
+  if (!InvalidDecl && getLangOpts().CPlusPlus && !II && BitWidth &&
+      T.hasQualifiers()) {
+    InvalidDecl = true;
+    Diag(Loc, diag::err_anon_bitfield_qualifiers);
+  }
+
   // C99 6.7.2.1p8: A member of a structure or union may have any type other
   // than a variably modified type.
   if (!InvalidDecl && T->isVariablyModifiedType()) {
index 7962330d1612a326e0881b9e77158b715992adfe..8b2436a869ba0299953dcac78bbc25dc347390d6 100644 (file)
@@ -9,7 +9,7 @@ A a = { };
 A a2 = { 1 }; // expected-error{{excess elements in struct initializer}}
 
 struct B {
-  const int : 0;
+  const int : 0; // expected-error{{anonymous bit-field cannot have qualifiers}}
 };
 
 B b;
diff --git a/test/CXX/drs/dr22xx.cpp b/test/CXX/drs/dr22xx.cpp
new file mode 100644 (file)
index 0000000..55b3d78
--- /dev/null
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++1z -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
+
+namespace dr2229 { // dr2229: yes
+struct AnonBitfieldQualifiers {
+  const unsigned : 1; // expected-error {{anonymous bit-field cannot have qualifiers}}
+  volatile unsigned : 1; // expected-error {{anonymous bit-field cannot have qualifiers}}
+  const volatile unsigned : 1; // expected-error {{anonymous bit-field cannot have qualifiers}}
+
+  unsigned : 1;
+  const unsigned i1 : 1;
+  volatile unsigned i2 : 1;
+  const volatile unsigned i3 : 1;
+};
+}