[Sema] Improve test coverage of narrowing conversion diagnostics
authorMikhail Maltsev <mikhail.maltsev@arm.com>
Fri, 2 Mar 2018 10:03:02 +0000 (10:03 +0000)
committerMikhail Maltsev <mikhail.maltsev@arm.com>
Fri, 2 Mar 2018 10:03:02 +0000 (10:03 +0000)
Summary:
This patch adds tests of narrowing conversion diagnostics for the
'unscoped enum -> integer' case.

Reviewers: faisalv, rsmith, rogfer01

Reviewed By: rogfer01

Subscribers: cfe-commits, rogfer01

Differential Revision: https://reviews.llvm.org/D43572

llvm-svn: 326551

clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp

index 2142c09..4436cb0 100644 (file)
@@ -147,8 +147,10 @@ void int_to_float() {
 void shrink_int() {
   // Not a constant expression.
   short s = 1;
+  UnscopedEnum e = EnumVal;
   unsigned short us = 1;
   Agg<char> c1 = {s};  // expected-error {{ cannot be narrowed }} expected-note {{silence}}
+  Agg<char> c2 = {e};  // expected-error {{ cannot be narrowed }} expected-note {{silence}}
   Agg<unsigned short> s1 = {s};  // expected-error {{ cannot be narrowed }} expected-note {{silence}}
   Agg<short> s2 = {us};  // expected-error {{ cannot be narrowed }} expected-note {{silence}}
 
@@ -158,16 +160,19 @@ void shrink_int() {
   // long).
   long l1 = 1;
   Agg<int> i1 = {l1};  // expected-error {{ cannot be narrowed }} expected-note {{silence}}
+  Agg<int> i2 = {e};  // OK
   long long ll = 1;
   Agg<long> l2 = {ll};  // OK
 
   // Constants.
-  Agg<char> c2 = {127};  // OK
-  Agg<char> c3 = {300};  // expected-error {{ cannot be narrowed }} expected-note {{silence}} expected-warning {{changes value}}
-
-  Agg<int> i2 = {0x7FFFFFFFU};  // OK
-  Agg<int> i3 = {0x80000000U};  // expected-error {{ cannot be narrowed }} expected-note {{silence}}
-  Agg<unsigned int> i4 = {-0x80000000L};  // expected-error {{ cannot be narrowed }} expected-note {{silence}}
+  Agg<char> c3 = {127};  // OK
+  Agg<char> c4 = {300};  // expected-error {{ cannot be narrowed }} expected-note {{silence}} expected-warning {{changes value}}
+  Agg<char> c5 = {EnumVal};  // expected-error {{ cannot be narrowed }} expected-note {{silence}} expected-warning {{changes value}}
+
+  Agg<int> i3 = {0x7FFFFFFFU};  // OK
+  Agg<int> i4 = {EnumVal};  // OK
+  Agg<int> i5 = {0x80000000U};  // expected-error {{ cannot be narrowed }} expected-note {{silence}}
+  Agg<unsigned int> i6 = {-0x80000000L};  // expected-error {{ cannot be narrowed }} expected-note {{silence}}
 
   // Bool is also an integer type, but conversions to it are a different AST
   // node.