1 // RUN: %clang_cc1 -fcxx-exceptions -fsyntax-only -Wunused -Wunused-template -Wunused-exception-parameter -Wunused-member-function -fdiagnostics-print-source-range-info %s 2>&1 | FileCheck %s --strict-whitespace
2 #include "Inputs/diag-unused-source-ranges.h"
4 #define CAT(a, b) a ## b
6 // CHECK: :{55:15-55:20}: warning: unused exception parameter 'param'
7 // CHECK-NEXT: catch (int ¶m) {}
8 // CHECK-NEXT: ^~~~~{{$}}
10 // CHECK: :{53:7-53:12}: warning: unused variable 'local'
11 // CHECK-NEXT: int local = 0;
12 // CHECK-NEXT: ^~~~~{{$}}
14 // CHECK: In file included from
15 // CHECK-NEXT: :{1:13-1:18}: warning: 'static' function 'thing' declared in header file should be declared 'static inline'
16 // CHECK-NEXT: static void thing(void) {}
17 // CHECK-NEXT: ^~~~~{{$}}
21 // CHECK: :{[[@LINE+3]]:10-[[@LINE+3]]:14}: warning: member function 'func' is not needed
22 // CHECK-NEXT: void func() {}
23 // CHECK-NEXT: ^~~~{{$}}
25 // CHECK: :{[[@LINE+3]]:32-[[@LINE+3]]:37}: warning: unused function template
26 // CHECK-NEXT: void templ(T) {}
27 // CHECK-NEXT: ^~~~~{{$}}
28 template <typename T
> void templ(T
) {}
29 // CHECK: :{[[@LINE+3]]:22-[[@LINE+3]]:32}: warning: member function 'templ<int>' is not needed
30 // CHECK-NEXT: void templ<int>(int) {}
31 // CHECK-NEXT: ^~~~~~~~~~{{$}}
32 template <> void templ
<int>(int) {}
33 // CHECK: :{[[@LINE+3]]:22-[[@LINE+3]]:27}: warning: member function 'templ<float>' is not needed
34 // CHECK-NEXT: void templ(float) {}
35 // CHECK-NEXT: ^~~~~{{$}}
36 template <> void templ(float) {}
38 // CHECK: :{[[@LINE+4]]:10-[[@LINE+4]]:13}: warning: unused function template
39 // CHECK-NEXT: void foo() {
40 // CHECK-NEXT: ^~~{{$}}
49 // CHECK: :{[[@LINE+3]]:12-[[@LINE+3]]:23}: warning: unused function 'unused_func'
50 // CHECK-NEXT: static int unused_func(int aaa, char bbb) {
51 // CHECK-NEXT: ^~~~~~~~~~~{{$}}
52 static int unused_func(int aaa
, char bbb
) {
59 // CHECK: :{[[@LINE+4]]:6-[[@LINE+4]]:16}: warning: unused function template
60 // CHECK-NEXT: auto arrow_decl(T a, T b) ->
61 // CHECK-NEXT: ^~~~~~~~~~{{$}}
63 auto arrow_decl(T a
, T b
) -> decltype(a
+ b
) { thing(); return a
+ b
; }
65 // CHECK: :{[[@LINE+4]]:6-[[@LINE+4]]:21}: warning: unused function 'arrow_decl<int>'
66 // CHECK-NEXT: auto arrow_decl<int>(int a, int b) ->
67 // CHECK-NEXT: ^~~~~~~~~~~~~~~{{$}}
69 auto arrow_decl
<int>(int a
, int b
) -> int { return a
+ b
; }
72 // CHECK: :{[[@LINE+4]]:10-[[@LINE+4]]:20}: warning: unused function template
73 // CHECK-NEXT: static T func_templ(int bbb, T ccc) {
74 // CHECK-NEXT: ^~~~~~~~~~{{$}}
76 static T
func_templ(int bbb
, T ccc
) {
80 // CHECK: :{[[@LINE+3]]:17-[[@LINE+3]]:32}: warning: function 'func_templ<int>' is not needed
81 // CHECK-NEXT: int func_templ<int>(int bbb, int ccc) {
82 // CHECK-NEXT: ^~~~~~~~~~~~~~~{{$}}
83 template <> int func_templ
<int>(int bbb
, int ccc
) {
87 // CHECK: :{[[@LINE+3]]:35-[[@LINE+3]]:47}: warning: unused function template
88 // CHECK-NEXT: static void never_called() {
89 // CHECK-NEXT: ^~~~~~~~~~~~{{$}}
90 template <typename T
> static void never_called() {
91 func_templ
<int>(0, 0);
94 // CHECK: :{[[@LINE+3]]:22-[[@LINE+3]]:31}: warning: unused variable template
95 // CHECK-NEXT: int var_templ =
96 // CHECK-NEXT: ^~~~~~~~~{{$}}
97 template <int n
> int var_templ
= n
* var_templ
<n
-1>;
98 // CHECK: :{[[@LINE+3]]:17-[[@LINE+3]]:29}: warning: variable 'var_templ<0>' is not needed
99 // CHECK-NEXT: int var_templ<0> =
100 // CHECK-NEXT: ^~~~~~~~~~~~{{$}}
101 template <> int var_templ
<0> = 1;
103 // CHECK: :{[[@LINE+3]]:8-[[@LINE+3]]:11}: warning: unused member function 'fun'
104 // CHECK-NEXT: void fun() {}
105 // CHECK-NEXT: ^~~{{$}}
107 // CHECK: :{[[@LINE+3]]:3-[[@LINE+3]]:8}: warning: unused variable 'var_x'
108 // CHECK-NEXT: } var_x;
109 // CHECK-NEXT: ^~~~~{{$}}
112 // CHECK: :{[[@LINE+5]]:12-[[@LINE+6]]:12}: warning: unused variable 'new_line'
113 // CHECK-NEXT: static int CAT(new_,
114 // CHECK-NEXT: ^~~~~~~~~{{$}}
115 // CHECK-NEXT: line) =
116 // CHECK-NEXT: ~~~~~{{$}}
118 line
) = sizeof(var_templ
<0>);
121 // CHECK: :{[[@LINE+3]]:15-[[@LINE+3]]:27}: warning: unused variable 'const_unused'
122 // CHECK-NEXT: constexpr int const_unused = 1
123 // CHECK-NEXT: ^~~~~~~~~~~~{{$}}
124 constexpr int const_unused
= 1;