forked from OSchip/llvm-project
Implement DR2229, which prohibits unnamed bit-fields from having qualifiers in C++.
llvm-svn: 327781
This commit is contained in:
parent
a8e2bb3949
commit
33e90d160b
|
@ -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<
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue