p7-0x-fixits.cpp revision 191591336f639dad1504e863733fb831645c1644
1// RUN: %clang_cc1 -fsyntax-only -Wc++0x-compat -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
2
3// Verify that the appropriate fixits are emitted for narrowing conversions in
4// initializer lists.
5
6typedef short int16_t;
7
8void fixits() {
9  int x = 999;
10  struct {char c;} c2 = {x};
11  // CHECK: warning:{{.*}} cannot be narrowed
12  // CHECK: fix-it:{{.*}}:26}:"static_cast<char>("
13  // CHECK: fix-it:{{.*}}:27}:")"
14  struct {int16_t i;} i16 = {70000};
15  // CHECK: warning:{{.*}} cannot be narrowed
16  // CHECK: fix-it:{{.*}}:30}:"static_cast<int16_t>("
17  // CHECK: fix-it:{{.*}}:35}:")"
18}
19
20template<typename T>
21void maybe_shrink_int(T t) {
22  struct {T t;} t2 = {700};
23}
24
25void test_template() {
26  maybe_shrink_int((char)3);
27  // CHECK: warning:{{.*}} cannot be narrowed
28  // CHECK: note:{{.*}} in instantiation
29  // CHECK: note:{{.*}} override
30  // FIXME: This should be static_cast<T>.
31  // CHECK: fix-it:{{.*}}"static_cast<char>("
32  // CHECK: fix-it:{{.*}}")"
33}
34