1 | // RUN: %clang_cc1 -fsyntax-only -Wmax-unsigned-zero -verify %s -std=c++11 |
2 | // RUN: %clang_cc1 -fsyntax-only -Wmax-unsigned-zero %s -std=c++11 -fdiagnostics-parseable-fixits 2>&1 | FileCheck %s |
3 | |
4 | namespace std { |
5 | template <typename T> |
6 | T max(const T &, const T &); |
7 | } |
8 | |
9 | void test(unsigned u) { |
10 | auto a = std::max(55u, 0u); |
11 | // expected-warning@-1{{taking the max of a value and unsigned zero is always equal to the other value}} |
12 | // expected-note@-2{{remove call to max function and unsigned zero argument}} |
13 | // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:20}:"" |
14 | // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:24-[[@LINE-4]]:28}:"" |
15 | auto b = std::max(u, 0u); |
16 | // expected-warning@-1{{taking the max of a value and unsigned zero is always equal to the other value}} |
17 | // expected-note@-2{{remove call to max function and unsigned zero argument}} |
18 | // fix-it:"/usr/local/google/home/rtrieu/clang/open/llvm/tools/clang/test/SemaCXX/warn-max-unsigned-zero.cpp":{13:12-13:20}:"" |
19 | // fix-it:"/usr/local/google/home/rtrieu/clang/open/llvm/tools/clang/test/SemaCXX/warn-max-unsigned-zero.cpp":{13:22-13:26}:"" |
20 | auto c = std::max(0u, 55u); |
21 | // expected-warning@-1{{taking the max of unsigned zero and a value is always equal to the other value}} |
22 | // expected-note@-2{{remove call to max function and unsigned zero argument}} |
23 | // fix-it:"/usr/local/google/home/rtrieu/clang/open/llvm/tools/clang/test/SemaCXX/warn-max-unsigned-zero.cpp":{16:12-16:20}:"" |
24 | // fix-it:"/usr/local/google/home/rtrieu/clang/open/llvm/tools/clang/test/SemaCXX/warn-max-unsigned-zero.cpp":{16:21-16:24}:"" |
25 | auto d = std::max(0u, u); |
26 | // expected-warning@-1{{taking the max of unsigned zero and a value is always equal to the other value}} |
27 | // expected-note@-2{{remove call to max function and unsigned zero argument}} |
28 | // fix-it:"/usr/local/google/home/rtrieu/clang/open/llvm/tools/clang/test/SemaCXX/warn-max-unsigned-zero.cpp":{19:12-19:20}:"" |
29 | // fix-it:"/usr/local/google/home/rtrieu/clang/open/llvm/tools/clang/test/SemaCXX/warn-max-unsigned-zero.cpp":{19:21-19:24}:"" |
30 | } |
31 | |
32 | void negative_test(signed s) { |
33 | auto a = std::max(0, s); |
34 | auto b = std::max(s, 0); |
35 | auto c = std::max(22, 0); |
36 | auto d = std::max(0, 22); |
37 | } |
38 | |
39 | template <unsigned x> |
40 | unsigned template_test() { |
41 | return std::max(x, 0u); |
42 | // expected-warning@-1{{taking the max of a value and unsigned zero is always equal to the other value}} |
43 | // expected-note@-2{{remove call to max function and unsigned zero argument}} |
44 | // fix-it:"/usr/local/google/home/rtrieu/clang/open/llvm/tools/clang/test/SemaCXX/warn-max-unsigned-zero.cpp":{33:10-33:18}:"" |
45 | // fix-it:"/usr/local/google/home/rtrieu/clang/open/llvm/tools/clang/test/SemaCXX/warn-max-unsigned-zero.cpp":{33:20-33:24}:"" |
46 | } |
47 | |
48 | int a = template_test<0>() + template_test<1>() + template_test<2>(); |
49 | |
50 | #define comp(x,y) std::max(x, y) |
51 | |
52 | int b = comp(0, 1); |
53 | int c = comp(0u, 1u); |
54 | int d = comp(2u, 0u); |
55 | |
56 | |