r327781 - Implement DR2229, which prohibits unnamed bit-fields from having qualifiers in C++.

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Sat Mar 17 14:08:40 PDT 2018


Author: aaronballman
Date: Sat Mar 17 14:08:40 2018
New Revision: 327781

URL: http://llvm.org/viewvc/llvm-project?rev=327781&view=rev
Log:
Implement DR2229, which prohibits unnamed bit-fields from having qualifiers in C++.

Added:
    cfe/trunk/test/CXX/drs/dr22xx.cpp
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/CXX/class/class.bit/p2.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=327781&r1=327780&r2=327781&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sat Mar 17 14:08:40 2018
@@ -1586,6 +1586,8 @@ def err_not_integral_type_bitfield : Err
   "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<

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=327781&r1=327780&r2=327781&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sat Mar 17 14:08:40 2018
@@ -14856,6 +14856,13 @@ FieldDecl *Sema::CheckFieldDecl(Declarat
     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()) {

Modified: cfe/trunk/test/CXX/class/class.bit/p2.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/class/class.bit/p2.cpp?rev=327781&r1=327780&r2=327781&view=diff
==============================================================================
--- cfe/trunk/test/CXX/class/class.bit/p2.cpp (original)
+++ cfe/trunk/test/CXX/class/class.bit/p2.cpp Sat Mar 17 14:08:40 2018
@@ -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;

Added: cfe/trunk/test/CXX/drs/dr22xx.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/drs/dr22xx.cpp?rev=327781&view=auto
==============================================================================
--- cfe/trunk/test/CXX/drs/dr22xx.cpp (added)
+++ cfe/trunk/test/CXX/drs/dr22xx.cpp Sat Mar 17 14:08:40 2018
@@ -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;
+};
+}




More information about the cfe-commits mailing list