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