aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaOverload.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2012-03-23 23:55:39 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2012-03-23 23:55:39 +0000
commitf602806965531ee06fd8664b9d7a8912c4af2870 (patch)
tree66b36e40cf4f0571cd120ee1e6e9061677cc60b4 /lib/Sema/SemaOverload.cpp
parente78ec3e8f7324e36ac9cf2268d5fe32997762940 (diff)
Teach APValue printer to print boolean 0 and 1 as 'false' and 'true'. Fix up
some calling code to actually pass in a non-null type, to avoid a crash. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@153358 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaOverload.cpp')
-rw-r--r--lib/Sema/SemaOverload.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp
index ff227eee6e..be0243403b 100644
--- a/lib/Sema/SemaOverload.cpp
+++ b/lib/Sema/SemaOverload.cpp
@@ -288,10 +288,13 @@ static const Expr *IgnoreNarrowingConversion(const Expr *Converted) {
/// \param Converted The result of applying this standard conversion sequence.
/// \param ConstantValue If this is an NK_Constant_Narrowing conversion, the
/// value of the expression prior to the narrowing conversion.
+/// \param ConstantType If this is an NK_Constant_Narrowing conversion, the
+/// type of the expression prior to the narrowing conversion.
NarrowingKind
StandardConversionSequence::getNarrowingKind(ASTContext &Ctx,
const Expr *Converted,
- APValue &ConstantValue) const {
+ APValue &ConstantValue,
+ QualType &ConstantType) const {
assert(Ctx.getLangOpts().CPlusPlus && "narrowing check outside C++");
// C++11 [dcl.init.list]p7:
@@ -325,6 +328,7 @@ StandardConversionSequence::getNarrowingKind(ASTContext &Ctx,
// If the resulting value is different, this was a narrowing conversion.
if (IntConstantValue != ConvertedValue) {
ConstantValue = APValue(IntConstantValue);
+ ConstantType = Initializer->getType();
return NK_Constant_Narrowing;
}
} else {
@@ -354,8 +358,10 @@ StandardConversionSequence::getNarrowingKind(ASTContext &Ctx,
llvm::APFloat::rmNearestTiesToEven, &ignored);
// If there was no overflow, the source value is within the range of
// values that can be represented.
- if (ConvertStatus & llvm::APFloat::opOverflow)
+ if (ConvertStatus & llvm::APFloat::opOverflow) {
+ ConstantType = Initializer->getType();
return NK_Constant_Narrowing;
+ }
} else {
return NK_Variable_Narrowing;
}
@@ -400,8 +406,10 @@ StandardConversionSequence::getNarrowingKind(ASTContext &Ctx,
ConvertedValue = ConvertedValue.extend(InitializerValue.getBitWidth());
ConvertedValue.setIsSigned(InitializerValue.isSigned());
// If the result is different, this was a narrowing conversion.
- if (ConvertedValue != InitializerValue)
+ if (ConvertedValue != InitializerValue) {
+ ConstantType = Initializer->getType();
return NK_Constant_Narrowing;
+ }
} else {
// Variables are always narrowings.
return NK_Variable_Narrowing;
@@ -4789,8 +4797,10 @@ ExprResult Sema::CheckConvertedConstantExpression(Expr *From, QualType T,
// Check for a narrowing implicit conversion.
APValue PreNarrowingValue;
+ QualType PreNarrowingType;
bool Diagnosed = false;
- switch (SCS->getNarrowingKind(Context, Result.get(), PreNarrowingValue)) {
+ switch (SCS->getNarrowingKind(Context, Result.get(), PreNarrowingValue,
+ PreNarrowingType)) {
case NK_Variable_Narrowing:
// Implicit conversion to a narrower type, and the value is not a constant
// expression. We'll diagnose this in a moment.
@@ -4800,7 +4810,7 @@ ExprResult Sema::CheckConvertedConstantExpression(Expr *From, QualType T,
case NK_Constant_Narrowing:
Diag(From->getLocStart(), diag::err_cce_narrowing)
<< CCE << /*Constant*/1
- << PreNarrowingValue.getAsString(Context, QualType()) << T;
+ << PreNarrowingValue.getAsString(Context, PreNarrowingType) << T;
Diagnosed = true;
break;