brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.3 KiB · 7d3c74b Raw
56 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -Wmax-unsigned-zero -verify %s -std=c++112// RUN: %clang_cc1 -fsyntax-only -Wmax-unsigned-zero %s -std=c++11 -fdiagnostics-parseable-fixits 2>&1 | FileCheck %s3 4namespace std {5template <typename T>6T max(const T &, const T &);7}8 9void 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  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:20}:""19  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:22-[[@LINE-4]]: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  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:20}:""24  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:21-[[@LINE-4]]: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  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:20}:""29  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:21-[[@LINE-4]]:24}:""30}31 32void 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 39template <unsigned x>40unsigned 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  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:18}:""45  // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:20-[[@LINE-4]]:24}:""46}47 48int a = template_test<0>() + template_test<1>() + template_test<2>();49 50#define comp(x,y) std::max(x, y)51 52int b = comp(0, 1);53int c = comp(0u, 1u);54int d = comp(2u, 0u);55 56