PR19415: Converting 'constexpr' to 'const' in a non-static data member can fail

if the member is already 'const'. Don't assert in that case.

llvm-svn: 206205
This commit is contained in:
Richard Smith 2014-04-14 21:00:40 +00:00
parent ac9c9a006f
commit 82dce550c8
2 changed files with 15 additions and 9 deletions

View File

@ -1960,14 +1960,19 @@ Sema::ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, Declarator &D,
Diag(DS.getConstexprSpecLoc(), diag::err_invalid_constexpr_member);
SourceLocation ConstexprLoc = DS.getConstexprSpecLoc();
if (InitStyle == ICIS_NoInit) {
B << 0 << 0 << FixItHint::CreateReplacement(ConstexprLoc, "const");
D.getMutableDeclSpec().ClearConstexprSpec();
const char *PrevSpec;
unsigned DiagID;
bool Failed = D.getMutableDeclSpec().SetTypeQual(DeclSpec::TQ_const, ConstexprLoc,
PrevSpec, DiagID, getLangOpts());
(void)Failed;
assert(!Failed && "Making a constexpr member const shouldn't fail");
B << 0 << 0;
if (D.getDeclSpec().getTypeQualifiers() & DeclSpec::TQ_const)
B << FixItHint::CreateRemoval(ConstexprLoc);
else {
B << FixItHint::CreateReplacement(ConstexprLoc, "const");
D.getMutableDeclSpec().ClearConstexprSpec();
const char *PrevSpec;
unsigned DiagID;
bool Failed = D.getMutableDeclSpec().SetTypeQual(
DeclSpec::TQ_const, ConstexprLoc, PrevSpec, DiagID, getLangOpts());
(void)Failed;
assert(!Failed && "Making a constexpr member const shouldn't fail");
}
} else {
B << 1;
const char *PrevSpec;

View File

@ -125,7 +125,8 @@ namespace NonStaticConstexpr {
struct foo {
constexpr int i; // expected-error {{non-static data member cannot be constexpr; did you intend to make it const?}}
constexpr int j = 7; // expected-error {{non-static data member cannot be constexpr; did you intend to make it static?}}
foo() : i(3) {
constexpr const int k; // expected-error {{non-static data member cannot be constexpr; did you intend to make it const?}}
foo() : i(3), k(4) {
}
static int get_j() {
return j;