forked from OSchip/llvm-project
Add some missing diagnostics for C++11 narrowing conversions.
llvm-svn: 174337
This commit is contained in:
parent
86b1d868ba
commit
6b21696ee8
|
@ -3697,7 +3697,8 @@ public:
|
|||
MultiExprArg ArgsPtr,
|
||||
SourceLocation Loc,
|
||||
SmallVectorImpl<Expr*> &ConvertedArgs,
|
||||
bool AllowExplicit = false);
|
||||
bool AllowExplicit = false,
|
||||
bool IsListInitialization = false);
|
||||
|
||||
ParsedType getDestructorName(SourceLocation TildeLoc,
|
||||
IdentifierInfo &II, SourceLocation NameLoc,
|
||||
|
@ -6623,7 +6624,8 @@ public:
|
|||
Expr **Args, unsigned NumArgs,
|
||||
SmallVector<Expr *, 8> &AllArgs,
|
||||
VariadicCallType CallType = VariadicDoesNotApply,
|
||||
bool AllowExplicit = false);
|
||||
bool AllowExplicit = false,
|
||||
bool IsListInitialization = false);
|
||||
|
||||
// DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but
|
||||
// will create a runtime trap if the resulting type is not a POD type.
|
||||
|
|
|
@ -9594,7 +9594,8 @@ Sema::CompleteConstructorCall(CXXConstructorDecl *Constructor,
|
|||
MultiExprArg ArgsPtr,
|
||||
SourceLocation Loc,
|
||||
SmallVectorImpl<Expr*> &ConvertedArgs,
|
||||
bool AllowExplicit) {
|
||||
bool AllowExplicit,
|
||||
bool IsListInitialization) {
|
||||
// FIXME: This duplicates a lot of code from Sema::ConvertArgumentsForCall.
|
||||
unsigned NumArgs = ArgsPtr.size();
|
||||
Expr **Args = ArgsPtr.data();
|
||||
|
@ -9615,7 +9616,8 @@ Sema::CompleteConstructorCall(CXXConstructorDecl *Constructor,
|
|||
SmallVector<Expr *, 8> AllArgs;
|
||||
bool Invalid = GatherArgumentsForCall(Loc, Constructor,
|
||||
Proto, 0, Args, NumArgs, AllArgs,
|
||||
CallType, AllowExplicit);
|
||||
CallType, AllowExplicit,
|
||||
IsListInitialization);
|
||||
ConvertedArgs.append(AllArgs.begin(), AllArgs.end());
|
||||
|
||||
DiagnoseSentinelCalls(Constructor, Loc, AllArgs.data(), AllArgs.size());
|
||||
|
|
|
@ -3720,7 +3720,8 @@ bool Sema::GatherArgumentsForCall(SourceLocation CallLoc,
|
|||
Expr **Args, unsigned NumArgs,
|
||||
SmallVector<Expr *, 8> &AllArgs,
|
||||
VariadicCallType CallType,
|
||||
bool AllowExplicit) {
|
||||
bool AllowExplicit,
|
||||
bool IsListInitialization) {
|
||||
unsigned NumArgsInProto = Proto->getNumArgs();
|
||||
unsigned NumArgsToCheck = NumArgs;
|
||||
bool Invalid = false;
|
||||
|
@ -3760,7 +3761,7 @@ bool Sema::GatherArgumentsForCall(SourceLocation CallLoc,
|
|||
ExprResult ArgE = PerformCopyInitialization(Entity,
|
||||
SourceLocation(),
|
||||
Owned(Arg),
|
||||
/*TopLevelOfInitList=*/false,
|
||||
IsListInitialization,
|
||||
AllowExplicit);
|
||||
if (ArgE.isInvalid())
|
||||
return true;
|
||||
|
|
|
@ -4729,7 +4729,8 @@ PerformConstructorInitialization(Sema &S,
|
|||
// call.
|
||||
if (S.CompleteConstructorCall(Constructor, Args,
|
||||
Loc, ConstructorArgs,
|
||||
AllowExplicitConv))
|
||||
AllowExplicitConv,
|
||||
IsListInitialization))
|
||||
return ExprError();
|
||||
|
||||
|
||||
|
@ -5474,9 +5475,9 @@ InitializationSequence::Perform(Sema &S,
|
|||
for (unsigned i = 0; i < NumInits; ++i) {
|
||||
Element.setElementIndex(i);
|
||||
ExprResult Init = S.Owned(ILE->getInit(i));
|
||||
ExprResult Res = S.PerformCopyInitialization(Element,
|
||||
Init.get()->getExprLoc(),
|
||||
Init);
|
||||
ExprResult Res = S.PerformCopyInitialization(
|
||||
Element, Init.get()->getExprLoc(), Init,
|
||||
/*TopLevelOfInitList=*/ true);
|
||||
assert(!Res.isInvalid() && "Result changed since try phase.");
|
||||
Converted[i] = Res.take();
|
||||
}
|
||||
|
@ -6189,7 +6190,11 @@ void InitializationSequence::dump(raw_ostream &OS) const {
|
|||
OS << "OpenCL event_t from zero";
|
||||
break;
|
||||
}
|
||||
|
||||
OS << " [" << S->Type.getAsString() << ']';
|
||||
}
|
||||
|
||||
OS << '\n';
|
||||
}
|
||||
|
||||
void InitializationSequence::dump() const {
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace std {
|
|||
};
|
||||
}
|
||||
|
||||
namespace bullet2 {
|
||||
namespace bullet1 {
|
||||
double ad[] = { 1, 2.0 };
|
||||
int ai[] = { 1, 2.0 }; // expected-error {{type 'double' cannot be narrowed to 'int' in initializer list}} expected-note {{override}}
|
||||
|
||||
|
@ -62,12 +62,16 @@ namespace bullet4_example3 {
|
|||
};
|
||||
|
||||
S s1 = { 1, 2, 3.0 };
|
||||
// FIXME: This is an ill-formed narrowing initialization.
|
||||
S s2 { 1.0, 2, 3 };
|
||||
S s2 { 1.0, 2, 3 }; // expected-error {{type 'double' cannot be narrowed to 'int' in initializer list}} expected-note {{override}}
|
||||
S s3 {};
|
||||
}
|
||||
|
||||
namespace bullet5 {
|
||||
int x1 {2};
|
||||
int x2 {2.0}; // expected-error {{type 'double' cannot be narrowed to 'int' in initializer list}} expected-note {{override}}
|
||||
}
|
||||
|
||||
namespace bullet6 {
|
||||
struct S {
|
||||
S(std::initializer_list<double>) {}
|
||||
S(const std::string &) {}
|
||||
|
@ -75,17 +79,12 @@ namespace bullet5 {
|
|||
|
||||
const S& r1 = { 1, 2, 3.0 };
|
||||
const S& r2 = { "Spinach" };
|
||||
S& r3 = { 1, 2, 3 }; // expected-error {{non-const lvalue reference to type 'bullet5::S' cannot bind to an initializer list temporary}}
|
||||
S& r3 = { 1, 2, 3 }; // expected-error {{non-const lvalue reference to type 'bullet6::S' cannot bind to an initializer list temporary}}
|
||||
const int& i1 = { 1 };
|
||||
const int& i2 = { 1.1 }; // expected-error {{type 'double' cannot be narrowed to 'int' in initializer list}} expected-note {{override}} expected-warning {{implicit conversion}}
|
||||
const int (&iar)[2] = { 1, 2 };
|
||||
}
|
||||
|
||||
namespace bullet6 {
|
||||
int x1 {2};
|
||||
int x2 {2.0}; // expected-error {{type 'double' cannot be narrowed to 'int' in initializer list}} expected-note {{override}}
|
||||
}
|
||||
|
||||
namespace bullet7 {
|
||||
int** pp {};
|
||||
}
|
||||
|
@ -99,14 +98,14 @@ namespace bullet8 {
|
|||
B(std::initializer_list<int> i) {}
|
||||
};
|
||||
B b1 { 1, 2 };
|
||||
B b2 { 1, 2.0 };
|
||||
B b2 { 1, 2.0 }; // expected-error {{type 'double' cannot be narrowed to 'int' in initializer list}} expected-note {{override}}
|
||||
|
||||
struct C {
|
||||
C(int i, double j) {}
|
||||
};
|
||||
C c1 = { 1, 2.2 };
|
||||
// FIXME: This is an ill-formed narrowing initialization.
|
||||
C c2 = { 1.1, 2 }; // expected-warning {{implicit conversion}}
|
||||
// FIXME: Suppress the narrowing warning in the cases where we issue a narrowing error.
|
||||
C c2 = { 1.1, 2 }; // expected-error {{type 'double' cannot be narrowed to 'int' in initializer list}} expected-note {{override}} expected-warning {{implicit conversion}}
|
||||
|
||||
int j { 1 };
|
||||
int k { };
|
||||
|
|
|
@ -75,9 +75,8 @@ namespace objects {
|
|||
{ F<0> f = {}; }
|
||||
// Narrowing conversions don't affect viability. The next two choose
|
||||
// the initializer_list constructor.
|
||||
// FIXME: Emit narrowing conversion errors.
|
||||
{ F<3> f{1, 1.0}; } // xpected-error {{narrowing conversion}}
|
||||
{ F<3> f = {1, 1.0}; } // xpected-error {{narrowing conversion}}
|
||||
{ F<3> f{1, 1.0}; } // expected-error {{type 'double' cannot be narrowed to 'int' in initializer list}} expected-note {{override}}
|
||||
{ F<3> f = {1, 1.0}; } // expected-error {{type 'double' cannot be narrowed to 'int' in initializer list}} expected-note {{override}}
|
||||
{ F<3> f{1, 2, 3, 4, 5, 6, 7, 8}; }
|
||||
{ F<3> f = {1, 2, 3, 4, 5, 6, 7, 8}; }
|
||||
{ F<3> f{1, 2, 3, 4, 5, 6, 7, 8}; }
|
||||
|
|
Loading…
Reference in New Issue