"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<
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()) {
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;
--- /dev/null
+// 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;
+};
+}