forked from OSchip/llvm-project
Emit a warning when list-initializing a std::initializer_list member.
llvm-svn: 150933
This commit is contained in:
parent
8558da1930
commit
73cfbebed4
|
@ -1643,6 +1643,10 @@ Sema::ActOnCXXInClassMemberInitializer(Decl *D, SourceLocation EqualLoc,
|
|||
|
||||
ExprResult Init = InitExpr;
|
||||
if (!FD->getType()->isDependentType() && !InitExpr->isTypeDependent()) {
|
||||
if (isa<InitListExpr>(InitExpr) && isStdInitializerList(FD->getType(), 0)) {
|
||||
Diag(FD->getLocation(), diag::warn_dangling_std_initializer_list)
|
||||
<< /*at end of ctor*/1 << InitExpr->getSourceRange();
|
||||
}
|
||||
// FIXME: if there is no EqualLoc, this is list-initialization.
|
||||
Init = PerformCopyInitialization(
|
||||
InitializedEntity::InitializeMember(FD), EqualLoc, InitExpr);
|
||||
|
@ -2112,6 +2116,11 @@ Sema::BuildMemberInitializer(ValueDecl *Member, Expr *Init,
|
|||
InitList = true;
|
||||
Args = &Init;
|
||||
NumArgs = 1;
|
||||
|
||||
if (isStdInitializerList(Member->getType(), 0)) {
|
||||
Diag(IdLoc, diag::warn_dangling_std_initializer_list)
|
||||
<< /*at end of ctor*/1 << InitRange;
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize the member.
|
||||
|
|
|
@ -1087,7 +1087,7 @@ Sema::BuildCXXNew(SourceLocation StartLoc, bool UseGlobal,
|
|||
if (initStyle == CXXNewExpr::ListInit && isStdInitializerList(AllocType, 0)) {
|
||||
Diag(AllocTypeInfo->getTypeLoc().getBeginLoc(),
|
||||
diag::warn_dangling_std_initializer_list)
|
||||
<< /*at end of FE*/0 << Inits[0]->getSourceRange();
|
||||
<< /*at end of FE*/0 << Inits[0]->getSourceRange();
|
||||
}
|
||||
|
||||
// In ARC, infer 'retaining' for the allocated
|
||||
|
|
|
@ -127,3 +127,12 @@ void dangle() {
|
|||
new auto{1, 2, 3}; // expected-error {{cannot use list-initialization}}
|
||||
new std::initializer_list<int>{1, 2, 3}; // expected-warning {{at the end of the full-expression}}
|
||||
}
|
||||
|
||||
struct haslist1 {
|
||||
std::initializer_list<int> il = {1, 2, 3}; // expected-warning{{at the end of the constructor}}
|
||||
haslist1();
|
||||
};
|
||||
|
||||
haslist1::haslist1()
|
||||
: il{1, 2, 3} // expected-warning{{at the end of the constructor}}
|
||||
{}
|
||||
|
|
Loading…
Reference in New Issue