1 | // RUN: %check_clang_tidy -check-suffix=DEFAULT %s \ |
2 | // RUN: cppcoreguidelines-narrowing-conversions %t -- |
3 | |
4 | // RUN: %check_clang_tidy -check-suffix=WARN %s \ |
5 | // RUN: cppcoreguidelines-narrowing-conversions %t -- \ |
6 | // RUN: -config='{CheckOptions: { \ |
7 | // RUN: cppcoreguidelines-narrowing-conversions.WarnWithinTemplateInstantiation: 1 \ |
8 | // RUN: }}' |
9 | |
10 | template <typename OrigType> |
11 | void assign_in_template(OrigType jj) { |
12 | int ii; |
13 | ii = jj; |
14 | // DEFAULT: Warning disabled because WarnWithinTemplateInstantiation=0. |
15 | // CHECK-MESSAGES-WARN: :[[@LINE-2]]:8: warning: narrowing conversion from 'long long' to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions] |
16 | } |
17 | |
18 | void narrow_inside_template_not_ok() { |
19 | long long j = 123; |
20 | assign_in_template(jj: j); |
21 | } |
22 | |
23 | void assign_outside_template(long long jj) { |
24 | int ii; |
25 | ii = jj; |
26 | // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:8: warning: narrowing conversion from 'long long' to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions] |
27 | // CHECK-MESSAGES-WARN: :[[@LINE-2]]:8: warning: narrowing conversion from 'long long' to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions] |
28 | } |
29 | |
30 | void narrow_outside_template_not_ok() { |
31 | long long j = 123; |
32 | assign_outside_template(jj: j); |
33 | } |
34 | |