summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Sema/SemaOverload.cpp3
-rw-r--r--clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp14
2 files changed, 14 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 1b07ec60ce9..2c03f6977aa 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -327,7 +327,8 @@ StandardConversionSequence::getNarrowingKind(ASTContext &Ctx,
FloatingIntegralConversion:
if (FromType->isRealFloatingType() && ToType->isIntegralType(Ctx)) {
return NK_Type_Narrowing;
- } else if (FromType->isIntegralType(Ctx) && ToType->isRealFloatingType()) {
+ } else if (FromType->isIntegralOrUnscopedEnumerationType() &&
+ ToType->isRealFloatingType()) {
llvm::APSInt IntConstantValue;
const Expr *Initializer = IgnoreNarrowingConversion(Converted);
assert(Initializer && "Unknown conversion expression");
diff --git a/clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp b/clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp
index 48c5b23207c..2142c098f88 100644
--- a/clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp
+++ b/clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp
@@ -24,6 +24,10 @@ void std_example() {
{ 2, f(2), f(2.0) }; // OK: the double-to-int conversion is not at the top level
}
+enum UnscopedEnum {
+ EnumVal = 300
+};
+
// Test each rule individually.
template<typename T>
@@ -115,15 +119,21 @@ void shrink_float() {
void int_to_float() {
// Not a constant expression.
char c = 1;
+ UnscopedEnum e = EnumVal;
// Variables. Yes, even though all char's will fit into any floating type.
Agg<float> f1 = {c}; // expected-error {{ cannot be narrowed }} expected-note {{silence}}
Agg<double> f2 = {c}; // expected-error {{ cannot be narrowed }} expected-note {{silence}}
Agg<long double> f3 = {c}; // expected-error {{ cannot be narrowed }} expected-note {{silence}}
+ Agg<float> f4 = {e}; // expected-error {{ cannot be narrowed }} expected-note {{silence}}
+ Agg<double> f5 = {e}; // expected-error {{ cannot be narrowed }} expected-note {{silence}}
+ Agg<long double> f6 = {e}; // expected-error {{ cannot be narrowed }} expected-note {{silence}}
+
// Constants.
- Agg<float> f4 = {12345678}; // OK (exactly fits in a float)
- Agg<float> f5 = {123456789}; // expected-error {{ cannot be narrowed }} expected-note {{silence}}
+ Agg<float> f7 = {12345678}; // OK (exactly fits in a float)
+ Agg<float> f8 = {EnumVal}; // OK
+ Agg<float> f9 = {123456789}; // expected-error {{ cannot be narrowed }} expected-note {{silence}}
Agg<float> ce1 = { Convert<int>(123456789) }; // expected-error {{constant expression evaluates to 123456789 which cannot be narrowed to type 'float'}} expected-note {{silence}}
Agg<double> ce2 = { ConvertVar<long long>() }; // expected-error {{non-constant-expression cannot be narrowed from type 'long long' to 'double'}} expected-note {{silence}}
OpenPOWER on IntegriCloud