[clang-tools-extra] r374540 - [ClangTidy] Separate tests for infrastructure and checkers
Dmitri Gribenko via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 11 05:05:46 PDT 2019
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-bool-literals-ignore-macros.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-bool-literals-ignore-macros.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-bool-literals-ignore-macros.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-bool-literals-ignore-macros.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,147 @@
+// RUN: %check_clang_tidy %s modernize-use-bool-literals %t -- \
+// RUN: -config="{CheckOptions: \
+// RUN: [{key: modernize-use-bool-literals.IgnoreMacros, \
+// RUN: value: 1}]}"
+
+bool IntToTrue = 1;
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: converting integer literal to bool, use bool literal instead [modernize-use-bool-literals]
+// CHECK-FIXES: {{^}}bool IntToTrue = true;{{$}}
+
+bool IntToFalse(0);
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: converting integer literal to bool
+// CHECK-FIXES: {{^}}bool IntToFalse(false);{{$}}
+
+bool LongLongToTrue{0x1LL};
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: converting integer literal to bool
+// CHECK-FIXES: {{^}}bool LongLongToTrue{true};{{$}}
+
+bool ExplicitCStyleIntToFalse = (bool)0;
+// CHECK-MESSAGES: :[[@LINE-1]]:33: warning: converting integer literal to bool
+// CHECK-FIXES: {{^}}bool ExplicitCStyleIntToFalse = false;{{$}}
+
+bool ExplicitFunctionalIntToFalse = bool(0);
+// CHECK-MESSAGES: :[[@LINE-1]]:37: warning: converting integer literal to bool
+// CHECK-FIXES: {{^}}bool ExplicitFunctionalIntToFalse = false;{{$}}
+
+bool ExplicitStaticIntToFalse = static_cast<bool>(0);
+// CHECK-MESSAGES: :[[@LINE-1]]:33: warning: converting integer literal to bool
+// CHECK-FIXES: {{^}}bool ExplicitStaticIntToFalse = false;{{$}}
+
+#define TRUE_MACRO 1
+// CHECK-FIXES: {{^}}#define TRUE_MACRO 1{{$}}
+
+bool MacroIntToTrue = TRUE_MACRO;
+// CHECK-FIXES: {{^}}bool MacroIntToTrue = TRUE_MACRO;{{$}}
+
+#define FALSE_MACRO bool(0)
+// CHECK-FIXES: {{^}}#define FALSE_MACRO bool(0){{$}}
+
+bool TrueBool = true; // OK
+
+bool FalseBool = bool(FALSE_MACRO);
+// CHECK-FIXES: {{^}}bool FalseBool = bool(FALSE_MACRO);{{$}}
+
+void boolFunction(bool bar) {
+
+}
+
+char Character = 0; // OK
+
+unsigned long long LongInteger = 1; // OK
+
+#define MACRO_DEPENDENT_CAST(x) static_cast<bool>(x)
+// CHECK-FIXES: {{^}}#define MACRO_DEPENDENT_CAST(x) static_cast<bool>(x){{$}}
+
+bool MacroDependentBool = MACRO_DEPENDENT_CAST(0);
+// CHECK-FIXES: {{^}}bool MacroDependentBool = MACRO_DEPENDENT_CAST(0);{{$}}
+
+bool ManyMacrosDependent = MACRO_DEPENDENT_CAST(FALSE_MACRO);
+// CHECK-FIXES: {{^}}bool ManyMacrosDependent = MACRO_DEPENDENT_CAST(FALSE_MACRO);{{$}}
+
+class FooClass {
+ public:
+ FooClass() : JustBool(0) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: converting integer literal to bool
+ // CHECK-FIXES: {{^ *}}FooClass() : JustBool(false) {}{{$}}
+ FooClass(int) : JustBool{0} {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: converting integer literal to bool
+ // CHECK-FIXES: {{^ *}}FooClass(int) : JustBool{false} {}{{$}}
+ private:
+ bool JustBool;
+ bool BoolWithBraces{0};
+ // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: converting integer literal to bool
+ // CHECK-FIXES: {{^ *}}bool BoolWithBraces{false};{{$}}
+ bool BoolFromInt = 0;
+ // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: converting integer literal to bool
+ // CHECK-FIXES: {{^ *}}bool BoolFromInt = false;{{$}}
+ bool SimpleBool = true; // OK
+};
+
+template<typename type>
+void templateFunction(type) {
+ type TemplateType = 0;
+ // CHECK-FIXES: {{^ *}}type TemplateType = 0;{{$}}
+}
+
+template<int c>
+void valueDependentTemplateFunction() {
+ bool Boolean = c;
+ // CHECK-FIXES: {{^ *}}bool Boolean = c;{{$}}
+}
+
+template<typename type>
+void anotherTemplateFunction(type) {
+ bool JustBool = 0;
+ // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: converting integer literal to bool
+ // CHECK-FIXES: {{^ *}}bool JustBool = false;{{$}}
+}
+
+int main() {
+ boolFunction(1);
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: converting integer literal to bool
+ // CHECK-FIXES: {{^ *}}boolFunction(true);{{$}}
+
+ boolFunction(false);
+
+ templateFunction(0);
+
+ templateFunction(false);
+
+ valueDependentTemplateFunction<1>();
+
+ anotherTemplateFunction(1);
+
+ IntToTrue = 1;
+ // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: converting integer literal to bool
+ // CHECK-FIXES: {{^ *}}IntToTrue = true;{{$}}
+}
+
+static int Value = 1;
+
+bool Function1() {
+ bool Result = Value == 1 ? 1 : 0;
+ // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: converting integer literal to bool
+ // CHECK-MESSAGES: :[[@LINE-2]]:34: warning: converting integer literal to bool
+ // CHECK-FIXES: {{^ *}}bool Result = Value == 1 ? true : false;{{$}}
+ return Result;
+}
+
+bool Function2() {
+ return Value == 1 ? 1 : 0;
+ // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: converting integer literal to bool
+ // CHECK-MESSAGES: :[[@LINE-2]]:27: warning: converting integer literal to bool
+ // CHECK-FIXES: {{^ *}}return Value == 1 ? true : false;{{$}}
+}
+
+void foo() {
+ bool Result;
+ Result = Value == 1 ? true : 0;
+ // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: converting integer literal to bool
+ // CHECK-FIXES: {{^ *}}Result = Value == 1 ? true : false;{{$}}
+ Result = Value == 1 ? false : bool(0);
+ // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: converting integer literal to bool
+ // CHECK-FIXES: {{^ *}}Result = Value == 1 ? false : false;{{$}}
+ Result = Value == 1 ? (bool)0 : false;
+ // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: converting integer literal to bool
+ // CHECK-FIXES: {{^ *}}Result = Value == 1 ? false : false;{{$}}
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-bool-literals.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-bool-literals.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-bool-literals.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-bool-literals.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,151 @@
+// RUN: %check_clang_tidy %s modernize-use-bool-literals %t -- \
+// RUN: -config="{CheckOptions: \
+// RUN: [{key: modernize-use-bool-literals.IgnoreMacros, \
+// RUN: value: 0}]}"
+
+bool IntToTrue = 1;
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: converting integer literal to bool, use bool literal instead [modernize-use-bool-literals]
+// CHECK-FIXES: {{^}}bool IntToTrue = true;{{$}}
+
+bool IntToFalse(0);
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: converting integer literal to bool
+// CHECK-FIXES: {{^}}bool IntToFalse(false);{{$}}
+
+bool LongLongToTrue{0x1LL};
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: converting integer literal to bool
+// CHECK-FIXES: {{^}}bool LongLongToTrue{true};{{$}}
+
+bool ExplicitCStyleIntToFalse = (bool)0;
+// CHECK-MESSAGES: :[[@LINE-1]]:33: warning: converting integer literal to bool
+// CHECK-FIXES: {{^}}bool ExplicitCStyleIntToFalse = false;{{$}}
+
+bool ExplicitFunctionalIntToFalse = bool(0);
+// CHECK-MESSAGES: :[[@LINE-1]]:37: warning: converting integer literal to bool
+// CHECK-FIXES: {{^}}bool ExplicitFunctionalIntToFalse = false;{{$}}
+
+bool ExplicitStaticIntToFalse = static_cast<bool>(0);
+// CHECK-MESSAGES: :[[@LINE-1]]:33: warning: converting integer literal to bool
+// CHECK-FIXES: {{^}}bool ExplicitStaticIntToFalse = false;{{$}}
+
+#define TRUE_MACRO 1
+// CHECK-FIXES: {{^}}#define TRUE_MACRO 1{{$}}
+
+bool MacroIntToTrue = TRUE_MACRO;
+// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: converting integer literal to bool
+// CHECK-FIXES: {{^}}bool MacroIntToTrue = TRUE_MACRO;{{$}}
+
+#define FALSE_MACRO bool(0)
+// CHECK-FIXES: {{^}}#define FALSE_MACRO bool(0){{$}}
+
+bool TrueBool = true; // OK
+
+bool FalseBool = bool(FALSE_MACRO);
+// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: converting integer literal to bool
+// CHECK-FIXES: {{^}}bool FalseBool = bool(FALSE_MACRO);{{$}}
+
+void boolFunction(bool bar) {
+
+}
+
+char Character = 0; // OK
+
+unsigned long long LongInteger = 1; // OK
+
+#define MACRO_DEPENDENT_CAST(x) static_cast<bool>(x)
+// CHECK-FIXES: {{^}}#define MACRO_DEPENDENT_CAST(x) static_cast<bool>(x){{$}}
+
+bool MacroDependentBool = MACRO_DEPENDENT_CAST(0);
+// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: converting integer literal to bool
+// CHECK-FIXES: {{^}}bool MacroDependentBool = MACRO_DEPENDENT_CAST(0);{{$}}
+
+bool ManyMacrosDependent = MACRO_DEPENDENT_CAST(FALSE_MACRO);
+// CHECK-MESSAGES: :[[@LINE-1]]:49: warning: converting integer literal to bool
+// CHECK-FIXES: {{^}}bool ManyMacrosDependent = MACRO_DEPENDENT_CAST(FALSE_MACRO);{{$}}
+
+class FooClass {
+ public:
+ FooClass() : JustBool(0) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: converting integer literal to bool
+ // CHECK-FIXES: {{^ *}}FooClass() : JustBool(false) {}{{$}}
+ FooClass(int) : JustBool{0} {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: converting integer literal to bool
+ // CHECK-FIXES: {{^ *}}FooClass(int) : JustBool{false} {}{{$}}
+ private:
+ bool JustBool;
+ bool BoolWithBraces{0};
+ // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: converting integer literal to bool
+ // CHECK-FIXES: {{^ *}}bool BoolWithBraces{false};{{$}}
+ bool BoolFromInt = 0;
+ // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: converting integer literal to bool
+ // CHECK-FIXES: {{^ *}}bool BoolFromInt = false;{{$}}
+ bool SimpleBool = true; // OK
+};
+
+template<typename type>
+void templateFunction(type) {
+ type TemplateType = 0;
+ // CHECK-FIXES: {{^ *}}type TemplateType = 0;{{$}}
+}
+
+template<int c>
+void valueDependentTemplateFunction() {
+ bool Boolean = c;
+ // CHECK-FIXES: {{^ *}}bool Boolean = c;{{$}}
+}
+
+template<typename type>
+void anotherTemplateFunction(type) {
+ bool JustBool = 0;
+ // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: converting integer literal to bool
+ // CHECK-FIXES: {{^ *}}bool JustBool = false;{{$}}
+}
+
+int main() {
+ boolFunction(1);
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: converting integer literal to bool
+ // CHECK-FIXES: {{^ *}}boolFunction(true);{{$}}
+
+ boolFunction(false);
+
+ templateFunction(0);
+
+ templateFunction(false);
+
+ valueDependentTemplateFunction<1>();
+
+ anotherTemplateFunction(1);
+
+ IntToTrue = 1;
+ // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: converting integer literal to bool
+ // CHECK-FIXES: {{^ *}}IntToTrue = true;{{$}}
+}
+
+static int Value = 1;
+
+bool Function1() {
+ bool Result = Value == 1 ? 1 : 0;
+ // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: converting integer literal to bool
+ // CHECK-MESSAGES: :[[@LINE-2]]:34: warning: converting integer literal to bool
+ // CHECK-FIXES: {{^ *}}bool Result = Value == 1 ? true : false;{{$}}
+ return Result;
+}
+
+bool Function2() {
+ return Value == 1 ? 1 : 0;
+ // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: converting integer literal to bool
+ // CHECK-MESSAGES: :[[@LINE-2]]:27: warning: converting integer literal to bool
+ // CHECK-FIXES: {{^ *}}return Value == 1 ? true : false;{{$}}
+}
+
+void foo() {
+ bool Result;
+ Result = Value == 1 ? true : 0;
+ // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: converting integer literal to bool
+ // CHECK-FIXES: {{^ *}}Result = Value == 1 ? true : false;{{$}}
+ Result = Value == 1 ? false : bool(0);
+ // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: converting integer literal to bool
+ // CHECK-FIXES: {{^ *}}Result = Value == 1 ? false : false;{{$}}
+ Result = Value == 1 ? (bool)0 : false;
+ // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: converting integer literal to bool
+ // CHECK-FIXES: {{^ *}}Result = Value == 1 ? false : false;{{$}}
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-default-member-init-assignment.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-default-member-init-assignment.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-default-member-init-assignment.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-default-member-init-assignment.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,192 @@
+// RUN: %check_clang_tidy %s modernize-use-default-member-init %t -- \
+// RUN: -config="{CheckOptions: [{key: modernize-use-default-member-init.UseAssignment, value: 1}]}"
+
+struct S {
+};
+
+struct PositiveValueChar {
+ PositiveValueChar() : c0(), c1()/*, c2(), c3()*/ {}
+ // CHECK-FIXES: PositiveValueChar() {}
+ const char c0;
+ // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: use default member initializer for 'c0' [modernize-use-default-member-init]
+ // CHECK-FIXES: const char c0 = '\0';
+ wchar_t c1;
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: use default member initializer for 'c1'
+ // CHECK-FIXES: wchar_t c1 = L'\0';
+ // FIXME: char16_t c2;
+ // C HECK-MESSAGES: :[[@LINE-1]]:12: warning: use default member initializer for 'c2'
+ // C HECK-FIXES: char16_t c2 = u'\0';
+ // FIXME: char32_t c3;
+ // C HECK-MESSAGES: :[[@LINE-1]]:12: warning: use default member initializer for 'c3'
+ // C HECK-FIXES: char32_t c3 = U'\0';
+};
+
+struct PositiveChar {
+ PositiveChar() : d('a') {}
+ // CHECK-FIXES: PositiveChar() {}
+ char d;
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'd'
+ // CHECK-FIXES: char d = 'a';
+};
+
+struct PositiveValueInt {
+ PositiveValueInt() : i() {}
+ // CHECK-FIXES: PositiveValueInt() {}
+ const int i;
+ // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use default member initializer for 'i'
+ // CHECK-FIXES: const int i = 0;
+};
+
+struct PositiveInt {
+ PositiveInt() : j(1) {}
+ // CHECK-FIXES: PositiveInt() {}
+ int j;
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'j'
+ // CHECK-FIXES: int j = 1;
+};
+
+struct PositiveUnaryMinusInt {
+ PositiveUnaryMinusInt() : j(-1) {}
+ // CHECK-FIXES: PositiveUnaryMinusInt() {}
+ int j;
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'j'
+ // CHECK-FIXES: int j = -1;
+};
+
+struct PositiveUnaryPlusInt {
+ PositiveUnaryPlusInt() : j(+1) {}
+ // CHECK-FIXES: PositiveUnaryPlusInt() {}
+ int j;
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'j'
+ // CHECK-FIXES: int j = +1;
+};
+
+struct PositiveValueComplexInt {
+ PositiveValueComplexInt() : i() {}
+ // CHECK-FIXES: PositiveValueComplexInt() {}
+ _Complex int i;
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use default member initializer for 'i'
+ // CHECK-FIXES: _Complex int i = 0;
+};
+
+struct PositiveValueFloat {
+ PositiveValueFloat() : f() {}
+ // CHECK-FIXES: PositiveValueFloat() {}
+ float f;
+ // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use default member initializer for 'f'
+ // CHECK-FIXES: float f = 0.0f;
+};
+
+struct PositiveValueDouble {
+ PositiveValueDouble() : d() {}
+ // CHECK-FIXES: PositiveValueDouble() {}
+ double d;
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'd'
+ // CHECK-FIXES: double d = 0.0;
+};
+
+struct PositiveDouble {
+ PositiveDouble() : f(2.5463e43) {}
+ // CHECK-FIXES: PositiveDouble() {}
+ double f;
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'f'
+ // CHECK-FIXES: double f = 2.5463e43;
+};
+
+struct PositiveValueComplexFloat {
+ PositiveValueComplexFloat() : f() {}
+ // CHECK-FIXES: PositiveValueComplexFloat() {}
+ _Complex float f;
+ // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: use default member initializer for 'f'
+ // CHECK-FIXES: _Complex float f = 0.0f;
+};
+
+struct PositiveValueComplexDouble {
+ PositiveValueComplexDouble() : f() {}
+ // CHECK-FIXES: PositiveValueComplexDouble() {}
+ _Complex double f;
+ // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use default member initializer for 'f'
+ // CHECK-FIXES: _Complex double f = 0.0;
+};
+
+struct PositiveUnaryMinusDouble {
+ PositiveUnaryMinusDouble() : f(-2.5463e43) {}
+ // CHECK-FIXES: PositiveUnaryMinusDouble() {}
+ double f;
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'f'
+ // CHECK-FIXES: double f = -2.5463e43;
+};
+
+struct PositiveUnaryPlusDouble {
+ PositiveUnaryPlusDouble() : f(+2.5463e43) {}
+ // CHECK-FIXES: PositiveUnaryPlusDouble() {}
+ double f;
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'f'
+ // CHECK-FIXES: double f = +2.5463e43;
+};
+
+struct PositiveValueBool {
+ PositiveValueBool() : b() {}
+ // CHECK-FIXES: PositiveValueBool() {}
+ bool b;
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'b'
+ // CHECK-FIXES: bool b = false;
+};
+
+struct PositiveBool {
+ PositiveBool() : a(true) {}
+ // CHECK-FIXES: PositiveBool() {}
+ bool a;
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'a'
+ // CHECK-FIXES: bool a = true;
+};
+
+struct PositiveValuePointer {
+ PositiveValuePointer() : p() {}
+ // CHECK-FIXES: PositiveValuePointer() {}
+ int *p;
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'p'
+ // CHECK-FIXES: int *p = nullptr;
+};
+
+struct PositiveNullPointer {
+ PositiveNullPointer() : q(nullptr) {}
+ // CHECK-FIXES: PositiveNullPointer() {}
+ int *q;
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'q'
+ // CHECK-FIXES: int *q = nullptr;
+};
+
+enum Enum { Foo };
+struct PositiveEnum {
+ PositiveEnum() : e(Foo) {}
+ // CHECK-FIXES: PositiveEnum() {}
+ Enum e;
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'e'
+ // CHECK-FIXES: Enum e = Foo;
+};
+
+struct PositiveValueEnum {
+ PositiveValueEnum() : e() {}
+ // CHECK-FIXES: PositiveValueEnum() {}
+ Enum e;
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'e'
+ // CHECK-FIXES: Enum e{};
+};
+
+struct PositiveString {
+ PositiveString() : s("foo") {}
+ // CHECK-FIXES: PositiveString() {}
+ const char *s;
+ // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: use default member initializer for 's'
+ // CHECK-FIXES: const char *s = "foo";
+};
+
+template <typename T>
+struct NegativeTemplate {
+ NegativeTemplate() : t() {}
+ T t;
+};
+
+NegativeTemplate<int> nti;
+NegativeTemplate<double> ntd;
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-default-member-init-bitfield.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-default-member-init-bitfield.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-default-member-init-bitfield.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-default-member-init-bitfield.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,10 @@
+// RUN: %check_clang_tidy -std=c++2a-or-later %s modernize-use-default-member-init %t
+
+struct PositiveBitField
+{
+ PositiveBitField() : i(6) {}
+ // CHECK-FIXES: PositiveBitField() {}
+ int i : 5;
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'i' [modernize-use-default-member-init]
+ // CHECK-FIXES: int i : 5{6};
+};
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-default-member-init-macros.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-default-member-init-macros.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-default-member-init-macros.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-default-member-init-macros.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,17 @@
+// RUN: %check_clang_tidy %s modernize-use-default-member-init %t -- \
+// RUN: -config="{CheckOptions: [{key: modernize-use-default-member-init.IgnoreMacros, value: 0}]}"
+
+#define MACRO() \
+ struct S { \
+ void *P; \
+ S() : P(nullptr) {} \
+ };
+
+MACRO();
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use default member initializer for 'P'
+
+struct S2 {
+ void *P;
+ // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use default member initializer for 'P'
+ S2() : P(nullptr) {}
+};
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-default-member-init.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-default-member-init.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-default-member-init.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-default-member-init.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,420 @@
+// RUN: %check_clang_tidy -std=c++11,c++14,c++17 %s modernize-use-default-member-init %t
+// FIXME: Fix the checker to work in C++2a mode.
+
+struct S {
+};
+
+struct PositiveValueChar {
+ PositiveValueChar() : c0(), c1()/*, c2(), c3()*/ {}
+ // CHECK-FIXES: PositiveValueChar() {}
+ const char c0;
+ // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: use default member initializer for 'c0' [modernize-use-default-member-init]
+ // CHECK-FIXES: const char c0{};
+ wchar_t c1;
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: use default member initializer for 'c1'
+ // CHECK-FIXES: wchar_t c1{};
+ // FIXME: char16_t c2;
+ // C HECK-MESSAGES: :[[@LINE-1]]:12: warning: use default member initializer for 'c2'
+ // C HECK-FIXES: char16_t c2{};
+ // FIXME: char32_t c3;
+ // C HECK-MESSAGES: :[[@LINE-1]]:12: warning: use default member initializer for 'c3'
+ // C HECK-FIXES: char32_t c3{};
+};
+
+struct PositiveChar {
+ PositiveChar() : d('a') {}
+ // CHECK-FIXES: PositiveChar() {}
+ char d;
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'd'
+ // CHECK-FIXES: char d{'a'};
+};
+
+struct PositiveValueInt {
+ PositiveValueInt() : i() {}
+ // CHECK-FIXES: PositiveValueInt() {}
+ const int i;
+ // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use default member initializer for 'i'
+ // CHECK-FIXES: const int i{};
+};
+
+struct PositiveInt {
+ PositiveInt() : j(1) {}
+ // CHECK-FIXES: PositiveInt() {}
+ int j;
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'j'
+ // CHECK-FIXES: int j{1};
+};
+
+struct PositiveUnaryMinusInt {
+ PositiveUnaryMinusInt() : j(-1) {}
+ // CHECK-FIXES: PositiveUnaryMinusInt() {}
+ int j;
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'j'
+ // CHECK-FIXES: int j{-1};
+};
+
+struct PositiveUnaryPlusInt {
+ PositiveUnaryPlusInt() : j(+1) {}
+ // CHECK-FIXES: PositiveUnaryPlusInt() {}
+ int j;
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'j'
+ // CHECK-FIXES: int j{+1};
+};
+
+struct PositiveValueComplexInt {
+ PositiveValueComplexInt() : i() {}
+ // CHECK-FIXES: PositiveValueComplexInt() {}
+ _Complex int i;
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use default member initializer for 'i'
+ // CHECK-FIXES: _Complex int i{};
+};
+
+struct PositiveValueFloat {
+ PositiveValueFloat() : f() {}
+ // CHECK-FIXES: PositiveValueFloat() {}
+ float f;
+ // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use default member initializer for 'f'
+ // CHECK-FIXES: float f{};
+};
+
+struct PositiveValueDouble {
+ PositiveValueDouble() : d() {}
+ // CHECK-FIXES: PositiveValueDouble() {}
+ double d;
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'd'
+ // CHECK-FIXES: double d{};
+};
+
+struct PositiveDouble {
+ PositiveDouble() : f(2.5463e43) {}
+ // CHECK-FIXES: PositiveDouble() {}
+ double f;
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'f'
+ // CHECK-FIXES: double f{2.5463e43};
+};
+
+struct PositiveValueComplexFloat {
+ PositiveValueComplexFloat() : f() {}
+ // CHECK-FIXES: PositiveValueComplexFloat() {}
+ _Complex float f;
+ // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: use default member initializer for 'f'
+ // CHECK-FIXES: _Complex float f{};
+};
+
+struct PositiveValueComplexDouble {
+ PositiveValueComplexDouble() : f() {}
+ // CHECK-FIXES: PositiveValueComplexDouble() {}
+ _Complex double f;
+ // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use default member initializer for 'f'
+ // CHECK-FIXES: _Complex double f{};
+};
+
+struct PositiveUnaryMinusDouble {
+ PositiveUnaryMinusDouble() : f(-2.5463e43) {}
+ // CHECK-FIXES: PositiveUnaryMinusDouble() {}
+ double f;
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'f'
+ // CHECK-FIXES: double f{-2.5463e43};
+};
+
+struct PositiveUnaryPlusDouble {
+ PositiveUnaryPlusDouble() : f(+2.5463e43) {}
+ // CHECK-FIXES: PositiveUnaryPlusDouble() {}
+ double f;
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'f'
+ // CHECK-FIXES: double f{+2.5463e43};
+};
+
+struct PositiveValueBool {
+ PositiveValueBool() : b() {}
+ // CHECK-FIXES: PositiveValueBool() {}
+ bool b;
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'b'
+ // CHECK-FIXES: bool b{};
+};
+
+struct PositiveBool {
+ PositiveBool() : a(true) {}
+ // CHECK-FIXES: PositiveBool() {}
+ bool a;
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'a'
+ // CHECK-FIXES: bool a{true};
+};
+
+struct PositiveValuePointer {
+ PositiveValuePointer() : p() {}
+ // CHECK-FIXES: PositiveValuePointer() {}
+ int *p;
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'p'
+ // CHECK-FIXES: int *p{};
+};
+
+struct PositiveNullPointer {
+ PositiveNullPointer() : q(nullptr) {}
+ // CHECK-FIXES: PositiveNullPointer() {}
+ int *q;
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'q'
+ // CHECK-FIXES: int *q{nullptr};
+};
+
+enum Enum { Foo, Bar };
+struct PositiveEnum {
+ PositiveEnum() : e(Foo) {}
+ // CHECK-FIXES: PositiveEnum() {}
+ Enum e;
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'e'
+ // CHECK-FIXES: Enum e{Foo};
+};
+
+struct PositiveValueEnum {
+ PositiveValueEnum() : e() {}
+ // CHECK-FIXES: PositiveValueEnum() {}
+ Enum e;
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'e'
+ // CHECK-FIXES: Enum e{};
+};
+
+struct PositiveString {
+ PositiveString() : s("foo") {}
+ // CHECK-FIXES: PositiveString() {}
+ const char *s;
+ // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: use default member initializer for 's'
+ // CHECK-FIXES: const char *s{"foo"};
+};
+
+struct PositiveStruct {
+ PositiveStruct() : s(7) {}
+ // CHECK-FIXES: PositiveStruct() {}
+ struct {
+ int s;
+ // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use default member initializer for 's'
+ // CHECK-FIXES: int s{7};
+ };
+};
+
+template <typename T>
+struct NegativeTemplate {
+ NegativeTemplate() : t() {}
+ T t;
+};
+
+NegativeTemplate<int> nti;
+NegativeTemplate<double> ntd;
+
+struct NegativeDefaultMember {
+ NegativeDefaultMember() {}
+ int i = 2;
+};
+
+struct NegativeClass : S {
+ NegativeClass() : s() {}
+ S s;
+};
+
+struct NegativeBase : S {
+ NegativeBase() : S() {}
+};
+
+struct NegativeDefaultOtherMember{
+ NegativeDefaultOtherMember() : i(3) {}
+ int i = 4;
+};
+
+struct NegativeUnion {
+ NegativeUnion() : d(5.0) {}
+ union {
+ int i;
+ double d;
+ };
+};
+
+struct NegativeBitField
+{
+ NegativeBitField() : i(6) {}
+ int i : 5;
+};
+
+struct NegativeNotDefaultInt
+{
+ NegativeNotDefaultInt(int) : i(7) {}
+ int i;
+};
+
+struct NegativeDefaultArg
+{
+ NegativeDefaultArg(int i = 4) : i(i) {}
+ int i;
+};
+
+struct ExistingChar {
+ ExistingChar(short) : e1(), e2(), e3(), e4() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: member initializer for 'e1' is redundant [modernize-use-default-member-init]
+ // CHECK-MESSAGES: :[[@LINE-2]]:31: warning: member initializer for 'e2' is redundant
+ // CHECK-MESSAGES: :[[@LINE-3]]:37: warning: member initializer for 'e3' is redundant
+ // CHECK-FIXES: ExistingChar(short) : e4() {}
+ ExistingChar(int) : e1(0), e2(0), e3(0), e4(0) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: member initializer for 'e1' is redundant
+ // CHECK-MESSAGES: :[[@LINE-2]]:30: warning: member initializer for 'e2' is redundant
+ // CHECK-MESSAGES: :[[@LINE-3]]:37: warning: member initializer for 'e3' is redundant
+ // CHECK-FIXES: ExistingChar(int) : e4(0) {}
+ ExistingChar(long) : e1('\0'), e2('\0'), e3('\0'), e4('\0') {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: member initializer for 'e1' is redundant
+ // CHECK-MESSAGES: :[[@LINE-2]]:34: warning: member initializer for 'e2' is redundant
+ // CHECK-MESSAGES: :[[@LINE-3]]:44: warning: member initializer for 'e3' is redundant
+ // CHECK-FIXES: ExistingChar(long) : e4('\0') {}
+ ExistingChar(char) : e1('a'), e2('a'), e3('a'), e4('a') {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:51: warning: member initializer for 'e4' is redundant
+ // CHECK-FIXES: ExistingChar(char) : e1('a'), e2('a'), e3('a') {}
+ char e1{};
+ char e2 = 0;
+ char e3 = '\0';
+ char e4 = 'a';
+};
+
+struct ExistingInt {
+ ExistingInt(short) : e1(), e2(), e3(), e4(), e5(), e6() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: member initializer for 'e1' is redundant [modernize-use-default-member-init]
+ // CHECK-MESSAGES: :[[@LINE-2]]:30: warning: member initializer for 'e2' is redundant
+ // CHECK-FIXES: ExistingInt(short) : e3(), e4(), e5(), e6() {}
+ ExistingInt(int) : e1(0), e2(0), e3(0), e4(0), e5(0), e6(0) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: member initializer for 'e1' is redundant
+ // CHECK-MESSAGES: :[[@LINE-2]]:29: warning: member initializer for 'e2' is redundant
+ // CHECK-FIXES: ExistingInt(int) : e3(0), e4(0), e5(0), e6(0) {}
+ ExistingInt(long) : e1(5), e2(5), e3(5), e4(5), e5(5), e6(5) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: member initializer for 'e3' is redundant
+ // CHECK-MESSAGES: :[[@LINE-2]]:44: warning: member initializer for 'e4' is redundant
+ // CHECK-MESSAGES: :[[@LINE-3]]:58: warning: member initializer for 'e6' is redundant
+ // CHECK-FIXES: ExistingInt(long) : e1(5), e2(5), e5(5) {}
+ ExistingInt(char) : e1(-5), e2(-5), e3(-5), e4(-5), e5(-5), e6(-5) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:55: warning: member initializer for 'e5' is redundant
+ // CHECK-FIXES: ExistingInt(char) : e1(-5), e2(-5), e3(-5), e4(-5), e6(-5) {}
+ int e1{};
+ int e2 = 0;
+ int e3 = {5};
+ int e4 = 5;
+ int e5 = -5;
+ int e6 = +5;
+};
+
+struct ExistingDouble {
+ ExistingDouble(short) : e1(), e2(), e3(), e4(), e5() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: member initializer for 'e1' is redundant
+ // CHECK-MESSAGES: :[[@LINE-2]]:33: warning: member initializer for 'e2' is redundant
+ // CHECK-FIXES: ExistingDouble(short) : e3(), e4(), e5() {}
+ ExistingDouble(int) : e1(0.0), e2(0.0), e3(0.0), e4(0.0), e5(0.0) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: member initializer for 'e1' is redundant
+ // CHECK-MESSAGES: :[[@LINE-2]]:34: warning: member initializer for 'e2' is redundant
+ // CHECK-FIXES: ExistingDouble(int) : e3(0.0), e4(0.0), e5(0.0) {}
+ ExistingDouble(long) : e1(5.0), e2(5.0), e3(5.0), e4(5.0), e5(5.0) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:44: warning: member initializer for 'e3' is redundant
+ // CHECK-MESSAGES: :[[@LINE-2]]:62: warning: member initializer for 'e5' is redundant
+ // CHECK-FIXES: ExistingDouble(long) : e1(5.0), e2(5.0), e4(5.0) {}
+ ExistingDouble(char) : e1(-5.0), e2(-5.0), e3(-5.0), e4(-5.0), e5(-5.0) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:56: warning: member initializer for 'e4' is redundant
+ // CHECK-FIXES: ExistingDouble(char) : e1(-5.0), e2(-5.0), e3(-5.0), e5(-5.0) {}
+ double e1{};
+ double e2 = 0.0;
+ double e3 = 5.0;
+ double e4 = -5.0;
+ double e5 = +5.0;
+};
+
+struct ExistingBool {
+ ExistingBool(short) : e1(), e2(), e3() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: member initializer for 'e1' is redundant
+ // CHECK-MESSAGES: :[[@LINE-2]]:31: warning: member initializer for 'e2' is redundant
+ // CHECK-FIXES: ExistingBool(short) : e3() {}
+ ExistingBool(int) : e1(false), e2(false), e3(false) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: member initializer for 'e1' is redundant
+ // CHECK-MESSAGES: :[[@LINE-2]]:34: warning: member initializer for 'e2' is redundant
+ // CHECK-FIXES: ExistingBool(int) : e3(false) {}
+ ExistingBool(long) : e1(true), e2(true), e3(true) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:44: warning: member initializer for 'e3' is redundant
+ // CHECK-FIXES: ExistingBool(long) : e1(true), e2(true) {}
+ bool e1{};
+ bool e2 = false;
+ bool e3 = true;
+};
+
+struct ExistingEnum {
+ ExistingEnum(short) : e1(Foo), e2(Foo) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: member initializer for 'e1' is redundant
+ // CHECK-FIXES: ExistingEnum(short) : e2(Foo) {}
+ ExistingEnum(int) : e1(Bar), e2(Bar) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: member initializer for 'e2' is redundant
+ // CHECK-FIXES: ExistingEnum(int) : e1(Bar) {}
+ Enum e1 = Foo;
+ Enum e2{Bar};
+};
+
+struct ExistingPointer {
+ ExistingPointer(short) : e1(), e2(), e3(), e4() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: member initializer for 'e1' is redundant
+ // CHECK-MESSAGES: :[[@LINE-2]]:34: warning: member initializer for 'e2' is redundant
+ // CHECK-MESSAGES: :[[@LINE-3]]:40: warning: member initializer for 'e3' is redundant
+ // CHECK-FIXES: ExistingPointer(short) : e4() {}
+ ExistingPointer(int) : e1(0), e2(0), e3(0), e4(&e1) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: member initializer for 'e1' is redundant
+ // CHECK-MESSAGES: :[[@LINE-2]]:33: warning: member initializer for 'e2' is redundant
+ // CHECK-MESSAGES: :[[@LINE-3]]:40: warning: member initializer for 'e3' is redundant
+ // CHECK-FIXES: ExistingPointer(int) : e4(&e1) {}
+ ExistingPointer(long) : e1(nullptr), e2(nullptr), e3(nullptr), e4(&e2) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: member initializer for 'e1' is redundant
+ // CHECK-MESSAGES: :[[@LINE-2]]:40: warning: member initializer for 'e2' is redundant
+ // CHECK-MESSAGES: :[[@LINE-3]]:53: warning: member initializer for 'e3' is redundant
+ // CHECK-FIXES: ExistingPointer(long) : e4(&e2) {}
+ int *e1{};
+ int *e2 = 0;
+ int *e3 = nullptr;
+ int **e4 = &e1;
+};
+
+struct ExistingString {
+ ExistingString(short) : e1(), e2(), e3(), e4() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: member initializer for 'e1' is redundant [modernize-use-default-member-init]
+ // CHECK-MESSAGES: :[[@LINE-2]]:33: warning: member initializer for 'e2' is redundant
+ // CHECK-FIXES: ExistingString(short) : e3(), e4() {}
+ ExistingString(int) : e1(0), e2(0), e3(0), e4(0) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: member initializer for 'e1' is redundant
+ // CHECK-MESSAGES: :[[@LINE-2]]:32: warning: member initializer for 'e2' is redundant
+ // CHECK-FIXES: ExistingString(int) : e3(0), e4(0) {}
+ ExistingString(long) : e1(nullptr), e2(nullptr), e3(nullptr), e4(nullptr) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: member initializer for 'e1' is redundant
+ // CHECK-MESSAGES: :[[@LINE-2]]:39: warning: member initializer for 'e2' is redundant
+ // CHECK-FIXES: ExistingString(long) : e3(nullptr), e4(nullptr) {}
+ ExistingString(char) : e1("foo"), e2("foo"), e3("foo"), e4("foo") {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:48: warning: member initializer for 'e3' is redundant
+ // CHECK-FIXES: ExistingString(char) : e1("foo"), e2("foo"), e4("foo") {}
+ const char *e1{};
+ const char *e2 = nullptr;
+ const char *e3 = "foo";
+ const char *e4 = "bar";
+};
+
+struct UnionExisting {
+ UnionExisting() : e(5.0) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: member initializer for 'e' is redundant
+ // CHECK-FIXES: UnionExisting() {}
+ union {
+ int i;
+ double e = 5.0;
+ };
+};
+
+template <typename T>
+struct NegativeTemplateExisting {
+ NegativeTemplateExisting(int) : t(0) {}
+ T t{};
+};
+
+NegativeTemplateExisting<int> ntei(0);
+NegativeTemplateExisting<double> nted(0);
+
+// This resulted in a warning by default.
+#define MACRO() \
+ struct MacroS { \
+ void *P; \
+ MacroS() : P(nullptr) {} \
+ };
+
+MACRO();
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-emplace-ignore-implicit-constructors.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-emplace-ignore-implicit-constructors.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-emplace-ignore-implicit-constructors.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-emplace-ignore-implicit-constructors.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,123 @@
+// RUN: %check_clang_tidy %s modernize-use-emplace %t -- \
+// RUN: -config="{CheckOptions: \
+// RUN: [{key: modernize-use-emplace.IgnoreImplicitConstructors, \
+// RUN: value: 1}] \
+// RUN: }"
+
+namespace std {
+template <typename>
+class initializer_list
+{
+public:
+ initializer_list() noexcept {}
+};
+
+template <typename T>
+class vector {
+public:
+ vector() = default;
+ vector(initializer_list<T>) {}
+
+ void push_back(const T &) {}
+ void push_back(T &&) {}
+
+ template <typename... Args>
+ void emplace_back(Args &&... args){};
+ ~vector();
+};
+
+} // namespace std
+
+void testInts() {
+ std::vector<int> v;
+ v.push_back(42);
+ v.push_back(int(42));
+ v.push_back(int{42});
+ v.push_back(42.0);
+ int z;
+ v.push_back(z);
+}
+
+struct Something {
+ Something(int a, int b = 41) {}
+ Something() {}
+ void push_back(Something);
+ int getInt() { return 42; }
+};
+
+struct Convertable {
+ operator Something() { return Something{}; }
+};
+
+struct Zoz {
+ Zoz(Something, int = 42) {}
+};
+
+Zoz getZoz(Something s) { return Zoz(s); }
+
+void test_Something() {
+ std::vector<Something> v;
+
+ v.push_back(Something(1, 2));
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back instead of push_back [modernize-use-emplace]
+ // CHECK-FIXES: v.emplace_back(1, 2);
+
+ v.push_back(Something{1, 2});
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back(1, 2);
+
+ v.push_back(Something());
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back();
+
+ v.push_back(Something{});
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back();
+
+ Something Different;
+ v.push_back(Something(Different.getInt(), 42));
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back(Different.getInt(), 42);
+
+ v.push_back(Different.getInt());
+ v.push_back(42);
+
+ Something temporary(42, 42);
+ temporary.push_back(temporary);
+ v.push_back(temporary);
+
+ v.push_back(Convertable());
+ v.push_back(Convertable{});
+ Convertable s;
+ v.push_back(s);
+}
+
+template <typename ElemType>
+void dependOnElem() {
+ std::vector<ElemType> v;
+ v.push_back(ElemType(42));
+}
+
+template <typename ContainerType>
+void dependOnContainer() {
+ ContainerType v;
+ v.push_back(Something(42));
+}
+
+void callDependent() {
+ dependOnElem<Something>();
+ dependOnContainer<std::vector<Something>>();
+}
+
+void test2() {
+ std::vector<Zoz> v;
+ v.push_back(Zoz(Something(21, 37)));
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back(Something(21, 37));
+
+ v.push_back(Zoz(Something(21, 37), 42));
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back(Something(21, 37), 42);
+
+ v.push_back(getZoz(Something(1, 2)));
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-emplace.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-emplace.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-emplace.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-emplace.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,607 @@
+// RUN: %check_clang_tidy %s modernize-use-emplace %t -- \
+// RUN: -config="{CheckOptions: \
+// RUN: [{key: modernize-use-emplace.ContainersWithPushBack, \
+// RUN: value: '::std::vector; ::std::list; ::std::deque; llvm::LikeASmallVector'}, \
+// RUN: {key: modernize-use-emplace.TupleTypes, \
+// RUN: value: '::std::pair; std::tuple; ::test::Single'}, \
+// RUN: {key: modernize-use-emplace.TupleMakeFunctions, \
+// RUN: value: '::std::make_pair; ::std::make_tuple; ::test::MakeSingle'}] \
+// RUN: }"
+
+namespace std {
+template <typename>
+class initializer_list
+{
+public:
+ initializer_list() noexcept {}
+};
+
+template <typename T>
+class vector {
+public:
+ vector() = default;
+ vector(initializer_list<T>) {}
+
+ void push_back(const T &) {}
+ void push_back(T &&) {}
+
+ template <typename... Args>
+ void emplace_back(Args &&... args){};
+ ~vector();
+};
+template <typename T>
+class list {
+public:
+ void push_back(const T &) {}
+ void push_back(T &&) {}
+
+ template <typename... Args>
+ void emplace_back(Args &&... args){};
+ ~list();
+};
+
+template <typename T>
+class deque {
+public:
+ void push_back(const T &) {}
+ void push_back(T &&) {}
+
+ template <typename... Args>
+ void emplace_back(Args &&... args){};
+ ~deque();
+};
+
+template <typename T> struct remove_reference { using type = T; };
+template <typename T> struct remove_reference<T &> { using type = T; };
+template <typename T> struct remove_reference<T &&> { using type = T; };
+
+template <typename T1, typename T2> class pair {
+public:
+ pair() = default;
+ pair(const pair &) = default;
+ pair(pair &&) = default;
+
+ pair(const T1 &, const T2 &) {}
+ pair(T1 &&, T2 &&) {}
+
+ template <typename U1, typename U2> pair(const pair<U1, U2> &){};
+ template <typename U1, typename U2> pair(pair<U1, U2> &&){};
+};
+
+template <typename T1, typename T2>
+pair<typename remove_reference<T1>::type, typename remove_reference<T2>::type>
+make_pair(T1 &&, T2 &&) {
+ return {};
+};
+
+template <typename... Ts> class tuple {
+public:
+ tuple() = default;
+ tuple(const tuple &) = default;
+ tuple(tuple &&) = default;
+
+ tuple(const Ts &...) {}
+ tuple(Ts &&...) {}
+
+ template <typename... Us> tuple(const tuple<Us...> &){};
+ template <typename... Us> tuple(tuple<Us...> &&) {}
+
+ template <typename U1, typename U2> tuple(const pair<U1, U2> &) {
+ static_assert(sizeof...(Ts) == 2, "Wrong tuple size");
+ };
+ template <typename U1, typename U2> tuple(pair<U1, U2> &&) {
+ static_assert(sizeof...(Ts) == 2, "Wrong tuple size");
+ };
+};
+
+template <typename... Ts>
+tuple<typename remove_reference<Ts>::type...> make_tuple(Ts &&...) {
+ return {};
+}
+
+template <typename T>
+class unique_ptr {
+public:
+ explicit unique_ptr(T *) {}
+ ~unique_ptr();
+};
+} // namespace std
+
+namespace llvm {
+template <typename T>
+class LikeASmallVector {
+public:
+ void push_back(const T &) {}
+ void push_back(T &&) {}
+
+ template <typename... Args>
+ void emplace_back(Args &&... args){};
+};
+
+} // llvm
+
+void testInts() {
+ std::vector<int> v;
+ v.push_back(42);
+ v.push_back(int(42));
+ v.push_back(int{42});
+ v.push_back(42.0);
+ int z;
+ v.push_back(z);
+}
+
+struct Something {
+ Something(int a, int b = 41) {}
+ Something() {}
+ void push_back(Something);
+ int getInt() { return 42; }
+};
+
+struct Convertable {
+ operator Something() { return Something{}; }
+};
+
+struct Zoz {
+ Zoz(Something, int = 42) {}
+};
+
+Zoz getZoz(Something s) { return Zoz(s); }
+
+void test_Something() {
+ std::vector<Something> v;
+
+ v.push_back(Something(1, 2));
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back instead of push_back [modernize-use-emplace]
+ // CHECK-FIXES: v.emplace_back(1, 2);
+
+ v.push_back(Something{1, 2});
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back(1, 2);
+
+ v.push_back(Something());
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back();
+
+ v.push_back(Something{});
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back();
+
+ Something Different;
+ v.push_back(Something(Different.getInt(), 42));
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back(Different.getInt(), 42);
+
+ v.push_back(Different.getInt());
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back(Different.getInt());
+
+ v.push_back(42);
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back(42);
+
+ Something temporary(42, 42);
+ temporary.push_back(temporary);
+ v.push_back(temporary);
+
+ v.push_back(Convertable());
+ v.push_back(Convertable{});
+ Convertable s;
+ v.push_back(s);
+}
+
+template <typename ElemType>
+void dependOnElem() {
+ std::vector<ElemType> v;
+ v.push_back(ElemType(42));
+}
+
+template <typename ContainerType>
+void dependOnContainer() {
+ ContainerType v;
+ v.push_back(Something(42));
+}
+
+void callDependent() {
+ dependOnElem<Something>();
+ dependOnContainer<std::vector<Something>>();
+}
+
+void test2() {
+ std::vector<Zoz> v;
+ v.push_back(Zoz(Something(21, 37)));
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back(Something(21, 37));
+
+ v.push_back(Zoz(Something(21, 37), 42));
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back(Something(21, 37), 42);
+
+ v.push_back(getZoz(Something(1, 2)));
+}
+
+struct GetPair {
+ std::pair<int, long> getPair();
+};
+void testPair() {
+ std::vector<std::pair<int, int>> v;
+ v.push_back(std::pair<int, int>(1, 2));
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back(1, 2);
+
+ GetPair g;
+ v.push_back(g.getPair());
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back(g.getPair());
+
+ std::vector<std::pair<Something, Zoz>> v2;
+ v2.push_back(std::pair<Something, Zoz>(Something(42, 42), Zoz(Something(21, 37))));
+ // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_back
+ // CHECK-FIXES: v2.emplace_back(Something(42, 42), Zoz(Something(21, 37)));
+}
+
+void testTuple() {
+ std::vector<std::tuple<bool, char, int>> v;
+ v.push_back(std::tuple<bool, char, int>(false, 'x', 1));
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back(false, 'x', 1);
+
+ v.push_back(std::tuple<bool, char, int>{false, 'y', 2});
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back(false, 'y', 2);
+
+ v.push_back({true, 'z', 3});
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back(true, 'z', 3);
+
+ std::vector<std::tuple<int, bool>> x;
+ x.push_back(std::make_pair(1, false));
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: x.emplace_back(1, false);
+
+ x.push_back(std::make_pair(2LL, 1));
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: x.emplace_back(2LL, 1);
+}
+
+struct Base {
+ Base(int, int *, int = 42);
+};
+
+struct Derived : Base {
+ Derived(int *, Something) : Base(42, nullptr) {}
+};
+
+void testDerived() {
+ std::vector<Base> v;
+ v.push_back(Derived(nullptr, Something{}));
+}
+
+void testNewExpr() {
+ std::vector<Derived> v;
+ v.push_back(Derived(new int, Something{}));
+}
+
+void testSpaces() {
+ std::vector<Something> v;
+
+ // clang-format off
+
+ v.push_back(Something(1, //arg1
+ 2 // arg2
+ ) // Something
+ );
+ // CHECK-MESSAGES: :[[@LINE-4]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back(1, //arg1
+ // CHECK-FIXES: 2 // arg2
+ // CHECK-FIXES: // Something
+ // CHECK-FIXES: );
+
+ v.push_back( Something (1, 2) );
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back(1, 2 );
+
+ v.push_back( Something {1, 2} );
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back(1, 2 );
+
+ v.push_back( Something {} );
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back( );
+
+ v.push_back(
+ Something(1, 2) );
+ // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back(1, 2 );
+
+ std::vector<Base> v2;
+ v2.push_back(
+ Base(42, nullptr));
+ // CHECK-MESSAGES: :[[@LINE-2]]:6: warning: use emplace_back
+ // CHECK-FIXES: v2.emplace_back(42, nullptr);
+
+ // clang-format on
+}
+
+void testPointers() {
+ std::vector<int *> v;
+ v.push_back(new int(5));
+
+ std::vector<std::unique_ptr<int>> v2;
+ v2.push_back(std::unique_ptr<int>(new int(42)));
+ // This call can't be replaced with emplace_back.
+ // If emplacement will fail (not enough memory to add to vector)
+ // we will have leak of int because unique_ptr won't be constructed
+ // (and destructed) as in push_back case.
+
+ auto *ptr = new int;
+ v2.push_back(std::unique_ptr<int>(ptr));
+ // Same here
+}
+
+void testMakePair() {
+ std::vector<std::pair<int, int>> v;
+ v.push_back(std::make_pair(1, 2));
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back(1, 2);
+
+ v.push_back(std::make_pair(42LL, 13));
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back(42LL, 13);
+
+ v.push_back(std::make_pair<char, char>(0, 3));
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back(std::make_pair<char, char>(0, 3));
+ //
+ // Even though the call above could be turned into v.emplace_back(0, 3),
+ // we don't eliminate the make_pair call here, because of the explicit
+ // template parameters provided. make_pair's arguments can be convertible
+ // to its explicitly provided template parameter, but not to the pair's
+ // element type. The examples below illustrate the problem.
+ struct D {
+ D(...) {}
+ operator char() const { return 0; }
+ };
+ v.push_back(std::make_pair<D, int>(Something(), 2));
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back(std::make_pair<D, int>(Something(), 2));
+
+ struct X {
+ X(std::pair<int, int>) {}
+ };
+ std::vector<X> x;
+ x.push_back(std::make_pair(1, 2));
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: x.emplace_back(std::make_pair(1, 2));
+ // make_pair cannot be removed here, as X is not constructible with two ints.
+
+ struct Y {
+ Y(std::pair<int, int>&&) {}
+ };
+ std::vector<Y> y;
+ y.push_back(std::make_pair(2, 3));
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: y.emplace_back(std::make_pair(2, 3));
+ // make_pair cannot be removed here, as Y is not constructible with two ints.
+}
+
+void testMakeTuple() {
+ std::vector<std::tuple<int, bool, char>> v;
+ v.push_back(std::make_tuple(1, true, 'v'));
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back(1, true, 'v');
+
+ v.push_back(std::make_tuple(2ULL, 1, 0));
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back(2ULL, 1, 0);
+
+ v.push_back(std::make_tuple<long long, int, int>(3LL, 1, 0));
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back(std::make_tuple<long long, int, int>(3LL, 1, 0));
+ // make_tuple is not removed when there are explicit template
+ // arguments provided.
+}
+
+namespace test {
+template <typename T> struct Single {
+ Single() = default;
+ Single(const Single &) = default;
+ Single(Single &&) = default;
+
+ Single(const T &) {}
+ Single(T &&) {}
+
+ template <typename U> Single(const Single<U> &) {}
+ template <typename U> Single(Single<U> &&) {}
+
+ template <typename U> Single(const std::tuple<U> &) {}
+ template <typename U> Single(std::tuple<U> &&) {}
+};
+
+template <typename T>
+Single<typename std::remove_reference<T>::type> MakeSingle(T &&) {
+ return {};
+}
+} // namespace test
+
+void testOtherTuples() {
+ std::vector<test::Single<int>> v;
+ v.push_back(test::Single<int>(1));
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back(1);
+
+ v.push_back({2});
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back(2);
+
+ v.push_back(test::MakeSingle(3));
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back(3);
+
+ v.push_back(test::MakeSingle<long long>(4));
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back(test::MakeSingle<long long>(4));
+ // We don't remove make functions with explicit template parameters.
+
+ v.push_back(test::MakeSingle(5LL));
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back(5LL);
+
+ v.push_back(std::make_tuple(6));
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back(6);
+
+ v.push_back(std::make_tuple(7LL));
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back(7LL);
+}
+
+void testOtherContainers() {
+ std::list<Something> l;
+ l.push_back(Something(42, 41));
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: l.emplace_back(42, 41);
+
+ std::deque<Something> d;
+ d.push_back(Something(42));
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: d.emplace_back(42);
+
+ llvm::LikeASmallVector<Something> ls;
+ ls.push_back(Something(42));
+ // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_back
+ // CHECK-FIXES: ls.emplace_back(42);
+}
+
+class IntWrapper {
+public:
+ IntWrapper(int x) : value(x) {}
+ IntWrapper operator+(const IntWrapper other) const {
+ return IntWrapper(value + other.value);
+ }
+
+private:
+ int value;
+};
+
+void testMultipleOpsInPushBack() {
+ std::vector<IntWrapper> v;
+ v.push_back(IntWrapper(42) + IntWrapper(27));
+}
+
+// Macro tests.
+#define PUSH_BACK_WHOLE(c, x) c.push_back(x)
+#define PUSH_BACK_NAME push_back
+#define PUSH_BACK_ARG(x) (x)
+#define SOME_OBJ Something(10)
+#define MILLION 3
+#define SOME_WEIRD_PUSH(v) v.push_back(Something(
+#define OPEN (
+#define CLOSE )
+void macroTest() {
+ std::vector<Something> v;
+ Something s;
+
+ PUSH_BACK_WHOLE(v, Something(5, 6));
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use emplace_back
+
+ v.PUSH_BACK_NAME(Something(5));
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+
+ v.push_back PUSH_BACK_ARG(Something(5, 6));
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+
+ v.push_back(SOME_OBJ);
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+
+ v.push_back(Something(MILLION));
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back(MILLION);
+
+ // clang-format off
+ v.push_back( Something OPEN 3 CLOSE );
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // clang-format on
+ PUSH_BACK_WHOLE(s, Something(1));
+}
+
+struct A {
+ int value1, value2;
+};
+
+struct B {
+ B(A) {}
+};
+
+struct C {
+ int value1, value2, value3;
+};
+
+void testAggregation() {
+ // This should not be noticed or fixed; after the correction, the code won't
+ // compile.
+
+ std::vector<A> v;
+ v.push_back(A({1, 2}));
+
+ std::vector<B> vb;
+ vb.push_back(B({10, 42}));
+}
+
+struct Bitfield {
+ unsigned bitfield : 1;
+ unsigned notBitfield;
+};
+
+void testBitfields() {
+ std::vector<Something> v;
+ Bitfield b;
+ v.push_back(Something(42, b.bitfield));
+ v.push_back(Something(b.bitfield));
+
+ v.push_back(Something(42, b.notBitfield));
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back(42, b.notBitfield);
+ int var;
+ v.push_back(Something(42, var));
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back(42, var);
+}
+
+class PrivateCtor {
+ PrivateCtor(int z);
+
+public:
+ void doStuff() {
+ std::vector<PrivateCtor> v;
+ // This should not change it because emplace back doesn't have permission.
+ // Check currently doesn't support friend declarations because pretty much
+ // nobody would want to be friend with std::vector :(.
+ v.push_back(PrivateCtor(42));
+ }
+};
+
+struct WithDtor {
+ WithDtor(int) {}
+ ~WithDtor();
+};
+
+void testWithDtor() {
+ std::vector<WithDtor> v;
+
+ v.push_back(WithDtor(42));
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+ // CHECK-FIXES: v.emplace_back(42);
+}
+
+void testInitializerList() {
+ std::vector<std::vector<int>> v;
+ v.push_back(std::vector<int>({1}));
+ // Test against the bug reported in PR32896.
+
+ v.push_back({{2}});
+
+ using PairIntVector = std::pair<int, std::vector<int>>;
+ std::vector<PairIntVector> x;
+ x.push_back(PairIntVector(3, {4}));
+ x.push_back({5, {6}});
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-equals-default-copy.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-equals-default-copy.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-equals-default-copy.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-equals-default-copy.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,507 @@
+// RUN: %check_clang_tidy %s modernize-use-equals-default %t -- \
+// RUN: -config="{CheckOptions: [{key: modernize-use-equals-default.IgnoreMacros, value: 0}]}" \
+// RUN: -- -fno-delayed-template-parsing -fexceptions
+
+// Out of line definition.
+struct OL {
+ OL(const OL &);
+ OL &operator=(const OL &);
+ int Field;
+};
+OL::OL(const OL &Other) : Field(Other.Field) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use '= default' to define a trivial copy constructor [modernize-use-equals-default]
+// CHECK-FIXES: OL::OL(const OL &Other) = default;
+OL &OL::operator=(const OL &Other) {
+ Field = Other.Field;
+ return *this;
+}
+// CHECK-MESSAGES: :[[@LINE-4]]:9: warning: use '= default' to define a trivial copy-assignment operator [modernize-use-equals-default]
+// CHECK-FIXES: OL &OL::operator=(const OL &Other) = default;
+
+// Inline.
+struct IL {
+ IL(const IL &Other) : Field(Other.Field) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+ // CHECK-FIXES: IL(const IL &Other) = default;
+ IL &operator=(const IL &Other) {
+ Field = Other.Field;
+ return *this;
+ }
+ // CHECK-MESSAGES: :[[@LINE-4]]:7: warning: use '= default'
+ // CHECK-FIXES: IL &operator=(const IL &Other) = default;
+ int Field;
+};
+
+// Wrong type.
+struct WT {
+ WT(const IL &Other) {}
+ WT &operator=(const IL &);
+};
+WT &WT::operator=(const IL &Other) { return *this; }
+
+// Qualifiers.
+struct Qual {
+ Qual(const Qual &Other) : Field(Other.Field), Volatile(Other.Volatile),
+ Mutable(Other.Mutable), Reference(Other.Reference),
+ Const(Other.Const) {}
+ // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use '= default'
+ // CHECK-FIXES: Qual(const Qual &Other)
+ // CHECK-FIXES: = default;
+
+ int Field;
+ volatile char Volatile;
+ mutable bool Mutable;
+ const OL &Reference; // This makes this class non-assignable.
+ const IL Const; // This also makes this class non-assignable.
+ static int Static;
+};
+
+// Wrong init arguments.
+struct WI {
+ WI(const WI &Other) : Field1(Other.Field1), Field2(Other.Field1) {}
+ WI &operator=(const WI &);
+ int Field1, Field2;
+};
+WI &WI::operator=(const WI &Other) {
+ Field1 = Other.Field1;
+ Field2 = Other.Field1;
+ return *this;
+}
+
+// Missing field.
+struct MF {
+ MF(const MF &Other) : Field1(Other.Field1), Field2(Other.Field2) {}
+ MF &operator=(const MF &);
+ int Field1, Field2, Field3;
+};
+MF &MF::operator=(const MF &Other) {
+ Field1 = Other.Field1;
+ Field2 = Other.Field2;
+ return *this;
+}
+
+struct Comments {
+ Comments(const Comments &Other)
+ /* don't delete */ : /* this comment */ Field(Other.Field) {}
+ // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use '= default'
+ // CHECK-FIXES: /* don't delete */ = default;
+ int Field;
+};
+
+struct MoreComments {
+ MoreComments(const MoreComments &Other) /* this comment is OK */
+ : Field(Other.Field) {}
+ // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use '= default'
+ // CHECK-FIXES: MoreComments(const MoreComments &Other) /* this comment is OK */
+ // CHECK-FIXES-NEXT: = default;
+ int Field;
+};
+
+struct ColonInComment {
+ ColonInComment(const ColonInComment &Other) /* : */ : Field(Other.Field) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+ // CHECK-FIXES: ColonInComment(const ColonInComment &Other) /* : */ = default;
+ int Field;
+};
+
+// No members or bases (in particular, no colon).
+struct Empty {
+ Empty(const Empty &Other) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+ // CHECK-FIXES: Empty(const Empty &Other) = default;
+ Empty &operator=(const Empty &);
+};
+Empty &Empty::operator=(const Empty &Other) { return *this; }
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: use '= default'
+// CHECK-FIXES: Empty &Empty::operator=(const Empty &Other) = default;
+
+// Bit fields.
+struct BF {
+ BF() = default;
+ BF(const BF &Other) : Field1(Other.Field1), Field2(Other.Field2), Field3(Other.Field3),
+ Field4(Other.Field4) {}
+ // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use '= default'
+ // CHECK-FIXES: BF(const BF &Other) {{$}}
+ // CHECK-FIXES: = default;
+ BF &operator=(const BF &);
+
+ unsigned Field1 : 3;
+ int : 7;
+ char Field2 : 6;
+ int : 0;
+ int Field3 : 24;
+ unsigned char Field4;
+};
+BF &BF::operator=(const BF &Other) {
+ Field1 = Other.Field1;
+ Field2 = Other.Field2;
+ Field3 = Other.Field3;
+ Field4 = Other.Field4;
+ return *this;
+}
+// CHECK-MESSAGES: :[[@LINE-7]]:9: warning: use '= default'
+// CHECK-FIXES: BF &BF::operator=(const BF &Other) = default;
+
+// Base classes.
+struct BC : IL, OL, BF {
+ BC(const BC &Other) : IL(Other), OL(Other), BF(Other) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+ // CHECK-FIXES: BC(const BC &Other) = default;
+ BC &operator=(const BC &Other);
+};
+BC &BC::operator=(const BC &Other) {
+ IL::operator=(Other);
+ OL::operator=(Other);
+ BF::operator=(Other);
+ return *this;
+}
+// CHECK-MESSAGES: :[[@LINE-6]]:9: warning: use '= default'
+// CHECK-FIXES: BC &BC::operator=(const BC &Other) = default;
+
+// Base classes with member.
+struct BCWM : IL, OL {
+ BCWM(const BCWM &Other) : IL(Other), OL(Other), Bf(Other.Bf) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+ // CHECK-FIXES: BCWM(const BCWM &Other) = default;
+ BCWM &operator=(const BCWM &);
+ BF Bf;
+};
+BCWM &BCWM::operator=(const BCWM &Other) {
+ IL::operator=(Other);
+ OL::operator=(Other);
+ Bf = Other.Bf;
+ return *this;
+}
+// CHECK-MESSAGES: :[[@LINE-6]]:13: warning: use '= default'
+// CHECK-FIXES: BCWM &BCWM::operator=(const BCWM &Other) = default;
+
+// Missing base class.
+struct MBC : IL, OL, BF {
+ MBC(const MBC &Other) : IL(Other), OL(Other) {}
+ MBC &operator=(const MBC &);
+};
+MBC &MBC::operator=(const MBC &Other) {
+ IL::operator=(Other);
+ OL::operator=(Other);
+ return *this;
+}
+
+// Base classes, incorrect parameter.
+struct BCIP : BCWM, BF {
+ BCIP(const BCIP &Other) : BCWM(Other), BF(Other.Bf) {}
+ BCIP &operator=(const BCIP &);
+};
+BCIP &BCIP::operator=(const BCIP &Other) {
+ BCWM::operator=(Other);
+ BF::operator=(Other.Bf);
+ return *this;
+}
+
+// Virtual base classes.
+struct VA : virtual OL {};
+struct VB : virtual OL {};
+struct VBC : VA, VB, virtual OL {
+ // OL is the first thing that is going to be initialized, despite the fact
+ // that it is the last in the list of bases, because it is virtual and there
+ // is a virtual OL at the beginning of VA (which is the same).
+ VBC(const VBC &Other) : OL(Other), VA(Other), VB(Other) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+ // CHECK-FIXES: VBC(const VBC &Other) = default;
+ VBC &operator=(const VBC &Other);
+};
+VBC &VBC::operator=(const VBC &Other) {
+ OL::operator=(Other);
+ VA::operator=(Other);
+ VB::operator=(Other);
+ return *this;
+}
+// CHECK-MESSAGES: :[[@LINE-6]]:11: warning: use '= default'
+// CHECK-FIXES: VBC &VBC::operator=(const VBC &Other) = default;
+
+// Indirect base.
+struct IB : VBC {
+ IB(const IB &Other) : OL(Other), VBC(Other) {}
+ IB &operator=(const IB &);
+};
+IB &IB::operator=(const IB &Other) {
+ OL::operator=(Other);
+ VBC::operator=(Other);
+ return *this;
+}
+
+// Class template.
+template <class T>
+struct Template {
+ Template() = default;
+ Template(const Template &Other) : Field(Other.Field) {}
+ Template &operator=(const Template &Other);
+ void foo(const T &t);
+ int Field;
+};
+template <class T>
+Template<T> &Template<T>::operator=(const Template<T> &Other) {
+ Field = Other.Field;
+ return *this;
+}
+Template<int> T1;
+
+// Dependent types.
+template <class T>
+struct DT1 {
+ DT1() = default;
+ DT1(const DT1 &Other) : Field(Other.Field) {}
+ DT1 &operator=(const DT1 &);
+ T Field;
+};
+template <class T>
+DT1<T> &DT1<T>::operator=(const DT1<T> &Other) {
+ Field = Other.Field;
+ return *this;
+}
+DT1<int> Dt1;
+
+template <class T>
+struct DT2 {
+ DT2() = default;
+ DT2(const DT2 &Other) : Field(Other.Field), Dependent(Other.Dependent) {}
+ DT2 &operator=(const DT2 &);
+ T Field;
+ typename T::TT Dependent;
+};
+template <class T>
+DT2<T> &DT2<T>::operator=(const DT2<T> &Other) {
+ Field = Other.Field;
+ Dependent = Other.Dependent;
+ return *this;
+}
+struct T {
+ typedef int TT;
+};
+DT2<T> Dt2;
+
+// Default arguments.
+struct DA {
+ DA(int Int);
+ DA(const DA &Other = DA(0)) : Field1(Other.Field1), Field2(Other.Field2) {}
+ DA &operator=(const DA &);
+ int Field1;
+ char Field2;
+};
+// Overloaded operator= cannot have a default argument.
+DA &DA::operator=(const DA &Other) {
+ Field1 = Other.Field1;
+ Field2 = Other.Field2;
+ return *this;
+}
+// CHECK-MESSAGES: :[[@LINE-5]]:9: warning: use '= default'
+// CHECK-FIXES: DA &DA::operator=(const DA &Other) = default;
+
+struct DA2 {
+ // Can be used as copy-constructor but cannot be explicitly defaulted.
+ DA2(const DA &Other, int Def = 0) {}
+};
+
+// Default initialization.
+struct DI {
+ DI(const DI &Other) : Field1(Other.Field1), Field2(Other.Field2) {}
+ int Field1;
+ int Field2 = 0;
+ int Fiedl3;
+};
+
+// Statement inside body.
+void foo();
+struct SIB {
+ SIB(const SIB &Other) : Field(Other.Field) { foo(); }
+ SIB &operator=(const SIB &);
+ int Field;
+};
+SIB &SIB::operator=(const SIB &Other) {
+ Field = Other.Field;
+ foo();
+ return *this;
+}
+
+// Comment inside body.
+struct CIB {
+ CIB(const CIB &Other) : Field(Other.Field) { /* Don't erase this */
+ }
+ // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use '= default'
+ CIB &operator=(const CIB &);
+ int Field;
+};
+CIB &CIB::operator=(const CIB &Other) {
+ Field = Other.Field;
+ // FIXME: don't erase this comment.
+ return *this;
+}
+// CHECK-MESSAGES: :[[@LINE-5]]:11: warning: use '= default'
+// CHECK-FIXES: CIB &CIB::operator=(const CIB &Other) = default;
+
+// Take non-const reference as argument.
+struct NCRef {
+ NCRef(NCRef &Other) : Field1(Other.Field1), Field2(Other.Field2) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+ // CHECK-FIXES: NCRef(NCRef &Other) = default;
+ NCRef &operator=(NCRef &);
+ int Field1, Field2;
+};
+NCRef &NCRef::operator=(NCRef &Other) {
+ Field1 = Other.Field1;
+ Field2 = Other.Field2;
+ return *this;
+}
+// CHECK-MESSAGES: :[[@LINE-5]]:15: warning: use '= default'
+// CHECK-FIXES: NCRef &NCRef::operator=(NCRef &Other) = default;
+
+// Already defaulted.
+struct IAD {
+ IAD(const IAD &Other) = default;
+ IAD &operator=(const IAD &Other) = default;
+};
+
+struct OAD {
+ OAD(const OAD &Other);
+ OAD &operator=(const OAD &);
+};
+OAD::OAD(const OAD &Other) = default;
+OAD &OAD::operator=(const OAD &Other) = default;
+
+// Deleted.
+struct ID {
+ ID(const ID &Other) = delete;
+ ID &operator=(const ID &Other) = delete;
+};
+
+// Non-reference parameter.
+struct NRef {
+ NRef &operator=(NRef Other);
+ int Field1;
+};
+NRef &NRef::operator=(NRef Other) {
+ Field1 = Other.Field1;
+ return *this;
+}
+
+// RValue reference parameter.
+struct RVR {
+ RVR(RVR &&Other) {}
+ RVR &operator=(RVR &&);
+};
+RVR &RVR::operator=(RVR &&Other) { return *this; }
+
+// Similar function.
+struct SF {
+ SF &foo(const SF &);
+ int Field1;
+};
+SF &SF::foo(const SF &Other) {
+ Field1 = Other.Field1;
+ return *this;
+}
+
+// No return.
+struct NR {
+ NR &operator=(const NR &);
+};
+NR &NR::operator=(const NR &Other) {}
+
+// Return misplaced.
+struct RM {
+ RM &operator=(const RM &);
+ int Field;
+};
+RM &RM::operator=(const RM &Other) {
+ return *this;
+ Field = Other.Field;
+}
+
+// Wrong return value.
+struct WRV {
+ WRV &operator=(WRV &);
+};
+WRV &WRV::operator=(WRV &Other) {
+ return Other;
+}
+
+// Wrong return type.
+struct WRT : IL {
+ IL &operator=(const WRT &);
+};
+IL &WRT::operator=(const WRT &Other) {
+ return *this;
+}
+
+// Try-catch.
+struct ITC {
+ ITC(const ITC &Other)
+ try : Field(Other.Field) {
+ } catch (...) {
+ }
+ ITC &operator=(const ITC &Other) try {
+ Field = Other.Field;
+ } catch (...) {
+ }
+ int Field;
+};
+
+struct OTC {
+ OTC(const OTC &);
+ OTC &operator=(const OTC &);
+ int Field;
+};
+OTC::OTC(const OTC &Other) try : Field(Other.Field) {
+} catch (...) {
+}
+OTC &OTC::operator=(const OTC &Other) try {
+ Field = Other.Field;
+} catch (...) {
+}
+
+// FIXME: the check is not able to detect exception specification.
+// noexcept(true).
+struct NET {
+ // This is the default.
+ //NET(const NET &Other) noexcept {}
+ NET &operator=(const NET &Other) noexcept;
+};
+//NET &NET::operator=(const NET &Other) noexcept { return *this; }
+
+// noexcept(false).
+struct NEF {
+ // This is the default.
+ //NEF(const NEF &Other) noexcept(false) {}
+ NEF &operator=(const NEF &Other) noexcept(false);
+};
+//NEF &NEF::operator=(const NEF &Other) noexcept(false) { return *this; }
+
+#define STRUCT_WITH_COPY_CONSTRUCT(_base, _type) \
+ struct _type { \
+ _type(const _type &v) : value(v.value) {} \
+ _base value; \
+ };
+
+STRUCT_WITH_COPY_CONSTRUCT(unsigned char, Hex8CopyConstruct)
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use '= default' to define a trivial copy constructor
+// CHECK-MESSAGES: :[[@LINE-6]]:44: note:
+
+#define STRUCT_WITH_COPY_ASSIGN(_base, _type) \
+ struct _type { \
+ _type &operator=(const _type &rhs) { \
+ value = rhs.value; \
+ return *this; \
+ } \
+ _base value; \
+ };
+
+STRUCT_WITH_COPY_ASSIGN(unsigned char, Hex8CopyAssign)
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use '= default' to define a trivial copy-assignment operator
+// CHECK-MESSAGES: :[[@LINE-9]]:40: note:
+
+// Use of braces
+struct UOB{
+ UOB(const UOB &Other):j{Other.j}{}
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default' to define a trivial copy constructor [modernize-use-equals-default]
+ // CHECK-FIXES: UOB(const UOB &Other)= default;
+ int j;
+};
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-equals-default-delayed.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-equals-default-delayed.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-equals-default-delayed.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-equals-default-delayed.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,9 @@
+// RUN: clang-tidy %s -checks=-*,modernize-use-equals-default -- -std=c++11 -fdelayed-template-parsing -fexceptions | count 0
+// Note: this test expects no diagnostics, but FileCheck cannot handle that,
+// hence the use of | count 0.
+// FIXME: Make the test work in all language modes.
+
+template <typename Ty>
+struct S {
+ S<Ty>& operator=(const S<Ty>&) { return *this; }
+};
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-equals-default-macros.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-equals-default-macros.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-equals-default-macros.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-equals-default-macros.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,12 @@
+// RUN: %check_clang_tidy %s modernize-use-equals-default %t -- \
+// RUN: -config="{CheckOptions: [{key: modernize-use-equals-default.IgnoreMacros, value: 0}]}"
+
+#define STRUCT_WITH_DEFAULT(_base, _type) \
+ struct _type { \
+ _type() {} \
+ _base value; \
+ };
+
+STRUCT_WITH_DEFAULT(unsigned char, InMacro)
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use '= default' to define a trivial default constructor
+// CHECK-MESSAGES: :[[@LINE-6]]:13: note:
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-equals-default.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-equals-default.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-equals-default.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-equals-default.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,207 @@
+// RUN: %check_clang_tidy %s modernize-use-equals-default %t -- -- -fno-delayed-template-parsing -fexceptions
+
+// Out of line definition.
+class OL {
+public:
+ OL();
+ ~OL();
+};
+
+OL::OL() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use '= default' to define a trivial default constructor [modernize-use-equals-default]
+// CHECK-FIXES: OL::OL() = default;
+OL::~OL() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use '= default' to define a trivial destructor [modernize-use-equals-default]
+// CHECK-FIXES: OL::~OL() = default;
+
+// Inline definitions.
+class IL {
+public:
+ IL() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+ // CHECK-FIXES: IL() = default;
+ ~IL() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+ // CHECK-FIXES: ~IL() = default;
+};
+
+// Non-empty body.
+void f();
+class NE {
+public:
+ NE() { f(); }
+ ~NE() { f(); }
+};
+
+// Initializer or arguments.
+class IA {
+public:
+ // Constructor with initializer.
+ IA() : Field(5) {}
+ // Constructor with arguments.
+ IA(int Arg1, int Arg2) {}
+ int Field;
+};
+
+// Default member initializer
+class DMI {
+public:
+ DMI() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+ // CHECK-FIXES: DMI() = default;
+ int Field = 5;
+};
+
+// Class member
+class CM {
+public:
+ CM() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+ // CHECK-FIXES: CM() = default;
+ OL o;
+};
+
+// Private constructor/destructor.
+class Priv {
+ Priv() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+ // CHECK-FIXES: Priv() = default;
+ ~Priv() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+ // CHECK-FIXES: ~Priv() = default;
+};
+
+// struct.
+struct ST {
+ ST() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+ // CHECK-FIXES: ST() = default;
+ ~ST() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+ // CHECK-FIXES: ST() = default;
+};
+
+// Deleted constructor/destructor.
+class Del {
+public:
+ Del() = delete;
+ ~Del() = delete;
+};
+
+// Do not remove other keywords.
+class KW {
+public:
+ explicit KW() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use '= default'
+ // CHECK-FIXES: explicit KW() = default;
+ virtual ~KW() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: use '= default'
+ // CHECK-FIXES: virtual ~KW() = default;
+};
+
+// Nested class.
+struct N {
+ struct NN {
+ NN() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use '= default'
+ // CHECK-FIXES: NN() = default;
+ ~NN() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use '= default'
+ // CHECK-FIXES: ~NN() = default;
+ };
+ int Int;
+};
+
+// Class template.
+template <class T>
+class Temp {
+public:
+ Temp() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+ // CHECK-FIXES: Temp() = default;
+ ~Temp() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+ // CHECK-FIXES: ~Temp() = default;
+};
+
+// Class template out of line with explicit instantiation.
+template <class T>
+class TempODef {
+public:
+ TempODef();
+ ~TempODef();
+};
+
+template <class T>
+TempODef<T>::TempODef() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: use '= default'
+// CHECK-FIXES: TempODef<T>::TempODef() = default;
+template <class T>
+TempODef<T>::~TempODef() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: use '= default'
+// CHECK-FIXES: TempODef<T>::~TempODef() = default;
+
+template class TempODef<int>;
+template class TempODef<double>;
+
+// Non user-provided constructor/destructor.
+struct Imp {
+ int Int;
+};
+void g() {
+ Imp *PtrImp = new Imp();
+ PtrImp->~Imp();
+ delete PtrImp;
+}
+
+// Already using default.
+struct IDef {
+ IDef() = default;
+ ~IDef() = default;
+};
+struct ODef {
+ ODef();
+ ~ODef();
+};
+ODef::ODef() = default;
+ODef::~ODef() = default;
+
+// Delegating constructor and overriden destructor.
+struct DC : KW {
+ DC() : KW() {}
+ ~DC() override {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+ // CHECK-FIXES: ~DC() override = default;
+};
+
+struct Comments {
+ Comments() {
+ // Don't erase comments inside the body.
+ }
+ // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use '= default'
+ ~Comments() {
+ // Don't erase comments inside the body.
+ }
+ // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use '= default'
+};
+
+// Try-catch.
+struct ITC {
+ ITC() try {} catch(...) {}
+ ~ITC() try {} catch(...) {}
+};
+
+struct OTC {
+ OTC();
+ ~OTC();
+};
+OTC::OTC() try {} catch(...) {}
+OTC::~OTC() try {} catch(...) {}
+
+#define STRUCT_WITH_DEFAULT(_base, _type) \
+ struct _type { \
+ _type() {} \
+ _base value; \
+ };
+
+STRUCT_WITH_DEFAULT(unsigned char, InMacro)
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-equals-delete-macros.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-equals-delete-macros.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-equals-delete-macros.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-equals-delete-macros.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,9 @@
+// RUN: %check_clang_tidy %s modernize-use-equals-delete %t -- \
+// RUN: -config="{CheckOptions: [{key: modernize-use-equals-delete.IgnoreMacros, value: 0}]}"
+
+#define MACRO(type) void operator=(type const &)
+class C {
+private:
+ MACRO(C);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function
+};
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-equals-delete.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-equals-delete.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-equals-delete.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-equals-delete.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,193 @@
+// RUN: %check_clang_tidy %s modernize-use-equals-delete %t
+
+struct PositivePrivate {
+private:
+ PositivePrivate();
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+ // CHECK-FIXES: PositivePrivate() = delete;
+ PositivePrivate(const PositivePrivate &);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+ // CHECK-FIXES: PositivePrivate(const PositivePrivate &) = delete;
+ PositivePrivate &operator=(const PositivePrivate &);
+ // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+ // CHECK-FIXES: PositivePrivate &operator=(const PositivePrivate &) = delete;
+ PositivePrivate(PositivePrivate &&);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+ // CHECK-FIXES: PositivePrivate(PositivePrivate &&) = delete;
+ PositivePrivate &operator=(PositivePrivate &&);
+ // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+ // CHECK-FIXES: PositivePrivate &operator=(PositivePrivate &&) = delete;
+ ~PositivePrivate();
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+ // CHECK-FIXES: ~PositivePrivate() = delete;
+};
+
+template<typename T>
+struct PositivePrivateTemplate {
+private:
+ PositivePrivateTemplate();
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+ // CHECK-FIXES: PositivePrivateTemplate() = delete;
+ PositivePrivateTemplate(const PositivePrivateTemplate &);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+ // CHECK-FIXES: PositivePrivateTemplate(const PositivePrivateTemplate &) = delete;
+ PositivePrivateTemplate &operator=(const PositivePrivateTemplate &);
+ // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+ // CHECK-FIXES: PositivePrivateTemplate &operator=(const PositivePrivateTemplate &) = delete;
+ PositivePrivateTemplate(PositivePrivateTemplate &&);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+ // CHECK-FIXES: PositivePrivateTemplate(PositivePrivateTemplate &&) = delete;
+ PositivePrivateTemplate &operator=(PositivePrivateTemplate &&);
+ // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+ // CHECK-FIXES: PositivePrivateTemplate &operator=(PositivePrivateTemplate &&) = delete;
+ ~PositivePrivateTemplate();
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+ // CHECK-FIXES: ~PositivePrivateTemplate() = delete;
+};
+
+template struct PositivePrivateTemplate<int>;
+template struct PositivePrivateTemplate<char>;
+
+struct NegativePublic {
+ NegativePublic(const NegativePublic &);
+};
+
+struct NegativeProtected {
+protected:
+ NegativeProtected(const NegativeProtected &);
+};
+
+struct PositiveInlineMember {
+ int foo() { return 0; }
+
+private:
+ PositiveInlineMember(const PositiveInlineMember &);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+ // CHECK-FIXES: PositiveInlineMember(const PositiveInlineMember &) = delete;
+};
+
+struct PositiveOutOfLineMember {
+ int foo();
+
+private:
+ PositiveOutOfLineMember(const PositiveOutOfLineMember &);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+ // CHECK-FIXES: PositiveOutOfLineMember(const PositiveOutOfLineMember &) = delete;
+};
+
+int PositiveOutOfLineMember::foo() { return 0; }
+
+struct PositiveAbstractMember {
+ virtual int foo() = 0;
+
+private:
+ PositiveAbstractMember(const PositiveAbstractMember &);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+ // CHECK-FIXES: PositiveAbstractMember(const PositiveAbstractMember &) = delete;
+};
+
+struct NegativeMemberNotImpl {
+ int foo();
+
+private:
+ NegativeMemberNotImpl(const NegativeMemberNotImpl &);
+};
+
+struct NegativeStaticMemberNotImpl {
+ static int foo();
+
+private:
+ NegativeStaticMemberNotImpl(const NegativeStaticMemberNotImpl &);
+};
+
+struct NegativeInline {
+private:
+ NegativeInline(const NegativeInline &) {}
+};
+
+struct NegativeOutOfLine {
+private:
+ NegativeOutOfLine(const NegativeOutOfLine &);
+};
+
+NegativeOutOfLine::NegativeOutOfLine(const NegativeOutOfLine &) {}
+
+struct NegativeConstructNotImpl {
+ NegativeConstructNotImpl();
+
+private:
+ NegativeConstructNotImpl(const NegativeConstructNotImpl &);
+};
+
+struct PositiveDefaultedConstruct {
+ PositiveDefaultedConstruct() = default;
+
+private:
+ PositiveDefaultedConstruct(const PositiveDefaultedConstruct &);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+ // CHECK-FIXES: PositiveDefaultedConstruct(const PositiveDefaultedConstruct &) = delete;
+};
+
+struct PositiveDeletedConstruct {
+ PositiveDeletedConstruct() = delete;
+
+private:
+ PositiveDeletedConstruct(const PositiveDeletedConstruct &);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+ // CHECK-FIXES: PositiveDeletedConstruct(const PositiveDeletedConstruct &) = delete;
+};
+
+struct NegativeDefaulted {
+private:
+ NegativeDefaulted(const NegativeDefaulted &) = default;
+};
+
+struct PrivateDeleted {
+private:
+ PrivateDeleted(const PrivateDeleted &) = delete;
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: deleted member function should be public [modernize-use-equals-delete]
+};
+
+struct ProtectedDeleted {
+protected:
+ ProtectedDeleted(const ProtectedDeleted &) = delete;
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: deleted member function should be public [modernize-use-equals-delete]
+};
+
+struct PublicDeleted {
+public:
+ PublicDeleted(const PublicDeleted &) = delete;
+};
+
+#define M1 \
+ struct PrivateDeletedMacro { \
+ private: \
+ PrivateDeletedMacro(const PrivateDeletedMacro &) = delete; \
+ }; \
+ struct ProtectedDeletedMacro { \
+ protected: \
+ ProtectedDeletedMacro(const ProtectedDeletedMacro &) = delete; \
+ }
+
+M1;
+
+#define DISALLOW_COPY_AND_ASSIGN(name) \
+ name(const name &) = delete; \
+ void operator=(const name &) = delete
+
+struct PrivateDeletedMacro2 {
+private:
+ DISALLOW_COPY_AND_ASSIGN(PrivateDeletedMacro2);
+};
+
+struct ProtectedDeletedMacro2 {
+protected:
+ DISALLOW_COPY_AND_ASSIGN(ProtectedDeletedMacro2);
+};
+
+// This resulted in a warning by default.
+#define MACRO(type) void operator=(type const &)
+class C {
+private:
+ MACRO(C);
+};
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-nodiscard-clang-unused.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-nodiscard-clang-unused.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-nodiscard-clang-unused.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-nodiscard-clang-unused.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,24 @@
+// RUN: %check_clang_tidy %s modernize-use-nodiscard %t -- \
+// RUN: -config="{CheckOptions: [{key: modernize-use-nodiscard.ReplacementString, value: '[[clang::warn_unused_result]]'}]}"
+
+class Foo
+{
+public:
+ bool f1() const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f1' should be marked {{\[\[clang::warn_unused_result\]\]}} [modernize-use-nodiscard]
+ // CHECK-FIXES: {{\[\[clang::warn_unused_result\]\]}} bool f1() const;
+
+ bool f2(int) const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f2' should be marked {{\[\[clang::warn_unused_result\]\]}} [modernize-use-nodiscard]
+ // CHECK-FIXES: {{\[\[clang::warn_unused_result\]\]}} bool f2(int) const;
+
+ bool f3(const int &) const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f3' should be marked {{\[\[clang::warn_unused_result\]\]}} [modernize-use-nodiscard]
+ // CHECK-FIXES: {{\[\[clang::warn_unused_result\]\]}} bool f3(const int &) const;
+
+ bool f4(void) const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f4' should be marked {{\[\[clang::warn_unused_result\]\]}} [modernize-use-nodiscard]
+ // CHECK-FIXES: {{\[\[clang::warn_unused_result\]\]}} bool f4(void) const;
+
+};
+
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-nodiscard-cxx11.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-nodiscard-cxx11.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-nodiscard-cxx11.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-nodiscard-cxx11.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,23 @@
+// RUN: %check_clang_tidy %s modernize-use-nodiscard %t -- \
+// RUN: -config="{CheckOptions: [{key: modernize-use-nodiscard.ReplacementString, value: '__attribute__((warn_unused_result))'}]}"
+
+class Foo
+{
+public:
+ bool f1() const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f1' should be marked __attribute__((warn_unused_result)) [modernize-use-nodiscard]
+ // CHECK-FIXES: __attribute__((warn_unused_result)) bool f1() const;
+
+ bool f2(int) const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f2' should be marked __attribute__((warn_unused_result)) [modernize-use-nodiscard]
+ // CHECK-FIXES: __attribute__((warn_unused_result)) bool f2(int) const;
+
+ bool f3(const int &) const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f3' should be marked __attribute__((warn_unused_result)) [modernize-use-nodiscard]
+ // CHECK-FIXES: __attribute__((warn_unused_result)) bool f3(const int &) const;
+
+ bool f4(void) const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f4' should be marked __attribute__((warn_unused_result)) [modernize-use-nodiscard]
+ // CHECK-FIXES: __attribute__((warn_unused_result)) bool f4(void) const;
+};
+
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-nodiscard-gcc-unused.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-nodiscard-gcc-unused.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-nodiscard-gcc-unused.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-nodiscard-gcc-unused.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,24 @@
+// RUN: %check_clang_tidy %s modernize-use-nodiscard %t -- \
+// RUN: -config="{CheckOptions: [{key: modernize-use-nodiscard.ReplacementString, value: '[[gcc::warn_unused_result]]'}]}"
+
+class Foo
+{
+public:
+ bool f1() const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f1' should be marked {{\[\[gcc::warn_unused_result\]\]}} [modernize-use-nodiscard]
+ // CHECK-FIXES: {{\[\[gcc::warn_unused_result\]\]}} bool f1() const;
+
+ bool f2(int) const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f2' should be marked {{\[\[gcc::warn_unused_result\]\]}} [modernize-use-nodiscard]
+ // CHECK-FIXES: {{\[\[gcc::warn_unused_result\]\]}} bool f2(int) const;
+
+ bool f3(const int &) const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f3' should be marked {{\[\[gcc::warn_unused_result\]\]}} [modernize-use-nodiscard]
+ // CHECK-FIXES: {{\[\[gcc::warn_unused_result\]\]}} bool f3(const int &) const;
+
+ bool f4(void) const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f4' should be marked {{\[\[gcc::warn_unused_result\]\]}} [modernize-use-nodiscard]
+ // CHECK-FIXES: {{\[\[gcc::warn_unused_result\]\]}} bool f4(void) const;
+
+};
+
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-nodiscard-no-macro-inscope-cxx11.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-nodiscard-no-macro-inscope-cxx11.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-nodiscard-no-macro-inscope-cxx11.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-nodiscard-no-macro-inscope-cxx11.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,13 @@
+// RUN: %check_clang_tidy %s modernize-use-nodiscard %t -- \
+// RUN: -config="{CheckOptions: [{key: modernize-use-nodiscard.ReplacementString, value: 'CUSTOM_NO_DISCARD'}]}"
+
+// As if the macro was not defined.
+// #define CUSTOM_NO_DISCARD __attribute_((warn_unused_result))
+
+class Foo
+{
+public:
+ bool f1() const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f1' should be marked CUSTOM_NO_DISCARD [modernize-use-nodiscard]
+};
+
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-nodiscard-no-macro.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-nodiscard-no-macro.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-nodiscard-no-macro.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-nodiscard-no-macro.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,22 @@
+// RUN: %check_clang_tidy -std=c++17-or-later %s modernize-use-nodiscard %t
+
+class Foo
+{
+public:
+ bool f1() const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f1' should be marked {{\[\[nodiscard\]\]}} [modernize-use-nodiscard]
+ // CHECK-FIXES: {{\[\[nodiscard\]\]}} bool f1() const;
+
+ bool f2(int) const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f2' should be marked {{\[\[nodiscard\]\]}} [modernize-use-nodiscard]
+ // CHECK-FIXES: {{\[\[nodiscard\]\]}} bool f2(int) const;
+
+ bool f3(const int &) const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f3' should be marked {{\[\[nodiscard\]\]}} [modernize-use-nodiscard]
+ // CHECK-FIXES: {{\[\[nodiscard\]\]}} bool f3(const int &) const;
+
+ bool f4(void) const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f4' should be marked {{\[\[nodiscard\]\]}} [modernize-use-nodiscard]
+ // CHECK-FIXES: {{\[\[nodiscard\]\]}} bool f4(void) const;
+
+};
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-nodiscard.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-nodiscard.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-nodiscard.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-nodiscard.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,262 @@
+// RUN: %check_clang_tidy %s modernize-use-nodiscard %t -- \
+// RUN: -config="{CheckOptions: [{key: modernize-use-nodiscard.ReplacementString, value: 'NO_DISCARD'}]}" \
+// RUN: -- -std=c++17
+
+namespace std {
+template <class>
+class function;
+class string {};
+}
+
+namespace boost {
+template <class>
+class function;
+}
+
+#define MUST_USE_RESULT __attribute__((warn_unused_result))
+#define NO_DISCARD [[nodiscard]]
+#define NO_RETURN [[noreturn]]
+
+#define BOOLEAN_FUNC bool f23() const
+
+typedef unsigned my_unsigned;
+typedef unsigned &my_unsigned_reference;
+typedef const unsigned &my_unsigned_const_reference;
+
+class Foo {
+public:
+ using size_type = unsigned;
+
+ bool f1() const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f1' should be marked NO_DISCARD [modernize-use-nodiscard]
+ // CHECK-FIXES: NO_DISCARD bool f1() const;
+
+ bool f2(int) const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f2' should be marked NO_DISCARD [modernize-use-nodiscard]
+ // CHECK-FIXES: NO_DISCARD bool f2(int) const;
+
+ bool f3(const int &) const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f3' should be marked NO_DISCARD [modernize-use-nodiscard]
+ // CHECK-FIXES: NO_DISCARD bool f3(const int &) const;
+
+ bool f4(void) const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f4' should be marked NO_DISCARD [modernize-use-nodiscard]
+ // CHECK-FIXES: NO_DISCARD bool f4(void) const;
+
+ // negative tests
+
+ void f5() const;
+
+ bool f6();
+
+ bool f7(int &);
+
+ bool f8(int &) const;
+
+ bool f9(int *) const;
+
+ bool f10(const int &, int &) const;
+
+ NO_DISCARD bool f12() const;
+
+ MUST_USE_RESULT bool f13() const;
+
+ [[nodiscard]] bool f11() const;
+
+ [[clang::warn_unused_result]] bool f11a() const;
+
+ [[gnu::warn_unused_result]] bool f11b() const;
+
+ bool _f20() const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function '_f20' should be marked NO_DISCARD [modernize-use-nodiscard]
+ // CHECK-FIXES: NO_DISCARD bool _f20() const;
+
+ NO_RETURN bool f21() const;
+
+ ~Foo();
+
+ bool operator+=(int) const;
+
+ // extra keywords (virtual,inline,const) on return type
+
+ virtual bool f14() const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f14' should be marked NO_DISCARD [modernize-use-nodiscard]
+ // CHECK-FIXES: NO_DISCARD virtual bool f14() const;
+
+ const bool f15() const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f15' should be marked NO_DISCARD [modernize-use-nodiscard]
+ // CHECK-FIXES: NO_DISCARD const bool f15() const;
+
+ inline const bool f16() const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f16' should be marked NO_DISCARD [modernize-use-nodiscard]
+ // CHECK-FIXES: NO_DISCARD inline const bool f16() const;
+
+ inline const std::string &f45() const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f45' should be marked NO_DISCARD [modernize-use-nodiscard]
+ // CHECK-FIXES: NO_DISCARD inline const std::string &f45() const;
+
+ inline virtual const bool f17() const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f17' should be marked NO_DISCARD [modernize-use-nodiscard]
+ // CHECK-FIXES: NO_DISCARD inline virtual const bool f17() const;
+
+ // inline with body
+ bool f18() const
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f18' should be marked NO_DISCARD [modernize-use-nodiscard]
+ // CHECK-FIXES: NO_DISCARD bool f18() const
+ {
+ return true;
+ }
+
+ bool f19() const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f19' should be marked NO_DISCARD [modernize-use-nodiscard]
+ // CHECK-FIXES: NO_DISCARD bool f19() const;
+
+ BOOLEAN_FUNC;
+
+ bool f24(size_type) const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f24' should be marked NO_DISCARD [modernize-use-nodiscard]
+ // CHECK-FIXES: NO_DISCARD bool f24(size_type) const;
+
+ bool f28(my_unsigned) const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f28' should be marked NO_DISCARD [modernize-use-nodiscard]
+ // CHECK-FIXES: NO_DISCARD bool f28(my_unsigned) const;
+
+ bool f29(my_unsigned_reference) const;
+
+ bool f30(my_unsigned_const_reference) const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f30' should be marked NO_DISCARD [modernize-use-nodiscard]
+ // CHECK-FIXES: NO_DISCARD bool f30(my_unsigned_const_reference) const;
+
+ template <class F>
+ F f37(F a, F b) const;
+
+ template <class F>
+ bool f38(F a) const;
+
+ bool f39(const std::function<bool()> &predicate) const;
+
+ bool f39a(std::function<bool()> predicate) const;
+
+ bool f39b(const std::function<bool()> predicate) const;
+
+ bool f45(const boost::function<bool()> &predicate) const;
+
+ bool f45a(boost::function<bool()> predicate) const;
+
+ bool f45b(const boost::function<bool()> predicate) const;
+
+ // Do not add ``[[nodiscard]]`` to parameter packs.
+ template <class... Args>
+ bool ParameterPack(Args... args) const;
+
+ template <typename... Targs>
+ bool ParameterPack2(Targs... Fargs) const;
+
+ // Do not add ``[[nodiscard]]`` to variadic functions.
+ bool VariadicFunctionTest(const int &, ...) const;
+
+ // Do not add ``[[nodiscard]]`` to non constant static functions.
+ static bool not_empty();
+
+ // Do not add ``[[nodiscard]]`` to conversion functions.
+ // explicit operator bool() const { return true; }
+};
+
+// Do not add ``[[nodiscard]]`` to Lambda.
+const auto nonConstReferenceType = [] {
+ return true;
+};
+
+auto lambda1 = [](int a, int b) { return a < b; };
+auto lambda1a = [](int a) { return a; };
+auto lambda1b = []() { return true;};
+
+auto get_functor = [](bool check) {
+ return [&](const std::string& sr)->std::string {
+ if(check){
+ return std::string();
+ }
+ return std::string();
+ };
+};
+
+// Do not add ``[[nodiscard]]`` to function definition.
+bool Foo::f19() const {
+ return true;
+}
+
+template <class T>
+class Bar {
+public:
+ using value_type = T;
+ using reference = value_type &;
+ using const_reference = const value_type &;
+
+ // Do not add ``[[nodiscard]]`` to non explicit conversion functions.
+ operator bool() const { return true; }
+
+ bool empty() const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'empty' should be marked NO_DISCARD [modernize-use-nodiscard]
+ // CHECK-FIXES: NO_DISCARD bool empty() const;
+
+ // we cannot assume that the template parameter isn't a pointer
+ bool f25(value_type) const;
+
+ bool f27(reference) const;
+
+ typename T::value_type f35() const;
+
+ T f34() const;
+
+ bool f31(T) const;
+
+ bool f33(T &) const;
+
+ bool f26(const_reference) const;
+
+ bool f32(const T &) const;
+};
+
+template <typename _Tp, int cn>
+class Vec {
+public:
+ Vec(_Tp v0, _Tp v1); //!< 2-element vector constructor
+
+ Vec cross(const Vec &v) const;
+
+ template <typename T2>
+ operator Vec<T2, cn>() const;
+};
+
+template <class T>
+class Bar2 {
+public:
+ typedef T value_type;
+ typedef value_type &reference;
+ typedef const value_type &const_reference;
+
+ // we cannot assume that the template parameter isn't a pointer
+ bool f40(value_type) const;
+
+ bool f41(reference) const;
+
+ value_type f42() const;
+
+ typename T::value_type f43() const;
+
+ bool f44(const_reference) const;
+};
+
+template <class T>
+bool Bar<T>::empty() const {
+ return true;
+}
+
+// don't mark typical ``[[nodiscard]]`` candidates if the class
+// has mutable member variables
+class MutableExample {
+ mutable bool m_isempty;
+
+public:
+ bool empty() const;
+};
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-noexcept-macro.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-noexcept-macro.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-noexcept-macro.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-noexcept-macro.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,38 @@
+// RUN: %check_clang_tidy -std=c++11,c++14 %s modernize-use-noexcept %t -- \
+// RUN: -config="{CheckOptions: [{key: modernize-use-noexcept.ReplacementString, value: 'NOEXCEPT'}]}" \
+// RUN: -- -fexceptions
+// This test is not run in C++17 or later because dynamic exception
+// specifications were removed in C++17.
+
+// Example definition of NOEXCEPT -- simplified test to see if noexcept is supported.
+#if (__has_feature(cxx_noexcept))
+#define NOEXCEPT noexcept
+#else
+#define NOEXCEPT throw()
+#endif
+
+void bar() throw() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: dynamic exception specification 'throw()' is deprecated; consider using 'NOEXCEPT' instead [modernize-use-noexcept]
+// CHECK-FIXES: void bar() NOEXCEPT {}
+
+// Should not trigger a FixItHint, since macros only support noexcept, and this
+// case throws.
+class A {};
+class B {};
+void foobar() throw(A, B);
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: dynamic exception specification 'throw(A, B)' is deprecated; consider removing it instead [modernize-use-noexcept]
+
+// Should not trigger a replacement.
+void foo() noexcept(true);
+
+struct Z {
+ void operator delete(void *ptr) throw();
+ void operator delete[](void *ptr) throw(int);
+ ~Z() throw(int) {}
+};
+// CHECK-MESSAGES: :[[@LINE-4]]:35: warning: dynamic exception specification 'throw()' is deprecated; consider using 'NOEXCEPT' instead [modernize-use-noexcept]
+// CHECK-MESSAGES: :[[@LINE-4]]:37: warning: dynamic exception specification 'throw(int)' is deprecated; consider removing it instead [modernize-use-noexcept]
+// CHECK-MESSAGES: :[[@LINE-4]]:8: warning: dynamic exception specification 'throw(int)' is deprecated; consider removing it instead [modernize-use-noexcept]
+// CHECK-FIXES: void operator delete(void *ptr) NOEXCEPT;
+// CHECK-FIXES: void operator delete[](void *ptr) throw(int);
+// CHECK-FIXES: ~Z() throw(int) {}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-noexcept-opt.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-noexcept-opt.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-noexcept-opt.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-noexcept-opt.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,90 @@
+// RUN: %check_clang_tidy -std=c++11,c++14 %s modernize-use-noexcept %t -- \
+// RUN: -config="{CheckOptions: [{key: modernize-use-noexcept.UseNoexceptFalse, value: 0}]}" \
+// RUN: -- -fexceptions
+// This test is not run in C++17 or later because dynamic exception
+// specifications were removed in C++17.
+
+class A {};
+class B {};
+
+void foo() throw();
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept]
+// CHECK-FIXES: void foo() noexcept;
+
+void bar() throw(...);
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: dynamic exception specification 'throw(...)' is deprecated; consider removing it instead [modernize-use-noexcept]
+// CHECK-FIXES: void bar() ;
+
+void k() throw(int(int));
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: dynamic exception specification 'throw(int(int))' is deprecated; consider removing it instead [modernize-use-noexcept]
+// CHECK-FIXES: void k() ;
+
+void foobar() throw(A, B)
+{}
+// CHECK-MESSAGES: :[[@LINE-2]]:15: warning: dynamic exception specification 'throw(A, B)' is deprecated; consider removing it instead [modernize-use-noexcept]
+// CHECK-FIXES: void foobar()
+
+void baz(int = (throw A(), 0)) throw(A, B) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: dynamic exception specification 'throw(A, B)' is deprecated; consider removing it instead [modernize-use-noexcept]
+// CHECK-FIXES: void baz(int = (throw A(), 0)) {}
+
+void g(void (*fp)(void) throw());
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept]
+// CHECK-FIXES: void g(void (*fp)(void) noexcept);
+
+void f(void (*fp)(void) throw(int)) throw(char);
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: dynamic exception specification 'throw(int)' is deprecated; consider removing it instead [modernize-use-noexcept]
+// CHECK-MESSAGES: :[[@LINE-2]]:37: warning: dynamic exception specification 'throw(char)' is deprecated; consider removing it instead [modernize-use-noexcept]
+// CHECK-FIXES: void f(void (*fp)(void) ) ;
+
+#define THROW throw
+void h(void (*fp)(void) THROW(int)) THROW(char);
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: dynamic exception specification 'THROW(int)' is deprecated; consider removing it instead [modernize-use-noexcept]
+// CHECK-MESSAGES: :[[@LINE-2]]:37: warning: dynamic exception specification 'THROW(char)' is deprecated; consider removing it instead [modernize-use-noexcept]
+// CHECK-FIXES: void h(void (*fp)(void) ) ;
+
+void j() throw(int(int) throw(void(void) throw(int)));
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: dynamic exception specification 'throw(int(int) throw(void(void) throw(int)))' is deprecated; consider removing it instead [modernize-use-noexcept]
+// CHECK-FIXES: void j() ;
+
+class Y {
+ Y() throw() = default;
+};
+// CHECK-MESSAGES: :[[@LINE-2]]:7: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept]
+// CHECK-FIXES: Y() noexcept = default;
+
+struct Z {
+ void operator delete(void *ptr) throw();
+ void operator delete[](void *ptr) throw(int);
+ ~Z() throw(int) {}
+};
+// CHECK-MESSAGES: :[[@LINE-4]]:35: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept]
+// CHECK-MESSAGES: :[[@LINE-4]]:37: warning: dynamic exception specification 'throw(int)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-MESSAGES: :[[@LINE-4]]:8: warning: dynamic exception specification 'throw(int)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void operator delete(void *ptr) noexcept;
+// CHECK-FIXES: void operator delete[](void *ptr) noexcept(false);
+// CHECK-FIXES: ~Z() noexcept(false) {}
+
+struct S {
+ void f() throw();
+};
+void f(void (S::*)() throw());
+// CHECK-MESSAGES: :[[@LINE-3]]:12: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept]
+// CHECK-MESSAGES: :[[@LINE-2]]:22: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept]
+// CHECK-FIXES: void f() noexcept;
+// CHECK-FIXES: void f(void (S::*)() noexcept);
+
+typedef void (*fp)(void (*fp2)(int) throw());
+// CHECK-MESSAGES: :[[@LINE-1]]:37: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept]
+// CHECK-FIXES: typedef void (*fp)(void (*fp2)(int) noexcept);
+
+// Should not trigger a replacement.
+void titi() noexcept {}
+void toto() noexcept(true) {}
+
+// Should not trigger a replacement.
+void bad()
+#if !__has_feature(cxx_noexcept)
+ throw()
+#endif
+ ;
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-noexcept.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-noexcept.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-noexcept.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-noexcept.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,105 @@
+// RUN: %check_clang_tidy -std=c++11,c++14 %s modernize-use-noexcept %t -- -- -fexceptions
+// This test is not run in C++17 or later because dynamic exception
+// specifications were removed in C++17.
+
+class A {};
+class B {};
+
+void foo() throw();
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept]
+// CHECK-FIXES: void foo() noexcept;
+
+template <typename T>
+void foo() throw();
+void footest() { foo<int>(); foo<double>(); }
+// CHECK-MESSAGES: :[[@LINE-2]]:12: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept]
+// CHECK-FIXES: void foo() noexcept;
+
+void bar() throw(...);
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: dynamic exception specification 'throw(...)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void bar() noexcept(false);
+
+void k() throw(int(int));
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: dynamic exception specification 'throw(int(int))' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void k() noexcept(false);
+
+void foobar() throw(A, B)
+{}
+// CHECK-MESSAGES: :[[@LINE-2]]:15: warning: dynamic exception specification 'throw(A, B)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void foobar() noexcept(false)
+
+void baz(int = (throw A(), 0)) throw(A, B) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: dynamic exception specification 'throw(A, B)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void baz(int = (throw A(), 0)) noexcept(false) {}
+
+void g(void (*fp)(void) throw());
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept]
+// CHECK-FIXES: void g(void (*fp)(void) noexcept);
+
+void f(void (*fp)(void) throw(int)) throw(char);
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: dynamic exception specification 'throw(int)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-MESSAGES: :[[@LINE-2]]:37: warning: dynamic exception specification 'throw(char)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void f(void (*fp)(void) noexcept(false)) noexcept(false);
+
+#define THROW throw
+void h(void (*fp)(void) THROW(int)) THROW(char);
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: dynamic exception specification 'THROW(int)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-MESSAGES: :[[@LINE-2]]:37: warning: dynamic exception specification 'THROW(char)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void h(void (*fp)(void) noexcept(false)) noexcept(false);
+
+void j() throw(int(int) throw(void(void) throw(int)));
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: dynamic exception specification 'throw(int(int) throw(void(void) throw(int)))' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void j() noexcept(false);
+
+class Y {
+ Y() throw() = default;
+};
+// CHECK-MESSAGES: :[[@LINE-2]]:7: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept]
+// CHECK-FIXES: Y() noexcept = default;
+
+struct Z {
+ void operator delete(void *ptr) throw();
+ void operator delete[](void *ptr) throw(int);
+ ~Z() throw(int) {}
+};
+// CHECK-MESSAGES: :[[@LINE-4]]:35: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept]
+// CHECK-MESSAGES: :[[@LINE-4]]:37: warning: dynamic exception specification 'throw(int)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-MESSAGES: :[[@LINE-4]]:8: warning: dynamic exception specification 'throw(int)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void operator delete(void *ptr) noexcept;
+// CHECK-FIXES: void operator delete[](void *ptr) noexcept(false);
+// CHECK-FIXES: ~Z() noexcept(false) {}
+
+struct S {
+ void f() throw();
+};
+void f(void (S::*)() throw());
+// CHECK-MESSAGES: :[[@LINE-3]]:12: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept]
+// CHECK-MESSAGES: :[[@LINE-2]]:22: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept]
+// CHECK-FIXES: void f() noexcept;
+// CHECK-FIXES: void f(void (S::*)() noexcept);
+
+template <typename T>
+struct ST {
+ void foo() throw();
+};
+template <typename T>
+void ft(void (ST<T>::*)() throw());
+// CHECK-MESSAGES: :[[@LINE-4]]:14: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept]
+// CHECK-MESSAGES: :[[@LINE-2]]:27: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept]
+// CHECK-FIXES: void foo() noexcept;
+// CHECK-FIXES: void ft(void (ST<T>::*)() noexcept);
+
+typedef void (*fp)(void (*fp2)(int) throw());
+// CHECK-MESSAGES: :[[@LINE-1]]:37: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept]
+// CHECK-FIXES: typedef void (*fp)(void (*fp2)(int) noexcept);
+
+// Should not trigger a replacement.
+void titi() noexcept {}
+void toto() noexcept(true) {}
+
+// Should not trigger a replacement.
+void bad()
+#if !__has_feature(cxx_noexcept)
+ throw()
+#endif
+ ;
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-nullptr-basic.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-nullptr-basic.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-nullptr-basic.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-nullptr-basic.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,362 @@
+// RUN: %check_clang_tidy -std=c++98 %s modernize-use-nullptr %t -- -- -Wno-non-literal-null-conversion
+//
+// Some parts of the test (e.g. assignment of `const int` to `int *`) fail in
+// C++11, so we need to run the test in C++98 mode.
+//
+// FIXME: Make the test work in all language modes.
+
+const unsigned int g_null = 0;
+#define NULL 0
+
+void test_assignment() {
+ int *p1 = 0;
+ // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use nullptr [modernize-use-nullptr]
+ // CHECK-FIXES: int *p1 = nullptr;
+ p1 = 0;
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use nullptr
+ // CHECK-FIXES: p1 = nullptr;
+
+ int *p2 = NULL;
+ // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use nullptr
+ // CHECK-FIXES: int *p2 = nullptr;
+
+ p2 = p1;
+ // CHECK-FIXES: p2 = p1;
+
+ const int null = 0;
+ int *p3 = null;
+ // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use nullptr
+ // CHECK-FIXES: int *p3 = nullptr;
+
+ p3 = NULL;
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use nullptr
+ // CHECK-FIXES: p3 = nullptr;
+
+ int *p4 = p3;
+ // CHECK-FIXES: int *p4 = p3;
+
+ p4 = null;
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use nullptr
+ // CHECK-FIXES: p4 = nullptr;
+
+ int i1 = 0;
+
+ int i2 = NULL;
+
+ int i3 = null;
+
+ int *p5, *p6, *p7;
+ p5 = p6 = p7 = NULL;
+ // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: use nullptr
+ // CHECK-FIXES: p5 = p6 = p7 = nullptr;
+}
+
+struct Foo {
+ Foo(int *p = NULL) : m_p1(p) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use nullptr
+ // CHECK-FIXES: Foo(int *p = nullptr) : m_p1(p) {}
+
+ void bar(int *p = 0) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: use nullptr
+ // CHECK-FIXES: void bar(int *p = nullptr) {}
+
+ void baz(int i = 0) {}
+
+ int *m_p1;
+ static int *m_p2;
+};
+
+int *Foo::m_p2 = NULL;
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: use nullptr
+// CHECK-FIXES: int *Foo::m_p2 = nullptr;
+
+template <typename T>
+struct Bar {
+ Bar(T *p) : m_p(p) {
+ m_p = static_cast<T*>(NULL);
+ // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: use nullptr
+ // CHECK-FIXES: m_p = static_cast<T*>(nullptr);
+
+ m_p = static_cast<T*>(reinterpret_cast<int*>((void*)NULL));
+ // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: use nullptr
+ // CHECK-FIXES: m_p = static_cast<T*>(nullptr);
+
+ m_p = static_cast<T*>(p ? p : static_cast<void*>(g_null));
+ // CHECK-MESSAGES: :[[@LINE-1]]:54: warning: use nullptr
+ // CHECK-FIXES: m_p = static_cast<T*>(p ? p : static_cast<void*>(nullptr));
+
+ T *p2 = static_cast<T*>(reinterpret_cast<int*>((void*)NULL));
+ // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: use nullptr
+ // CHECK-FIXES: T *p2 = static_cast<T*>(nullptr);
+
+ m_p = NULL;
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: use nullptr
+ // CHECK-FIXES: m_p = nullptr;
+
+ int i = static_cast<int>(0.f);
+ T *i2 = static_cast<int>(0.f);
+ // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use nullptr
+ // CHECK-FIXES: T *i2 = nullptr;
+ }
+
+ T *m_p;
+};
+
+struct Baz {
+ Baz() : i(0) {}
+ int i;
+};
+
+void test_cxx_cases() {
+ Foo f(g_null);
+ // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use nullptr
+ // CHECK-FIXES: Foo f(nullptr);
+
+ f.bar(NULL);
+ // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use nullptr
+ // CHECK-FIXES: f.bar(nullptr);
+
+ f.baz(g_null);
+
+ f.m_p1 = 0;
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use nullptr
+ // CHECK-FIXES: f.m_p1 = nullptr;
+
+ Bar<int> b(g_null);
+ // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: use nullptr
+ // CHECK-FIXES: Bar<int> b(nullptr);
+
+ Baz b2;
+ int Baz::*memptr(0);
+ // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: use nullptr
+ // CHECK-FIXES: int Baz::*memptr(nullptr);
+
+ memptr = 0;
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use nullptr
+ // CHECK-FIXES: memptr = nullptr;
+}
+
+void test_function_default_param1(void *p = 0);
+// CHECK-MESSAGES: :[[@LINE-1]]:45: warning: use nullptr
+// CHECK-FIXES: void test_function_default_param1(void *p = nullptr);
+
+void test_function_default_param2(void *p = NULL);
+// CHECK-MESSAGES: :[[@LINE-1]]:45: warning: use nullptr
+// CHECK-FIXES: void test_function_default_param2(void *p = nullptr);
+
+void test_function_default_param3(void *p = g_null);
+// CHECK-MESSAGES: :[[@LINE-1]]:45: warning: use nullptr
+// CHECK-FIXES: void test_function_default_param3(void *p = nullptr);
+
+void test_function(int *p) {}
+
+void test_function_no_ptr_param(int i) {}
+
+void test_function_call() {
+ test_function(0);
+ // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: use nullptr
+ // CHECK-FIXES: test_function(nullptr);
+
+ test_function(NULL);
+ // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: use nullptr
+ // CHECK-FIXES: test_function(nullptr);
+
+ test_function(g_null);
+ // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: use nullptr
+ // CHECK-FIXES: test_function(nullptr);
+
+ test_function_no_ptr_param(0);
+}
+
+char *test_function_return1() {
+ return 0;
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use nullptr
+ // CHECK-FIXES: return nullptr;
+}
+
+void *test_function_return2() {
+ return NULL;
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use nullptr
+ // CHECK-FIXES: return nullptr;
+}
+
+long *test_function_return3() {
+ return g_null;
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use nullptr
+ // CHECK-FIXES: return nullptr;
+}
+
+int test_function_return4() {
+ return 0;
+}
+
+int test_function_return5() {
+ return NULL;
+}
+
+int test_function_return6() {
+ return g_null;
+}
+
+int *test_function_return_cast1() {
+ return(int)0;
+ // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use nullptr
+ // CHECK-FIXES: return nullptr;
+}
+
+int *test_function_return_cast2() {
+#define RET return
+ RET(int)0;
+ // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use nullptr
+ // CHECK-FIXES: RET nullptr;
+#undef RET
+}
+
+// Test parentheses expressions resulting in a nullptr.
+int *test_parentheses_expression1() {
+ return(0);
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use nullptr
+ // CHECK-FIXES: return(nullptr);
+}
+
+int *test_parentheses_expression2() {
+ return(int(0.f));
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use nullptr
+ // CHECK-FIXES: return(nullptr);
+}
+
+int *test_nested_parentheses_expression() {
+ return((((0))));
+ // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use nullptr
+ // CHECK-FIXES: return((((nullptr))));
+}
+
+void *test_parentheses_explicit_cast() {
+ return(static_cast<void*>(0));
+ // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: use nullptr
+ // CHECK-FIXES: return(static_cast<void*>(nullptr));
+}
+
+void *test_parentheses_explicit_cast_sequence1() {
+ return(static_cast<void*>(static_cast<int*>((void*)NULL)));
+ // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: use nullptr
+ // CHECK-FIXES: return(static_cast<void*>(nullptr));
+}
+
+void *test_parentheses_explicit_cast_sequence2() {
+ return(static_cast<void*>(reinterpret_cast<int*>((float*)int(0.f))));
+ // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: use nullptr
+ // CHECK-FIXES: return(static_cast<void*>(nullptr));
+}
+
+// Test explicit cast expressions resulting in nullptr.
+struct Bam {
+ Bam(int *a) {}
+ Bam(float *a) {}
+ Bam operator=(int *a) { return Bam(a); }
+ Bam operator=(float *a) { return Bam(a); }
+};
+
+void ambiguous_function(int *a) {}
+void ambiguous_function(float *a) {}
+void const_ambiguous_function(const int *p) {}
+void const_ambiguous_function(const float *p) {}
+
+void test_explicit_cast_ambiguous1() {
+ ambiguous_function((int*)0);
+ // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use nullptr
+ // CHECK-FIXES: ambiguous_function((int*)nullptr);
+}
+
+void test_explicit_cast_ambiguous2() {
+ ambiguous_function((int*)(0));
+ // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use nullptr
+ // CHECK-FIXES: ambiguous_function((int*)nullptr);
+}
+
+void test_explicit_cast_ambiguous3() {
+ ambiguous_function(static_cast<int*>(reinterpret_cast<int*>((float*)0)));
+ // CHECK-MESSAGES: :[[@LINE-1]]:40: warning: use nullptr
+ // CHECK-FIXES: ambiguous_function(static_cast<int*>(nullptr));
+}
+
+Bam test_explicit_cast_ambiguous4() {
+ return(((int*)(0)));
+ // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: use nullptr
+ // CHECK-FIXES: return(((int*)nullptr));
+}
+
+void test_explicit_cast_ambiguous5() {
+ // Test for ambiguous overloaded constructors.
+ Bam k((int*)(0));
+ // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: use nullptr
+ // CHECK-FIXES: Bam k((int*)nullptr);
+
+ // Test for ambiguous overloaded operators.
+ k = (int*)0;
+ // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use nullptr
+ // CHECK-FIXES: k = (int*)nullptr;
+}
+
+void test_const_pointers_abiguous() {
+ const_ambiguous_function((int*)0);
+ // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: use nullptr
+ // CHECK-FIXES: const_ambiguous_function((int*)nullptr);
+}
+
+// Test where the implicit cast to null is surrounded by another implict cast
+// with possible explict casts in-between.
+void test_const_pointers() {
+ const int *const_p1 = 0;
+ // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: use nullptr
+ // CHECK-FIXES: const int *const_p1 = nullptr;
+ const int *const_p2 = NULL;
+ // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: use nullptr
+ // CHECK-FIXES: const int *const_p2 = nullptr;
+ const int *const_p3 = (int)0;
+ // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: use nullptr
+ // CHECK-FIXES: const int *const_p3 = nullptr;
+ const int *const_p4 = (int)0.0f;
+ // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: use nullptr
+ // CHECK-FIXES: const int *const_p4 = nullptr;
+ const int *const_p5 = (int*)0;
+ // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: use nullptr
+ // CHECK-FIXES: const int *const_p5 = (int*)nullptr;
+ int *t;
+ const int *const_p6 = static_cast<int*>(t ? t : static_cast<int*>(0));
+ // CHECK-MESSAGES: :[[@LINE-1]]:69: warning: use nullptr
+ // CHECK-FIXES: const int *const_p6 = static_cast<int*>(t ? t : static_cast<int*>(nullptr));
+}
+
+void test_nested_implicit_cast_expr() {
+ int func0(void*, void*);
+ int func1(int, void*, void*);
+
+ (double)func1(0, 0, 0);
+ // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: use nullptr
+ // CHECK-MESSAGES: :[[@LINE-2]]:23: warning: use nullptr
+ // CHECK-FIXES: (double)func1(0, nullptr, nullptr);
+ (double)func1(func0(0, 0), 0, 0);
+ // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: use nullptr
+ // CHECK-MESSAGES: :[[@LINE-2]]:26: warning: use nullptr
+ // CHECK-MESSAGES: :[[@LINE-3]]:30: warning: use nullptr
+ // CHECK-MESSAGES: :[[@LINE-4]]:33: warning: use nullptr
+ // CHECK-FIXES: (double)func1(func0(nullptr, nullptr), nullptr, nullptr);
+}
+
+// FIXME: currently, the check doesn't work as it should with templates.
+template<typename T>
+class A {
+ public:
+ A(T *p = NULL) {}
+
+ void f() {
+ Ptr = NULL;
+ }
+ T *Ptr;
+};
+
+template<typename T>
+T *f2(T *a = NULL) {
+ return a ? a : NULL;
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-nullptr.c
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-nullptr.c?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-nullptr.c (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-nullptr.c Fri Oct 11 05:05:42 2019
@@ -0,0 +1,10 @@
+// RUN: clang-tidy %s -checks=-*,modernize-use-nullptr -- | count 0
+
+// Note: this test expects no diagnostics, but FileCheck cannot handle that,
+// hence the use of | count 0.
+
+#define NULL 0
+void f(void) {
+ char *str = NULL; // ok
+ (void)str;
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-nullptr.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-nullptr.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-nullptr.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-nullptr.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,304 @@
+// RUN: %check_clang_tidy %s modernize-use-nullptr %t -- \
+// RUN: -config="{CheckOptions: [{key: modernize-use-nullptr.NullMacros, value: 'MY_NULL,NULL'}]}"
+
+#define NULL 0
+
+namespace std {
+
+typedef decltype(nullptr) nullptr_t;
+
+} // namespace std
+
+// Just to make sure make_null() could have side effects.
+void external();
+
+std::nullptr_t make_null() {
+ external();
+ return nullptr;
+}
+
+void func() {
+ void *CallTest = make_null();
+
+ int var = 1;
+ void *CommaTest = (var+=2, make_null());
+
+ int *CastTest = static_cast<int*>(make_null());
+}
+
+void dummy(int*) {}
+void side_effect() {}
+
+#define MACRO_EXPANSION_HAS_NULL \
+ void foo() { \
+ dummy(0); \
+ dummy(NULL); \
+ side_effect(); \
+ }
+
+MACRO_EXPANSION_HAS_NULL;
+#undef MACRO_EXPANSION_HAS_NULL
+
+
+void test_macro_expansion1() {
+#define MACRO_EXPANSION_HAS_NULL \
+ dummy(NULL); \
+ side_effect();
+
+ MACRO_EXPANSION_HAS_NULL;
+
+#undef MACRO_EXPANSION_HAS_NULL
+}
+
+// Test macro expansion with cast sequence, PR15572.
+void test_macro_expansion2() {
+#define MACRO_EXPANSION_HAS_NULL \
+ dummy((int*)0); \
+ side_effect();
+
+ MACRO_EXPANSION_HAS_NULL;
+
+#undef MACRO_EXPANSION_HAS_NULL
+}
+
+void test_macro_expansion3() {
+#define MACRO_EXPANSION_HAS_NULL \
+ dummy(NULL); \
+ side_effect();
+
+#define OUTER_MACRO \
+ MACRO_EXPANSION_HAS_NULL; \
+ side_effect();
+
+ OUTER_MACRO;
+
+#undef OUTER_MACRO
+#undef MACRO_EXPANSION_HAS_NULL
+}
+
+void test_macro_expansion4() {
+#define MY_NULL NULL
+ int *p = MY_NULL;
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use nullptr [modernize-use-nullptr]
+ // CHECK-FIXES: int *p = nullptr;
+#undef MY_NULL
+}
+
+#define IS_EQ(x, y) if (x != y) return;
+void test_macro_args() {
+ int i = 0;
+ int *Ptr;
+
+ IS_EQ(static_cast<int*>(0), Ptr);
+ // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: use nullptr
+ // CHECK-FIXES: IS_EQ(static_cast<int*>(nullptr), Ptr);
+
+ IS_EQ(0, Ptr); // literal
+ // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use nullptr
+ // CHECK-FIXES: IS_EQ(nullptr, Ptr);
+
+ IS_EQ(NULL, Ptr); // macro
+ // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use nullptr
+ // CHECK-FIXES: IS_EQ(nullptr, Ptr);
+
+ // These are ok since the null literal is not spelled within a macro.
+#define myassert(x) if (!(x)) return;
+ myassert(0 == Ptr);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use nullptr
+ // CHECK-FIXES: myassert(nullptr == Ptr);
+
+ myassert(NULL == Ptr);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use nullptr
+ // CHECK-FIXES: myassert(nullptr == Ptr);
+
+ // These are bad as the null literal is buried in a macro.
+#define BLAH(X) myassert(0 == (X));
+#define BLAH2(X) myassert(NULL == (X));
+ BLAH(Ptr);
+ BLAH2(Ptr);
+
+ // Same as above but testing extra macro expansion.
+#define EXPECT_NULL(X) IS_EQ(0, X);
+#define EXPECT_NULL2(X) IS_EQ(NULL, X);
+ EXPECT_NULL(Ptr);
+ EXPECT_NULL2(Ptr);
+
+ // Almost the same as above but now null literal is not in a macro so ok
+ // to transform.
+#define EQUALS_PTR(X) IS_EQ(X, Ptr);
+ EQUALS_PTR(0);
+ // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: use nullptr
+ // CHECK-FIXES: EQUALS_PTR(nullptr);
+ EQUALS_PTR(NULL);
+ // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: use nullptr
+ // CHECK-FIXES: EQUALS_PTR(nullptr);
+
+ // Same as above but testing extra macro expansion.
+#define EQUALS_PTR_I(X) EQUALS_PTR(X)
+ EQUALS_PTR_I(0);
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use nullptr
+ // CHECK-FIXES: EQUALS_PTR_I(nullptr);
+ EQUALS_PTR_I(NULL);
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use nullptr
+ // CHECK-FIXES: EQUALS_PTR_I(nullptr);
+
+ // Ok since null literal not within macro. However, now testing macro
+ // used as arg to another macro.
+#define decorate(EXPR) side_effect(); EXPR;
+ decorate(IS_EQ(NULL, Ptr));
+ // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: use nullptr
+ // CHECK-FIXES: decorate(IS_EQ(nullptr, Ptr));
+ decorate(IS_EQ(0, Ptr));
+ // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: use nullptr
+ // CHECK-FIXES: decorate(IS_EQ(nullptr, Ptr));
+
+ // This macro causes a NullToPointer cast to happen where 0 is assigned to z
+ // but the 0 literal cannot be replaced because it is also used as an
+ // integer in the comparison.
+#define INT_AND_PTR_USE(X) do { int *z = X; if (X == 4) break; } while(false)
+ INT_AND_PTR_USE(0);
+
+ // Both uses of X in this case result in NullToPointer casts so replacement
+ // is possible.
+#define PTR_AND_PTR_USE(X) do { int *z = X; if (X != z) break; } while(false)
+ PTR_AND_PTR_USE(0);
+ // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use nullptr
+ // CHECK-FIXES: PTR_AND_PTR_USE(nullptr);
+ PTR_AND_PTR_USE(NULL);
+ // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use nullptr
+ // CHECK-FIXES: PTR_AND_PTR_USE(nullptr);
+
+#define OPTIONAL_CODE(...) __VA_ARGS__
+#define NOT_NULL dummy(0)
+#define CALL(X) X
+ OPTIONAL_CODE(NOT_NULL);
+ CALL(NOT_NULL);
+
+#define ENTRY(X) {X}
+ struct A {
+ int *Ptr;
+ } a[2] = {ENTRY(0), {0}};
+ // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use nullptr
+ // CHECK-MESSAGES: :[[@LINE-2]]:24: warning: use nullptr
+ // CHECK-FIXES: a[2] = {ENTRY(nullptr), {nullptr}};
+#undef ENTRY
+
+#define assert1(expr) (expr) ? 0 : 1
+#define assert2 assert1
+ int *p;
+ assert2(p == 0);
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use nullptr
+ // CHECK-FIXES: assert2(p == nullptr);
+ assert2(p == NULL);
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use nullptr
+ // CHECK-FIXES: assert2(p == nullptr);
+#undef assert2
+#undef assert1
+
+#define ASSERT_EQ(a, b) a == b
+#define ASSERT_NULL(x) ASSERT_EQ(static_cast<void *>(NULL), x)
+ int *pp;
+ ASSERT_NULL(pp);
+ ASSERT_NULL(NULL);
+ // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: use nullptr
+ // CHECK-FIXES: ASSERT_NULL(nullptr);
+#undef ASSERT_NULL
+#undef ASSERT_EQ
+}
+
+// One of the ancestor of the cast is a NestedNameSpecifierLoc.
+class NoDef;
+char function(NoDef *p);
+#define F(x) (sizeof(function(x)) == 1)
+template<class T, T t>
+class C {};
+C<bool, F(0)> c;
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: use nullptr
+// CHECK-FIXES: C<bool, F(nullptr)> c;
+#undef F
+
+// Test default argument expression.
+struct D {
+ explicit D(void *t, int *c = NULL) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: use nullptr
+ // CHECK-FIXES: explicit D(void *t, int *c = nullptr) {}
+};
+
+void test_default_argument() {
+ D(nullptr);
+}
+
+// Test on two neighbour CXXDefaultArgExprs nodes.
+typedef unsigned long long uint64;
+struct ZZ {
+ explicit ZZ(uint64, const uint64* = NULL) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:39: warning: use nullptr
+// CHECK-FIXES: explicit ZZ(uint64, const uint64* = nullptr) {}
+ operator bool() { return true; }
+};
+
+uint64 Hash(uint64 seed = 0) { return 0; }
+
+void f() {
+ bool a;
+ a = ZZ(Hash());
+}
+
+// Test on ignoring substituted template types.
+template<typename T>
+class TemplateClass {
+ public:
+ explicit TemplateClass(int a, T default_value = 0) {}
+
+ void h(T *default_value = 0) {}
+
+ void f(int* p = 0) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use nullptr
+// CHECK-FIXES: void f(int* p = nullptr) {}
+};
+
+void IgnoreSubstTemplateType() {
+ TemplateClass<int*> a(1);
+}
+
+// Test on casting nullptr.
+struct G {
+ explicit G(bool, const char * = NULL) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: use nullptr
+ // CHECK-FIXES: explicit G(bool, const char * = nullptr) {}
+};
+bool g(const char*);
+void test_cast_nullptr() {
+ G(g(nullptr));
+ G(g((nullptr)));
+ G(g(static_cast<char*>(nullptr)));
+ G(g(static_cast<const char*>(nullptr)));
+}
+
+// Test on recognizing multiple NULLs.
+class H {
+public:
+ H(bool);
+};
+
+#define T(expression) H(expression);
+bool h(int *, int *, int * = nullptr);
+void test_multiple_nulls() {
+ T(h(NULL, NULL));
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use nullptr
+// CHECK-MESSAGES: :[[@LINE-2]]:13: warning: use nullptr
+// CHECK-FIXES: T(h(nullptr, nullptr));
+ T(h(NULL, nullptr));
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use nullptr
+// CHECK-FIXES: T(h(nullptr, nullptr));
+ T(h(nullptr, NULL));
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use nullptr
+// CHECK-FIXES: T(h(nullptr, nullptr));
+ T(h(nullptr, nullptr));
+ T(h(NULL, NULL, NULL));
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use nullptr
+// CHECK-MESSAGES: :[[@LINE-2]]:13: warning: use nullptr
+// CHECK-MESSAGES: :[[@LINE-3]]:19: warning: use nullptr
+// CHECK-FIXES: T(h(nullptr, nullptr, nullptr));
+}
+#undef T
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-override-cxx98.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-override-cxx98.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-override-cxx98.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-override-cxx98.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,19 @@
+// RUN: %check_clang_tidy -std=c++98 %s modernize-use-override %t
+
+struct Base {
+ virtual ~Base() {}
+ virtual void a();
+ virtual void b();
+};
+
+struct SimpleCases : public Base {
+public:
+ virtual ~SimpleCases();
+ // CHECK-FIXES: {{^}} virtual ~SimpleCases();
+
+ void a();
+ // CHECK-FIXES: {{^}} void a();
+
+ virtual void b();
+ // CHECK-FIXES: {{^}} virtual void b();
+};
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-override-ms.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-override-ms.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-override-ms.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-override-ms.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,25 @@
+// RUN: %check_clang_tidy %s modernize-use-override %t -- -- -fms-extensions
+
+// This test is designed to test ms-extension __declspec(dllexport) attributes.
+#define EXPORT __declspec(dllexport)
+
+class Base {
+ virtual EXPORT void a();
+};
+
+class EXPORT InheritedBase {
+ virtual void a();
+};
+
+class Derived : public Base {
+ virtual EXPORT void a();
+ // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: prefer using 'override' or (rarely) 'final' instead of 'virtual' [modernize-use-override]
+ // CHECK-FIXES: {{^}} EXPORT void a() override;
+};
+
+class EXPORT InheritedDerived : public InheritedBase {
+ virtual void a();
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using 'override' or (rarely) 'final' instead of 'virtual' [modernize-use-override]
+ // CHECK-FIXES: {{^}} void a() override;
+};
+
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-override-no-destructors.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-override-no-destructors.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-override-no-destructors.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-override-no-destructors.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,15 @@
+// RUN: %check_clang_tidy %s modernize-use-override %t -- \
+// RUN: -config="{CheckOptions: [{key: modernize-use-override.IgnoreDestructors, value: 1}]}"
+
+struct Base {
+ virtual ~Base();
+ virtual void f();
+};
+
+struct Simple : public Base {
+ virtual ~Simple();
+ // CHECK-MESSAGES-NOT: warning:
+ virtual void f();
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using
+ // CHECK-FIXES: {{^}} void f() override;
+};
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-override-with-macro.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-override-with-macro.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-override-with-macro.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-override-with-macro.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,69 @@
+// RUN: %check_clang_tidy %s modernize-use-override %t -- \
+// RUN: -config="{CheckOptions: [{key: modernize-use-override.OverrideSpelling, value: 'OVERRIDE'},{key: modernize-use-override.FinalSpelling, value: 'FINAL'}]}"
+
+#define ABSTRACT = 0
+
+#define OVERRIDE override
+#define FINAL final
+#define VIRTUAL virtual
+#define NOT_VIRTUAL
+#define NOT_OVERRIDE
+
+#define MUST_USE_RESULT __attribute__((warn_unused_result))
+#define UNUSED __attribute__((unused))
+
+struct Base {
+ virtual ~Base() {}
+ virtual void a();
+ virtual void b();
+ virtual void c();
+ virtual void e() = 0;
+ virtual void f2() const = 0;
+ virtual void g() = 0;
+ virtual void j() const;
+ virtual void k() = 0;
+ virtual void l() const;
+};
+
+struct SimpleCases : public Base {
+public:
+ virtual ~SimpleCases();
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: prefer using 'OVERRIDE' or (rarely) 'FINAL' instead of 'virtual' [modernize-use-override]
+ // CHECK-FIXES: {{^}} ~SimpleCases() OVERRIDE;
+
+ void a();
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: annotate this function with 'OVERRIDE' or (rarely) 'FINAL' [modernize-use-override]
+ // CHECK-FIXES: {{^}} void a() OVERRIDE;
+
+ virtual void b();
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using 'OVERRIDE' or (rarely) 'FINAL' instead of 'virtual' [modernize-use-override]
+ // CHECK-FIXES: {{^}} void b() OVERRIDE;
+
+ virtual void c();
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using
+ // CHECK-FIXES: {{^}} void c() OVERRIDE;
+
+ virtual void e() = 0;
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using
+ // CHECK-FIXES: {{^}} void e() OVERRIDE = 0;
+
+ virtual void f2() const = 0;
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using
+ // CHECK-FIXES: {{^}} void f2() const OVERRIDE = 0;
+
+ virtual void g() ABSTRACT;
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using
+ // CHECK-FIXES: {{^}} void g() OVERRIDE ABSTRACT;
+
+ virtual void j() const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using
+ // CHECK-FIXES: {{^}} void j() const OVERRIDE;
+
+ virtual void k() OVERRIDE;
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'virtual' is redundant since the function is already declared 'OVERRIDE' [modernize-use-override]
+ // CHECK-FIXES: {{^}} void k() OVERRIDE;
+
+ virtual void l() const OVERRIDE;
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'virtual' is redundant since the function is already declared 'OVERRIDE' [modernize-use-override]
+ // CHECK-FIXES: {{^}} void l() const OVERRIDE;
+};
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-override-with-no-macro-inscope.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-override-with-no-macro-inscope.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-override-with-no-macro-inscope.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-override-with-no-macro-inscope.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,27 @@
+// RUN: %check_clang_tidy %s modernize-use-override %t -- \
+// RUN: -config="{CheckOptions: [{key: modernize-use-override.OverrideSpelling, value: 'CUSTOM_OVERRIDE'},{key: modernize-use-override.FinalSpelling, value: 'CUSTOM_FINAL'}]}"
+
+// As if the macro was not defined.
+//#define CUSTOM_OVERRIDE override
+//#define CUSTOM_FINAL override
+
+struct Base {
+ virtual ~Base() {}
+ virtual void a();
+ virtual void b();
+};
+
+struct SimpleCases : public Base {
+public:
+ virtual ~SimpleCases();
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: prefer using 'CUSTOM_OVERRIDE' or (rarely) 'CUSTOM_FINAL' instead of 'virtual' [modernize-use-override]
+ // CHECK-FIXES: {{^}} virtual ~SimpleCases();
+
+ void a();
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: annotate this function with 'CUSTOM_OVERRIDE' or (rarely) 'CUSTOM_FINAL' [modernize-use-override]
+ // CHECK-FIXES: {{^}} void a();
+
+ virtual void b();
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using 'CUSTOM_OVERRIDE' or (rarely) 'CUSTOM_FINAL' instead of 'virtual' [modernize-use-override]
+ // CHECK-FIXES: {{^}} virtual void b();
+};
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-override.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-override.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-override.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-override.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,318 @@
+// RUN: %check_clang_tidy %s modernize-use-override %t -- -- -fexceptions
+
+#define ABSTRACT = 0
+
+#define OVERRIDE override
+#define VIRTUAL virtual
+#define NOT_VIRTUAL
+#define NOT_OVERRIDE
+
+#define MUST_USE_RESULT __attribute__((warn_unused_result))
+#define UNUSED __attribute__((unused))
+
+struct MUST_USE_RESULT MustUseResultObject {};
+
+struct IntPair {
+ int First, Second;
+};
+
+struct Base {
+ virtual ~Base() {}
+ virtual void a();
+ virtual void b();
+ virtual void c();
+ virtual void d();
+ virtual void d2();
+ virtual void e() = 0;
+ virtual void f() = 0;
+ virtual void f2() const = 0;
+ virtual void g() = 0;
+
+ virtual void j() const;
+ virtual MustUseResultObject k();
+ virtual bool l() MUST_USE_RESULT UNUSED;
+ virtual bool n() MUST_USE_RESULT UNUSED;
+
+ virtual void m();
+ virtual void m2();
+ virtual void o() __attribute__((unused));
+
+ virtual void r() &;
+ virtual void rr() &&;
+
+ virtual void cv() const volatile;
+ virtual void cv2() const volatile;
+
+ virtual void ne() noexcept(false);
+ virtual void t() throw();
+
+ virtual void il(IntPair);
+};
+
+struct SimpleCases : public Base {
+public:
+ virtual ~SimpleCases();
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: prefer using 'override' or (rarely) 'final' instead of 'virtual' [modernize-use-override]
+ // CHECK-FIXES: {{^}} ~SimpleCases() override;
+
+ void a();
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: annotate this
+ // CHECK-FIXES: {{^}} void a() override;
+
+ void b() override;
+ // CHECK-MESSAGES-NOT: warning:
+ // CHECK-FIXES: {{^}} void b() override;
+
+ virtual void c();
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using
+ // CHECK-FIXES: {{^}} void c() override;
+
+ virtual void d() override;
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'virtual' is redundant since the function is already declared 'override'
+ // CHECK-FIXES: {{^}} void d() override;
+
+ virtual void d2() final;
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'virtual' is redundant since the function is already declared 'final'
+ // CHECK-FIXES: {{^}} void d2() final;
+
+ virtual void e() = 0;
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using
+ // CHECK-FIXES: {{^}} void e() override = 0;
+
+ virtual void f()=0;
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using
+ // CHECK-FIXES: {{^}} void f() override =0;
+
+ virtual void f2() const=0;
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using
+ // CHECK-FIXES: {{^}} void f2() const override =0;
+
+ virtual void g() ABSTRACT;
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using
+ // CHECK-FIXES: {{^}} void g() override ABSTRACT;
+
+ virtual void j() const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using
+ // CHECK-FIXES: {{^}} void j() const override;
+
+ virtual MustUseResultObject k(); // Has an implicit attribute.
+ // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: prefer using
+ // CHECK-FIXES: {{^}} MustUseResultObject k() override;
+
+ virtual bool l() MUST_USE_RESULT UNUSED;
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using
+ // CHECK-FIXES: {{^}} bool l() override MUST_USE_RESULT UNUSED;
+
+ virtual bool n() UNUSED MUST_USE_RESULT;
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using
+ // CHECK-FIXES: {{^}} bool n() override UNUSED MUST_USE_RESULT;
+
+ void m() override final;
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: 'override' is redundant since the function is already declared 'final'
+ // CHECK-FIXES: {{^}} void m() final;
+
+ virtual void m2() override final;
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'virtual' and 'override' are redundant since the function is already declared 'final'
+ // CHECK-FIXES: {{^}} void m2() final;
+
+ virtual void o() __attribute__((unused));
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using
+ // CHECK-FIXES: {{^}} void o() override __attribute__((unused));
+
+ virtual void ne() noexcept(false);
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using
+ // CHECK-FIXES: {{^}} void ne() noexcept(false) override;
+
+ virtual void t() throw();
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using
+ // CHECK-FIXES: {{^}} void t() throw() override;
+};
+
+// CHECK-MESSAGES-NOT: warning:
+
+void SimpleCases::c() {}
+// CHECK-FIXES: {{^}}void SimpleCases::c() {}
+
+SimpleCases::~SimpleCases() {}
+// CHECK-FIXES: {{^}}SimpleCases::~SimpleCases() {}
+
+struct DefaultedDestructor : public Base {
+ DefaultedDestructor() {}
+ virtual ~DefaultedDestructor() = default;
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: prefer using
+ // CHECK-FIXES: {{^}} ~DefaultedDestructor() override = default;
+};
+
+struct FinalSpecified : public Base {
+public:
+ virtual ~FinalSpecified() final;
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: 'virtual' is redundant since the function is already declared 'final'
+ // CHECK-FIXES: {{^}} ~FinalSpecified() final;
+
+ void b() final;
+ // CHECK-MESSAGES-NOT: warning:
+ // CHECK-FIXES: {{^}} void b() final;
+
+ virtual void d() final;
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'virtual' is redundant
+ // CHECK-FIXES: {{^}} void d() final;
+
+ virtual void e() final = 0;
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'virtual' is redundant
+ // CHECK-FIXES: {{^}} void e() final = 0;
+
+ virtual void j() const final;
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'virtual' is redundant
+ // CHECK-FIXES: {{^}} void j() const final;
+
+ virtual bool l() final MUST_USE_RESULT UNUSED;
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'virtual' is redundant
+ // CHECK-FIXES: {{^}} bool l() final MUST_USE_RESULT UNUSED;
+};
+
+struct InlineDefinitions : public Base {
+public:
+ virtual ~InlineDefinitions() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: prefer using
+ // CHECK-FIXES: {{^}} ~InlineDefinitions() override {}
+
+ void a() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: annotate this
+ // CHECK-FIXES: {{^}} void a() override {}
+
+ void b() override {}
+ // CHECK-MESSAGES-NOT: warning:
+ // CHECK-FIXES: {{^}} void b() override {}
+
+ virtual void c()
+ {}
+ // CHECK-MESSAGES: :[[@LINE-2]]:16: warning: prefer using
+ // CHECK-FIXES: {{^}} void c() override
+
+ virtual void d() override {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'virtual' is redundant
+ // CHECK-FIXES: {{^}} void d() override {}
+
+ virtual void j() const
+ {}
+ // CHECK-MESSAGES: :[[@LINE-2]]:16: warning: prefer using
+ // CHECK-FIXES: {{^}} void j() const override
+
+ virtual MustUseResultObject k() {} // Has an implicit attribute.
+ // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: prefer using
+ // CHECK-FIXES: {{^}} MustUseResultObject k() override {}
+
+ virtual bool l() MUST_USE_RESULT UNUSED {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using
+ // CHECK-FIXES: {{^}} bool l() override MUST_USE_RESULT UNUSED {}
+
+ virtual void r() &
+ {}
+ // CHECK-MESSAGES: :[[@LINE-2]]:16: warning: prefer using
+ // CHECK-FIXES: {{^}} void r() & override
+
+ virtual void rr() &&
+ {}
+ // CHECK-MESSAGES: :[[@LINE-2]]:16: warning: prefer using
+ // CHECK-FIXES: {{^}} void rr() && override
+
+ virtual void cv() const volatile
+ {}
+ // CHECK-MESSAGES: :[[@LINE-2]]:16: warning: prefer using
+ // CHECK-FIXES: {{^}} void cv() const volatile override
+
+ virtual void cv2() const volatile // some comment
+ {}
+ // CHECK-MESSAGES: :[[@LINE-2]]:16: warning: prefer using
+ // CHECK-FIXES: {{^}} void cv2() const volatile override // some comment
+};
+
+struct DefaultArguments : public Base {
+ // Tests for default arguments (with initializer lists).
+ // Make sure the override fix is placed after the argument list.
+ void il(IntPair p = {1, (2 + (3))}) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: annotate this
+ // CHECK-FIXES: {{^}} void il(IntPair p = {1, (2 + (3))}) override {}
+};
+
+struct Macros : public Base {
+ // Tests for 'virtual' and 'override' being defined through macros. Basically
+ // give up for now.
+ NOT_VIRTUAL void a() NOT_OVERRIDE;
+ // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: annotate this
+ // CHECK-FIXES: {{^}} NOT_VIRTUAL void a() override NOT_OVERRIDE;
+
+ VIRTUAL void b() NOT_OVERRIDE;
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using
+ // CHECK-FIXES: {{^}} VIRTUAL void b() override NOT_OVERRIDE;
+
+ NOT_VIRTUAL void c() OVERRIDE;
+ // CHECK-MESSAGES-NOT: warning:
+ // CHECK-FIXES: {{^}} NOT_VIRTUAL void c() OVERRIDE;
+
+ VIRTUAL void d() OVERRIDE;
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'virtual' is redundant
+ // CHECK-FIXES: {{^}} VIRTUAL void d() OVERRIDE;
+
+#define FUNC(return_type, name) return_type name()
+ FUNC(void, e);
+ // CHECK-FIXES: {{^}} FUNC(void, e);
+
+#define F virtual void f();
+ F
+ // CHECK-FIXES: {{^}} F
+
+ VIRTUAL void g() OVERRIDE final;
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'virtual' and 'override' are redundant
+ // CHECK-FIXES: {{^}} VIRTUAL void g() final;
+};
+
+// Tests for templates.
+template <typename T> struct TemplateBase {
+ virtual void f(T t);
+};
+
+template <typename T> struct DerivedFromTemplate : public TemplateBase<T> {
+ virtual void f(T t);
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using
+ // CHECK-FIXES: {{^}} void f(T t) override;
+};
+void f() { DerivedFromTemplate<int>().f(2); }
+
+template <class C>
+struct UnusedMemberInstantiation : public C {
+ virtual ~UnusedMemberInstantiation() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: prefer using
+ // CHECK-FIXES: {{^}} ~UnusedMemberInstantiation() override {}
+};
+struct IntantiateWithoutUse : public UnusedMemberInstantiation<Base> {};
+
+struct Base2 {
+ virtual ~Base2() {}
+ virtual void a();
+};
+
+// The OverrideAttr isn't propagated to specializations in all cases. Make sure
+// we don't add "override" a second time.
+template <int I>
+struct MembersOfSpecializations : public Base2 {
+ void a() override;
+ // CHECK-MESSAGES-NOT: warning:
+ // CHECK-FIXES: {{^}} void a() override;
+};
+template <> void MembersOfSpecializations<3>::a() {}
+void ff() { MembersOfSpecializations<3>().a(); };
+
+// In case try statement is used as a method body,
+// make sure that override fix is placed before try keyword.
+struct TryStmtAsBody : public Base {
+ void a() try
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: annotate this
+ // CHECK-FIXES: {{^}} void a() override try
+ { b(); } catch(...) { c(); }
+
+ virtual void d() try
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using
+ // CHECK-FIXES: {{^}} void d() override try
+ { e(); } catch(...) { f(); }
+};
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-trailing-return-type.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-trailing-return-type.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-trailing-return-type.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-trailing-return-type.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,565 @@
+// RUN: %check_clang_tidy -std=c++14,c++17 %s modernize-use-trailing-return-type %t -- -- -fdeclspec -fexceptions
+// FIXME: Fix the checker to work in C++2a mode, it is performing a
+// use-of-uninitialized-value.
+
+namespace std {
+ template <typename T>
+ class vector;
+
+ template <typename T, int N>
+ class array;
+
+ class string;
+
+ template <typename T>
+ auto declval() -> T;
+}
+
+//
+// Functions
+//
+
+int f();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto f() -> int;{{$}}
+int ((f))();
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto ((f))() -> int;{{$}}
+int f(int);
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto f(int) -> int;{{$}}
+int f(int arg);
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto f(int arg) -> int;{{$}}
+int f(int arg1, int arg2, int arg3);
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto f(int arg1, int arg2, int arg3) -> int;{{$}}
+int f(int arg1, int arg2, int arg3, ...);
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto f(int arg1, int arg2, int arg3, ...) -> int;{{$}}
+template <typename T> int f(T t);
+// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}template <typename T> auto f(T t) -> int;{{$}}
+
+//
+// Functions with formatting
+//
+
+int a1() { return 42; }
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto a1() -> int { return 42; }{{$}}
+int a2() {
+ return 42;
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto a2() -> int {{{$}}
+int a3()
+{
+ return 42;
+}
+// CHECK-MESSAGES: :[[@LINE-4]]:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto a3() -> int{{$}}
+int a4(int arg ) ;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto a4(int arg ) -> int ;{{$}}
+int a5
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto a5{{$}}
+(int arg);
+// CHECK-FIXES: {{^}}(int arg) -> int;{{$}}
+const
+int
+*
+a7
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+()
+// CHECK-FIXES: {{^}}() -> const{{$}}
+// CHECK-FIXES: {{^}}int{{$}}
+// CHECK-FIXES: {{^}}*{{$}}
+;
+
+int*a7(int arg);
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto a7(int arg) -> int*;{{$}}
+template<template <typename> class C>
+C<int>a8(int arg);
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto a8(int arg) -> C<int>;{{$}}
+
+
+//
+// Functions with qualifiers and specifiers
+//
+
+inline int d1(int arg);
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}inline auto d1(int arg) -> int;{{$}}
+extern "C" int d2(int arg);
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}extern "C" auto d2(int arg) -> int;{{$}}
+inline int d3(int arg) noexcept(true);
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}inline auto d3(int arg) noexcept(true) -> int;{{$}}
+inline int d4(int arg) try { } catch(...) { }
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}inline auto d4(int arg) -> int try { } catch(...) { }{{$}}
+int d5(int arg) throw();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto d5(int arg) throw() -> int;{{$}}
+static int d6(int arg);
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}static auto d6(int arg) -> int;{{$}}
+int static d6(int arg);
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto static d6(int arg) -> int;{{$}}
+unsigned static int d7(int arg);
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}static auto d7(int arg) -> unsigned int;{{$}}
+const long static int volatile constexpr unsigned inline long d8(int arg);
+// CHECK-MESSAGES: :[[@LINE-1]]:63: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}static constexpr inline auto d8(int arg) -> const long int volatile unsigned long;{{$}}
+int constexpr d9();
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto constexpr d9() -> int;{{$}}
+inline int constexpr d10();
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}inline auto constexpr d10() -> int;{{$}}
+unsigned constexpr int d11();
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}constexpr auto d11() -> unsigned int;{{$}}
+unsigned extern int d13();
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}extern auto d13() -> unsigned int;{{$}}
+int static& d14();
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}static auto d14() -> int &;{{$}}
+class DDD {
+ int friend unsigned m1();
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}} friend auto m1() -> int unsigned;{{$}}
+ int friend unsigned m1() { return 0; }
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}} friend auto m1() -> int unsigned { return 0; }{{$}}
+ const long int friend volatile constexpr unsigned inline long m2();
+// CHECK-MESSAGES: :[[@LINE-1]]:67: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}} friend constexpr inline auto m2() -> const long int volatile unsigned long;{{$}}
+ int virtual unsigned m3();
+// CHECK-MESSAGES: :[[@LINE-1]]:26: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}} virtual auto m3() -> int unsigned;{{$}}
+ template <typename T>
+ int friend unsigned m4();
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}} friend auto m4() -> int unsigned;{{$}}
+};
+
+//
+// Functions in namespaces
+//
+
+namespace N {
+ int e1();
+}
+// CHECK-MESSAGES: :[[@LINE-2]]:9: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}} auto e1() -> int;{{$}}
+int N::e1() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto N::e1() -> int {}{{$}}
+
+//
+// Functions with unsupported return types
+//
+int (*e3())(double);
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}int (*e3())(double);{{$}}
+struct A;
+int A::* e5();
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}int A::* e5();{{$}}
+int std::vector<std::string>::* e6();
+// CHECK-MESSAGES: :[[@LINE-1]]:33: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}int std::vector<std::string>::* e6();{{$}}
+int (std::vector<std::string>::*e7())(double);
+// CHECK-MESSAGES: :[[@LINE-1]]:33: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}int (std::vector<std::string>::*e7())(double);{{$}}
+
+//
+// Functions with complex return types
+//
+
+inline volatile const std::vector<std::string> e2();
+// CHECK-MESSAGES: :[[@LINE-1]]:48: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}inline auto e2() -> volatile const std::vector<std::string>;{{$}}
+inline const std::vector<std::string> volatile e2();
+// CHECK-MESSAGES: :[[@LINE-1]]:48: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}inline auto e2() -> const std::vector<std::string> volatile;{{$}}
+inline std::vector<std::string> const volatile e2();
+// CHECK-MESSAGES: :[[@LINE-1]]:48: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}inline auto e2() -> std::vector<std::string> const volatile;{{$}}
+int* e8();
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto e8() -> int*;{{$}}
+static const char* e9(void* user_data);
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}static auto e9(void* user_data) -> const char*;{{$}}
+static const char* const e10(void* user_data);
+// CHECK-MESSAGES: :[[@LINE-1]]:26: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}static auto e10(void* user_data) -> const char* const;{{$}}
+static const char** volatile * const & e11(void* user_data);
+// CHECK-MESSAGES: :[[@LINE-1]]:40: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}static auto e11(void* user_data) -> const char** volatile * const &;{{$}}
+static const char* const * const * const e12(void* user_data);
+// CHECK-MESSAGES: :[[@LINE-1]]:42: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}static auto e12(void* user_data) -> const char* const * const * const;{{$}}
+struct A e13();
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto e13() -> struct A;{{$}}
+
+//
+// decltype (unsupported if top level expression)
+//
+
+decltype(1 + 2) dec1() { return 1 + 2; }
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// TODO: source range of DecltypeTypeLoc not yet implemented
+// _HECK-FIXES: {{^}}auto dec1() -> decltype(1 + 2) { return 1 + 2; }{{$}}
+template <typename F, typename T>
+decltype(std::declval<F>(std::declval<T>)) dec2(F f, T t) { return f(t); }
+// CHECK-MESSAGES: :[[@LINE-1]]:44: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// TODO: source range of DecltypeTypeLoc not yet implemented
+// _HECK-FIXES: {{^}}auto dec2(F f, T t) -> decltype(std::declval<F>(std::declval<T>)) { return f(t); }{{$}}
+template <typename T>
+typename decltype(std::declval<T>())::value_type dec3();
+// CHECK-MESSAGES: :[[@LINE-1]]:50: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto dec3() -> typename decltype(std::declval<T>())::value_type;{{$}}
+template <typename T>
+decltype(std::declval<T>())* dec4();
+// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto dec4() -> decltype(std::declval<T>())*;{{$}}
+
+//
+// Methods
+//
+
+struct B {
+ B& operator=(const B&);
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}} auto operator=(const B&) -> B&;{{$}}
+
+ double base1(int, bool b);
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}} auto base1(int, bool b) -> double;{{$}}
+
+ virtual double base2(int, bool b) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}} virtual auto base2(int, bool b) -> double {}{{$}}
+
+ virtual float base3() const = 0;
+// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}} virtual auto base3() const -> float = 0;{{$}}
+
+ virtual float base4() volatile = 0;
+// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}} virtual auto base4() volatile -> float = 0;{{$}}
+
+ double base5(int, bool b) &&;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}} auto base5(int, bool b) && -> double;{{$}}
+
+ double base6(int, bool b) const &&;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}} auto base6(int, bool b) const && -> double;{{$}}
+
+ double base7(int, bool b) const & = delete;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}} auto base7(int, bool b) const & -> double = delete;{{$}}
+
+ double base8(int, bool b) const volatile & = delete;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}} auto base8(int, bool b) const volatile & -> double = delete;{{$}}
+
+ virtual const char * base9() const noexcept { return ""; }
+// CHECK-MESSAGES: :[[@LINE-1]]:26: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}} virtual auto base9() const noexcept -> const char * { return ""; }{{$}}
+};
+
+double B::base1(int, bool b) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto B::base1(int, bool b) -> double {}{{$}}
+
+struct D : B {
+ virtual double f1(int, bool b) final;
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}} virtual auto f1(int, bool b) -> double final;{{$}}
+
+ virtual double base2(int, bool b) override;
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}} virtual auto base2(int, bool b) -> double override;{{$}}
+
+ virtual float base3() const override final { }
+// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}} virtual auto base3() const -> float override final { }{{$}}
+
+ const char * base9() const noexcept override { return ""; }
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}} auto base9() const noexcept -> const char * override { return ""; }{{$}}
+
+ int f2() __restrict;
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}} auto f2() __restrict -> int;{{$}}
+
+ volatile int* __restrict f3() const __restrict noexcept;
+// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}} auto f3() const __restrict noexcept -> volatile int* __restrict;{{$}}
+};
+
+//
+// Functions with attributes
+//
+
+int g1() [[asdf]];
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto g1() -> int {{[[][[]}}asdf{{[]][]]}};{{$}}
+[[noreturn]] int g2();
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}{{[[][[]}}noreturn{{[]][]]}} auto g2() -> int;{{$}}
+int g2 [[noreturn]] ();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto g2 {{[[][[]}}noreturn{{[]][]]}} () -> int;{{$}}
+int unsigned g3() __attribute__((cdecl)); // FunctionTypeLoc is null.
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+int unsigned __attribute__((cdecl)) g3() ; // FunctionTypeLoc is null.
+// CHECK-MESSAGES: :[[@LINE-1]]:37: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+__attribute__((cdecl)) int unsigned g3() ; // FunctionTypeLoc is null.
+// CHECK-MESSAGES: :[[@LINE-1]]:37: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+
+//
+// Templates
+//
+template <typename Container>
+[[maybe_unused]] typename Container::value_type const volatile&& t1(Container& C) noexcept;
+// CHECK-MESSAGES: :[[@LINE-1]]:66: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}{{[[][[]}}maybe_unused{{[]][]]}} auto t1(Container& C) noexcept -> typename Container::value_type const volatile&&;{{$}}
+template <typename T>
+class BB {
+ using type = int;
+
+ template <typename U>
+ typename BB<U>::type m1();
+// CHECK-MESSAGES: :[[@LINE-1]]:26: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}} auto m1() -> typename BB<U>::type;{{$}}
+};
+
+//
+// Macros
+//
+
+#define DWORD unsigned int
+DWORD h1();
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto h1() -> DWORD;{{$}}
+#define INT int
+#define UNSIGNED unsigned
+UNSIGNED INT h2();
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto h2() -> UNSIGNED INT;{{$}}
+#define CONST const
+CONST int h3();
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto h3() -> CONST int;{{$}}
+#define ALWAYS_INLINE inline
+#define DLL_EXPORT __declspec(dllexport)
+ALWAYS_INLINE DLL_EXPORT int h4();
+// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}ALWAYS_INLINE DLL_EXPORT auto h4() -> int;{{$}}
+#define DEPRECATED __attribute__((deprecated))
+int h5() DEPRECATED;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto h5() -> int DEPRECATED;{{$}}
+int DEPRECATED h5();
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto DEPRECATED h5() -> int;{{$}}
+DEPRECATED int h5();
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}DEPRECATED auto h5() -> int;{{$}}
+[[noreturn]] [[nodiscard]] DEPRECATED DLL_EXPORT int h6 [[deprecated]] ();
+// CHECK-MESSAGES: :[[@LINE-1]]:54: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}{{[[][[]}}noreturn{{[]][]]}} {{[[][[]}}nodiscard{{[]][]]}} DEPRECATED DLL_EXPORT auto h6 {{[[][[]}}deprecated{{[]][]]}} () -> int;{{$}}
+#define FUNCTION_NAME(a, b) a##b
+int FUNCTION_NAME(foo, bar)();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto FUNCTION_NAME(foo, bar)() -> int;{{$}}
+#define DEFINE_FUNCTION_1(a, b) int a##b()
+DEFINE_FUNCTION_1(foo, bar);
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+#define DEFINE_FUNCTION_2 int foo(int arg);
+DEFINE_FUNCTION_2
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+#define DLL_EXPORT_const __declspec(dllexport) const
+DLL_EXPORT_const int h7();
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+#define DLL_EXPORT_CONST __declspec(dllexport) CONST
+DLL_EXPORT_CONST int h7();
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+
+template <typename T>
+using Real = T;
+#define PRECISION float
+Real<PRECISION> h8() { return 0.; }
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto h8() -> Real<PRECISION> { return 0.; }{{$}}
+
+#define MAYBE_UNUSED_MACRO [[maybe_unused]]
+template <typename Container>
+MAYBE_UNUSED_MACRO typename Container::value_type const volatile** const h9(Container& C) noexcept;
+// CHECK-MESSAGES: :[[@LINE-1]]:74: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}MAYBE_UNUSED_MACRO auto h9(Container& C) noexcept -> typename Container::value_type const volatile** const;{{$}}
+
+#define NOEXCEPT noexcept
+int h9(int arg) NOEXCEPT;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto h9(int arg) NOEXCEPT -> int;{{$}}
+#define STATIC_INT static int
+STATIC_INT h10();
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+#define UNSIGNED_STATIC_INT unsigned static int
+UNSIGNED_STATIC_INT h11();
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+#define STATIC static
+unsigned STATIC int h11();
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}STATIC auto h11() -> unsigned int;{{$}}
+#define STATIC_CONSTEXPR static constexpr
+unsigned STATIC_CONSTEXPR int h12();
+// CHECK-MESSAGES: :[[@LINE-1]]:31: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}STATIC_CONSTEXPR auto h12() -> unsigned int;{{$}}
+#define STATIC_CONSTEXPR_LONG static constexpr long
+unsigned STATIC_CONSTEXPR_LONG int h13();
+// CHECK-MESSAGES: :[[@LINE-1]]:36: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+DEPRECATED const int& h14();
+// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}DEPRECATED auto h14() -> const int&;{{$}}
+DEPRECATED const long static volatile unsigned& h15();
+// CHECK-MESSAGES: :[[@LINE-1]]:49: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}DEPRECATED static auto h15() -> const long volatile unsigned&;{{$}}
+#define WRAP(x) x
+WRAP(const) int& h16();
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+WRAP(CONST) int& h16();
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+#define CONCAT(a, b) a##b
+CONCAT(con, st) int& h16();
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+DEPRECATED const UNSIGNED& h17();
+// CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}DEPRECATED auto h17() -> const UNSIGNED&;{{$}}
+DEPRECATED CONST UNSIGNED STATIC& h18();
+// CHECK-MESSAGES: :[[@LINE-1]]:35: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}DEPRECATED STATIC auto h18() -> CONST UNSIGNED &;{{$}}
+#define CONST_CAT con##st
+CONST_CAT int& h19();
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto h19() -> CONST_CAT int&;{{$}}
+#define CONST_F_MACRO WRAP(CONST_CAT)
+CONST_F_MACRO int& h19();
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto h19() -> CONST_F_MACRO int&;{{$}}
+
+//
+// Name collisions
+//
+struct Object { long long value; };
+
+Object j1(unsigned Object) { return {Object * 2}; }
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}Object j1(unsigned Object) { return {Object * 2}; }{{$}}
+::Object j1(unsigned Object);
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto j1(unsigned Object) -> ::Object;{{$}}
+const Object& j2(unsigned a, int b, char Object, long l);
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}const Object& j2(unsigned a, int b, char Object, long l);{{$}}
+const struct Object& j2(unsigned a, int b, char Object, long l);
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto j2(unsigned a, int b, char Object, long l) -> const struct Object&;{{$}}
+std::vector<Object> j3(unsigned Object);
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}std::vector<Object> j3(unsigned Object);{{$}}
+std::vector<const Object> j7(unsigned Object);
+// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}std::vector<const Object> j7(unsigned Object);{{$}}
+std::vector<Object> j4(unsigned vector);
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto j4(unsigned vector) -> std::vector<Object>;{{$}}
+std::vector<::Object> j4(unsigned vector);
+// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto j4(unsigned vector) -> std::vector<::Object>;{{$}}
+std::vector<struct Object> j4(unsigned vector);
+// CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto j4(unsigned vector) -> std::vector<struct Object>;{{$}}
+std::vector<Object> j4(unsigned Vector);
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto j4(unsigned Vector) -> std::vector<Object>;{{$}}
+using std::vector;
+vector<Object> j5(unsigned vector);
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}vector<Object> j5(unsigned vector);{{$}}
+constexpr auto Size = 5;
+std::array<int, Size> j6(unsigned Size);
+// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}std::array<int, Size> j6(unsigned Size);{{$}}
+std::array<decltype(Size), (Size * 2) + 1> j8(unsigned Size);
+// CHECK-MESSAGES: :[[@LINE-1]]:44: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}std::array<decltype(Size), (Size * 2) + 1> j8(unsigned Size);{{$}}
+
+class CC {
+ int Object;
+ struct Object m();
+// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}} auto m() -> struct Object;{{$}}
+};
+Object CC::m() { return {0}; }
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto CC::m() -> Object { return {0}; }{{$}}
+class DD : public CC {
+ ::Object g();
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}} auto g() -> ::Object;{{$}}
+};
+Object DD::g() {
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}auto DD::g() -> Object {{{$}}
+ return {0};
+}
+
+
+//
+// Samples which do not trigger the check
+//
+
+auto f() -> int;
+auto f(int) -> int;
+auto f(int arg) -> int;
+auto f(int arg1, int arg2, int arg3) -> int;
+auto f(int arg1, int arg2, int arg3, ...) -> int;
+template <typename T> auto f(T t) -> int;
+
+auto ff();
+decltype(auto) fff();
+
+void c();
+void c(int arg);
+void c(int arg) { return; }
+
+struct D2 : B {
+ D2();
+ virtual ~D2();
+
+ virtual auto f1(int, bool b) -> double final;
+ virtual auto base2(int, bool b) -> double override;
+ virtual auto base3() const -> float override final { }
+
+ operator double();
+};
+
+auto l1 = [](int arg) {};
+auto l2 = [](int arg) -> double {};
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-transparent-functors.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-transparent-functors.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-transparent-functors.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-transparent-functors.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,110 @@
+// RUN: %check_clang_tidy -std=c++14-or-later %s modernize-use-transparent-functors %t
+
+namespace std {
+template<class T>
+struct remove_reference;
+
+template <class T>
+constexpr T &&forward(typename std::remove_reference<T>::type &t);
+
+template <class T>
+constexpr T &&forward(typename std::remove_reference<T>::type &&t);
+
+template <typename T = void>
+struct plus {
+ constexpr T operator()(const T &Lhs, const T &Rhs) const;
+};
+
+template <>
+struct plus<void> {
+ template <typename T, typename U>
+ constexpr auto operator()(T &&Lhs, U &&Rhs) const ->
+ decltype(forward<T>(Lhs) + forward<U>(Rhs));
+};
+
+template <typename T = void>
+struct less {
+ constexpr bool operator()(const T &Lhs, const T &Rhs) const;
+};
+
+template <>
+struct less<void> {
+ template <typename T, typename U>
+ constexpr bool operator()(T &&Lhs, U &&Rhs) const;
+};
+
+template <typename T = void>
+struct logical_not {
+ constexpr bool operator()(const T &Arg) const;
+};
+
+template <>
+struct logical_not<void> {
+ template <typename T>
+ constexpr bool operator()(T &&Arg) const;
+};
+
+template <typename T>
+class allocator;
+
+template <
+ class Key,
+ class Compare = std::less<>,
+ class Allocator = std::allocator<Key>>
+class set {};
+
+template <
+ class Key,
+ class Compare = std::less<Key>,
+ class Allocator = std::allocator<Key>>
+class set2 {};
+
+template <class InputIt, class UnaryPredicate>
+InputIt find_if(InputIt first, InputIt last,
+ UnaryPredicate p);
+
+template <class RandomIt, class Compare>
+void sort(RandomIt first, RandomIt last, Compare comp);
+
+class iterator {};
+class string {};
+}
+
+int main() {
+ using std::set;
+ using std::less;
+ std::set<int, std::less<int>> s;
+ // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: prefer transparent functors 'less<>' [modernize-use-transparent-functors]
+ // CHECK-FIXES: {{^}} std::set<int, std::less<>> s;{{$}}
+ set<int, std::less<int>> s2;
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: prefer transparent functors
+ // CHECK-FIXES: {{^}} set<int, std::less<>> s2;{{$}}
+ set<int, less<int>> s3;
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: prefer transparent functors
+ // CHECK-FIXES: {{^}} set<int, less<>> s3;{{$}}
+ std::set<int, std::less<>> s4;
+ std::set<char *, std::less<std::string>> s5;
+ std::set<set<int, less<int>>, std::less<>> s6;
+ // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: prefer transparent functors
+ // CHECK-FIXES: {{^}} std::set<set<int, less<>>, std::less<>> s6;{{$}}
+ std::iterator begin, end;
+ sort(begin, end, std::less<int>());
+ // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: prefer transparent functors
+ std::sort(begin, end, std::less<>());
+ find_if(begin, end, std::logical_not<bool>());
+ // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: prefer transparent functors
+ std::find_if(begin, end, std::logical_not<>());
+ using my_set = std::set<int, std::less<int>>;
+ // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: prefer transparent functors
+ // CHECK-FIXES: {{^}} using my_set = std::set<int, std::less<>>;{{$}}
+ using my_set2 = std::set<char*, std::less<std::string>>;
+ using my_less = std::less<std::string>;
+ find_if(begin, end, my_less());
+ // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: prefer transparent functors
+ std::set2<int> control;
+}
+
+struct ImplicitTypeLoc : std::set2<std::less<int>> {
+ // CHECK-MESSAGES: :[[@LINE-1]]:36: warning: prefer transparent functors
+ ImplicitTypeLoc() {}
+};
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-uncaught-exceptions.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-uncaught-exceptions.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-uncaught-exceptions.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-uncaught-exceptions.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,80 @@
+// RUN: %check_clang_tidy -std=c++17-or-later %s modernize-use-uncaught-exceptions %t
+
+#define MACRO std::uncaught_exception
+// CHECK-FIXES: #define MACRO std::uncaught_exception
+
+bool uncaught_exception() {
+ return 0;
+}
+
+namespace std {
+ bool uncaught_exception() {
+ return false;
+ }
+
+ int uncaught_exceptions() {
+ return 0;
+ }
+}
+
+template <typename T>
+bool doSomething(T t) {
+ return t();
+ // CHECK-FIXES: return t();
+}
+
+template <bool (*T)()>
+bool doSomething2() {
+ return T();
+ // CHECK-MESSAGES: [[@LINE-1]]:10: warning: 'std::uncaught_exception' is deprecated, use 'std::uncaught_exceptions' instead
+ // CHECK-FIXES: return T();
+}
+
+void no_warn() {
+
+ uncaught_exception();
+ // CHECK-FIXES: uncaught_exception();
+
+ doSomething(uncaught_exception);
+ // CHECK-FIXES: doSomething(uncaught_exception);
+}
+
+void warn() {
+
+ std::uncaught_exception();
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: 'std::uncaught_exception' is deprecated, use 'std::uncaught_exceptions' instead
+ // CHECK-FIXES: std::uncaught_exceptions();
+
+ using std::uncaught_exception;
+ // CHECK-MESSAGES: [[@LINE-1]]:14: warning: 'std::uncaught_exception' is deprecated, use 'std::uncaught_exceptions' instead
+ // CHECK-FIXES: using std::uncaught_exceptions;
+
+ uncaught_exception();
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: 'std::uncaught_exception' is deprecated, use 'std::uncaught_exceptions' instead
+ // CHECK-FIXES: uncaught_exceptions();
+
+ bool b{uncaught_exception()};
+ // CHECK-MESSAGES: [[@LINE-1]]:10: warning: 'std::uncaught_exception' is deprecated, use 'std::uncaught_exceptions' instead
+ // CHECK-FIXES: bool b{std::uncaught_exceptions() > 0};
+
+ MACRO();
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: 'std::uncaught_exception' is deprecated, use 'std::uncaught_exceptions' instead
+ // CHECK-FIXES: MACRO();
+
+ doSomething(std::uncaught_exception);
+ // CHECK-MESSAGES: [[@LINE-1]]:15: warning: 'std::uncaught_exception' is deprecated, use 'std::uncaught_exceptions' instead
+ // CHECK-FIXES: doSomething(std::uncaught_exception);
+
+ doSomething(uncaught_exception);
+ // CHECK-MESSAGES: [[@LINE-1]]:15: warning: 'std::uncaught_exception' is deprecated, use 'std::uncaught_exceptions' instead
+ // CHECK-FIXES: doSomething(uncaught_exception);
+
+ bool (*foo)();
+ foo = &uncaught_exception;
+ // CHECK-MESSAGES: [[@LINE-1]]:10: warning: 'std::uncaught_exception' is deprecated, use 'std::uncaught_exceptions' instead
+ // CHECK-FIXES: foo = &uncaught_exception;
+
+ doSomething2<uncaught_exception>();
+ // CHECK-MESSAGES: [[@LINE-1]]:16: warning: 'std::uncaught_exception' is deprecated, use 'std::uncaught_exceptions' instead
+ // CHECK-FIXES: doSomething2<uncaught_exception>();
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-using-macros.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-using-macros.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-using-macros.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-using-macros.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,22 @@
+// RUN: %check_clang_tidy %s modernize-use-using %t -- \
+// RUN: -config="{CheckOptions: [{key: modernize-use-using.IgnoreMacros, value: 0}]}"
+
+#define CODE typedef int INT
+
+CODE;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: #define CODE typedef int INT
+// CHECK-FIXES: CODE;
+
+struct Foo;
+#define Bar Baz
+typedef Foo Bar;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: #define Bar Baz
+// CHECK-FIXES: using Baz = Foo;
+
+#define TYPEDEF typedef
+TYPEDEF Foo Bak;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: #define TYPEDEF typedef
+// CHECK-FIXES: TYPEDEF Foo Bak;
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-using.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-using.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-using.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/modernize-use-using.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,185 @@
+// RUN: %check_clang_tidy %s modernize-use-using %t
+
+typedef int Type;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' [modernize-use-using]
+// CHECK-FIXES: using Type = int;
+
+typedef long LL;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: using LL = long;
+
+typedef int Bla;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: using Bla = int;
+
+typedef Bla Bla2;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: using Bla2 = Bla;
+
+typedef void (*type)(int, int);
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: using type = void (*)(int, int);
+
+typedef void (*type2)();
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: using type2 = void (*)();
+
+class Class {
+ typedef long long Type;
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef'
+ // CHECK-FIXES: using Type = long long;
+};
+
+typedef void (Class::*MyPtrType)(Bla) const;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: using MyPtrType = void (Class::*)(Bla)[[ATTR:( __attribute__\(\(thiscall\)\))?]] const;
+
+class Iterable {
+public:
+ class Iterator {};
+};
+
+template <typename T>
+class Test {
+ typedef typename T::iterator Iter;
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef'
+ // CHECK-FIXES: using Iter = typename T::iterator;
+};
+
+using balba = long long;
+
+union A {};
+
+typedef void (A::*PtrType)(int, int) const;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: using PtrType = void (A::*)(int, int)[[ATTR]] const;
+
+typedef Class some_class;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: using some_class = Class;
+
+typedef Class Cclass;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: using Cclass = Class;
+
+typedef Cclass cclass2;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: using cclass2 = Cclass;
+
+class cclass {};
+
+typedef void (cclass::*MyPtrType3)(Bla);
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: using MyPtrType3 = void (cclass::*)(Bla)[[ATTR]];
+
+using my_class = int;
+
+typedef Test<my_class *> another;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: using another = Test<my_class *>;
+
+typedef int* PInt;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: using PInt = int *;
+
+typedef int bla1, bla2, bla3;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: typedef int bla1, bla2, bla3;
+
+#define CODE typedef int INT
+
+CODE;
+// CHECK-FIXES: #define CODE typedef int INT
+// CHECK-FIXES: CODE;
+
+struct Foo;
+#define Bar Baz
+typedef Foo Bar;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: #define Bar Baz
+// CHECK-FIXES: using Baz = Foo;
+
+#define TYPEDEF typedef
+TYPEDEF Foo Bak;
+// CHECK-FIXES: #define TYPEDEF typedef
+// CHECK-FIXES: TYPEDEF Foo Bak;
+
+#define FOO Foo
+typedef FOO Bam;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: #define FOO Foo
+// CHECK-FIXES: using Bam = Foo;
+
+typedef struct Foo Bap;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: using Bap = struct Foo;
+
+struct Foo typedef Bap2;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: using Bap2 = struct Foo;
+
+Foo typedef Bap3;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: using Bap3 = Foo;
+
+typedef struct Unknown Baq;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: using Baq = struct Unknown;
+
+struct Unknown2 typedef Baw;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: using Baw = struct Unknown2;
+
+int typedef Bax;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: using Bax = int;
+
+typedef struct Q1 { int a; } S1;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: typedef struct Q1 { int a; } S1;
+typedef struct { int b; } S2;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: typedef struct { int b; } S2;
+struct Q2 { int c; } typedef S3;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: struct Q2 { int c; } typedef S3;
+struct { int d; } typedef S4;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: struct { int d; } typedef S4;
+
+namespace my_space {
+ class my_cclass {};
+ typedef my_cclass FuncType;
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: using FuncType = my_cclass;
+}
+
+#define lol 4
+typedef unsigned Map[lol];
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: typedef unsigned Map[lol];
+
+typedef void (*fun_type)();
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: using fun_type = void (*)();
+
+namespace template_instantiations {
+template <typename T>
+class C {
+ protected:
+ typedef C<T> super;
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef'
+ // CHECK-FIXES: using super = C<T>;
+ virtual void f();
+
+public:
+ virtual ~C();
+};
+
+class D : public C<D> {
+ void f() override { super::f(); }
+};
+class E : public C<E> {
+ void f() override { super::f(); }
+};
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/mpi-buffer-deref.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/mpi-buffer-deref.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/mpi-buffer-deref.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/mpi-buffer-deref.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,51 @@
+// REQUIRES: static-analyzer
+// RUN: %check_clang_tidy %s mpi-buffer-deref %t -- -- -I %S/Inputs/mpi-type-mismatch
+
+#include "mpimock.h"
+
+void negativeTests() {
+ char *buf;
+ MPI_Send(&buf, 1, MPI_CHAR, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer is insufficiently dereferenced: pointer->pointer [mpi-buffer-deref]
+
+ unsigned **buf2;
+ MPI_Send(buf2, 1, MPI_UNSIGNED, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer is insufficiently dereferenced: pointer->pointer
+
+ short buf3[1][1];
+ MPI_Send(buf3, 1, MPI_SHORT, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer is insufficiently dereferenced: array->array
+
+ long double _Complex *buf4[1];
+ MPI_Send(buf4, 1, MPI_C_LONG_DOUBLE_COMPLEX, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer is insufficiently dereferenced: pointer->array
+
+ std::complex<float> *buf5[1][1];
+ MPI_Send(&buf5, 1, MPI_CXX_FLOAT_COMPLEX, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer is insufficiently dereferenced: pointer->array->array->pointer
+}
+
+void positiveTests() {
+ char buf;
+ MPI_Send(&buf, 1, MPI_CHAR, 0, 0, MPI_COMM_WORLD);
+
+ unsigned *buf2;
+ MPI_Send(buf2, 1, MPI_UNSIGNED, 0, 0, MPI_COMM_WORLD);
+
+ short buf3[1][1];
+ MPI_Send(buf3[0], 1, MPI_SHORT, 0, 0, MPI_COMM_WORLD);
+
+ long double _Complex *buf4[1];
+ MPI_Send(*buf4, 1, MPI_C_LONG_DOUBLE_COMPLEX, 0, 0, MPI_COMM_WORLD);
+
+ long double _Complex buf5[1];
+ MPI_Send(buf5, 1, MPI_C_LONG_DOUBLE_COMPLEX, 0, 0, MPI_COMM_WORLD);
+
+ std::complex<float> *buf6[1][1];
+ MPI_Send(*buf6[0], 1, MPI_CXX_FLOAT_COMPLEX, 0, 0, MPI_COMM_WORLD);
+
+ // Referencing an array with '&' is valid, as this also points to the
+ // beginning of the array.
+ long double _Complex buf7[1];
+ MPI_Send(&buf7, 1, MPI_C_LONG_DOUBLE_COMPLEX, 0, 0, MPI_COMM_WORLD);
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/mpi-type-mismatch.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/mpi-type-mismatch.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/mpi-type-mismatch.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/mpi-type-mismatch.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,256 @@
+// REQUIRES: static-analyzer
+// RUN: %check_clang_tidy %s mpi-type-mismatch %t -- -- -I %S/Inputs/mpi-type-mismatch
+
+#include "mpimock.h"
+
+void charNegativeTest() {
+ int buf;
+ MPI_Send(&buf, 1, MPI_CHAR, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'int' does not match the MPI datatype 'MPI_CHAR'
+
+ short buf2;
+ MPI_Send(&buf2, 1, MPI_CHAR, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'short' does not match the MPI datatype 'MPI_CHAR'
+
+ long buf3;
+ MPI_Send(&buf3, 1, MPI_CHAR, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'long' does not match the MPI datatype 'MPI_CHAR'
+
+ int8_t buf4;
+ MPI_Send(&buf4, 1, MPI_CHAR, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'int8_t' does not match the MPI datatype 'MPI_CHAR'
+
+ uint16_t buf5;
+ MPI_Send(&buf5, 1, MPI_CHAR, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'uint16_t' does not match the MPI datatype 'MPI_CHAR'
+
+ long double _Complex buf6;
+ MPI_Send(&buf6, 1, MPI_CHAR, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'long double _Complex' does not match the MPI datatype 'MPI_CHAR'
+
+ std::complex<float> buf7;
+ MPI_Send(&buf7, 1, MPI_CHAR, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'complex<float>' does not match the MPI datatype 'MPI_CHAR'
+}
+
+void intNegativeTest() {
+ unsigned char buf;
+ MPI_Send(&buf, 1, MPI_INT, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'unsigned char' does not match the MPI datatype 'MPI_INT'
+
+ unsigned buf2;
+ MPI_Send(&buf2, 1, MPI_INT, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'unsigned int' does not match the MPI datatype 'MPI_INT'
+
+ short buf3;
+ MPI_Send(&buf3, 1, MPI_INT, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'short' does not match the MPI datatype 'MPI_INT'
+
+ long buf4;
+ MPI_Send(&buf4, 1, MPI_INT, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'long' does not match the MPI datatype 'MPI_INT'
+
+ int8_t buf5;
+ MPI_Send(&buf5, 1, MPI_INT, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'int8_t' does not match the MPI datatype 'MPI_INT'
+
+ uint16_t buf6;
+ MPI_Send(&buf6, 1, MPI_INT, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'uint16_t' does not match the MPI datatype 'MPI_INT'
+
+ long double _Complex buf7;
+ MPI_Send(&buf7, 1, MPI_INT, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'long double _Complex' does not match the MPI datatype 'MPI_INT'
+
+ std::complex<float> buf8;
+ MPI_Send(&buf8, 1, MPI_INT, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'complex<float>' does not match the MPI datatype 'MPI_INT'
+}
+
+void longNegativeTest() {
+ char buf;
+ MPI_Send(&buf, 1, MPI_LONG, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'char' does not match the MPI datatype 'MPI_LONG'
+
+ unsigned buf2;
+ MPI_Send(&buf2, 1, MPI_LONG, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'unsigned int' does not match the MPI datatype 'MPI_LONG'
+
+ unsigned short buf3;
+ MPI_Send(&buf3, 1, MPI_LONG, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'unsigned short' does not match the MPI datatype 'MPI_LONG'
+
+ unsigned long buf4;
+ MPI_Send(&buf4, 1, MPI_LONG, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'unsigned long' does not match the MPI datatype 'MPI_LONG'
+
+ int8_t buf5;
+ MPI_Send(&buf5, 1, MPI_LONG, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'int8_t' does not match the MPI datatype 'MPI_LONG'
+
+ uint16_t buf6;
+ MPI_Send(&buf6, 1, MPI_LONG, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'uint16_t' does not match the MPI datatype 'MPI_LONG'
+
+ long double _Complex buf7;
+ MPI_Send(&buf7, 1, MPI_LONG, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'long double _Complex' does not match the MPI datatype 'MPI_LONG'
+
+ std::complex<float> buf8;
+ MPI_Send(&buf8, 1, MPI_LONG, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'complex<float>' does not match the MPI datatype 'MPI_LONG'
+}
+
+void int8_tNegativeTest() {
+ char buf;
+ MPI_Send(&buf, 1, MPI_INT8_T, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'char' does not match the MPI datatype 'MPI_INT8_T'
+
+ unsigned buf2;
+ MPI_Send(&buf2, 1, MPI_INT8_T, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'unsigned int' does not match the MPI datatype 'MPI_INT8_T'
+
+ short buf3;
+ MPI_Send(&buf3, 1, MPI_INT8_T, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'short' does not match the MPI datatype 'MPI_INT8_T'
+
+ unsigned long buf4;
+ MPI_Send(&buf4, 1, MPI_INT8_T, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'unsigned long' does not match the MPI datatype 'MPI_INT8_T'
+
+ uint8_t buf5;
+ MPI_Send(&buf5, 1, MPI_INT8_T, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'uint8_t' does not match the MPI datatype 'MPI_INT8_T'
+
+ uint16_t buf6;
+ MPI_Send(&buf6, 1, MPI_INT8_T, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'uint16_t' does not match the MPI datatype 'MPI_INT8_T'
+
+ long double _Complex buf7;
+ MPI_Send(&buf7, 1, MPI_INT8_T, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'long double _Complex' does not match the MPI datatype 'MPI_INT8_T'
+
+ std::complex<float> buf8;
+ MPI_Send(&buf8, 1, MPI_INT8_T, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'complex<float>' does not match the MPI datatype 'MPI_INT8_T'
+}
+
+void complex_c_long_double_complexNegativeTest() {
+ char buf;
+ MPI_Send(&buf, 1, MPI_C_LONG_DOUBLE_COMPLEX, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'char' does not match the MPI datatype 'MPI_C_LONG_DOUBLE_COMPLEX'
+
+ unsigned buf2;
+ MPI_Send(&buf2, 1, MPI_C_LONG_DOUBLE_COMPLEX, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'unsigned int' does not match the MPI datatype 'MPI_C_LONG_DOUBLE_COMPLEX'
+
+ short buf3;
+ MPI_Send(&buf3, 1, MPI_C_LONG_DOUBLE_COMPLEX, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'short' does not match the MPI datatype 'MPI_C_LONG_DOUBLE_COMPLEX'
+
+ unsigned long buf4;
+ MPI_Send(&buf4, 1, MPI_C_LONG_DOUBLE_COMPLEX, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'unsigned long' does not match the MPI datatype 'MPI_C_LONG_DOUBLE_COMPLEX'
+
+ uint8_t buf5;
+ MPI_Send(&buf5, 1, MPI_C_LONG_DOUBLE_COMPLEX, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'uint8_t' does not match the MPI datatype 'MPI_C_LONG_DOUBLE_COMPLEX'
+
+ uint16_t buf6;
+ MPI_Send(&buf6, 1, MPI_C_LONG_DOUBLE_COMPLEX, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'uint16_t' does not match the MPI datatype 'MPI_C_LONG_DOUBLE_COMPLEX'
+
+ double _Complex buf7;
+ MPI_Send(&buf7, 1, MPI_C_LONG_DOUBLE_COMPLEX, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'double _Complex' does not match the MPI datatype 'MPI_C_LONG_DOUBLE_COMPLEX'
+
+ std::complex<float> buf8;
+ MPI_Send(&buf8, 1, MPI_C_LONG_DOUBLE_COMPLEX, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'complex<float>' does not match the MPI datatype 'MPI_C_LONG_DOUBLE_COMPLEX'
+}
+
+void complex_cxx_float_complexNegativeTest() {
+ char buf;
+ MPI_Send(&buf, 1, MPI_CXX_FLOAT_COMPLEX, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'char' does not match the MPI datatype 'MPI_CXX_FLOAT_COMPLEX'
+
+ unsigned buf2;
+ MPI_Send(&buf2, 1, MPI_CXX_FLOAT_COMPLEX, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'unsigned int' does not match the MPI datatype 'MPI_CXX_FLOAT_COMPLEX'
+
+ short buf3;
+ MPI_Send(&buf3, 1, MPI_CXX_FLOAT_COMPLEX, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'short' does not match the MPI datatype 'MPI_CXX_FLOAT_COMPLEX'
+
+ unsigned long buf4;
+ MPI_Send(&buf4, 1, MPI_CXX_FLOAT_COMPLEX, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'unsigned long' does not match the MPI datatype 'MPI_CXX_FLOAT_COMPLEX'
+
+ uint8_t buf5;
+ MPI_Send(&buf5, 1, MPI_CXX_FLOAT_COMPLEX, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'uint8_t' does not match the MPI datatype 'MPI_CXX_FLOAT_COMPLEX'
+
+ uint16_t buf6;
+ MPI_Send(&buf6, 1, MPI_CXX_FLOAT_COMPLEX, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'uint16_t' does not match the MPI datatype 'MPI_CXX_FLOAT_COMPLEX'
+
+ double _Complex buf7;
+ MPI_Send(&buf7, 1, MPI_CXX_FLOAT_COMPLEX, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'double _Complex' does not match the MPI datatype 'MPI_CXX_FLOAT_COMPLEX'
+
+ std::complex<double> buf8;
+ MPI_Send(&buf8, 1, MPI_CXX_FLOAT_COMPLEX, 0, 0, MPI_COMM_WORLD);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: buffer type 'complex<double>' does not match the MPI datatype 'MPI_CXX_FLOAT_COMPLEX'
+}
+
+void skippedTypesTests() {
+ // typedefs, user defined MPI and nullptr types are skipped
+ typedef char CHAR;
+ CHAR buf;
+ MPI_Send(&buf, 1, MPI_CXX_FLOAT_COMPLEX, 0, 0, MPI_COMM_WORLD);
+
+ typedef unsigned UNSIGNED;
+ UNSIGNED buf2;
+ MPI_Send(&buf2, 1, MPI_CXX_FLOAT_COMPLEX, 0, 0, MPI_COMM_WORLD);
+
+#define _MPI_LONG MPI_LONG
+ int buf3;
+ MPI_Send(&buf3, 1, _MPI_LONG, 0, 0, MPI_COMM_WORLD);
+
+#define _MPI_CXX_FLOAT_COMPLEX MPI_CXX_FLOAT_COMPLEX
+ short buf4;
+ MPI_Send(&buf4, 1, _MPI_CXX_FLOAT_COMPLEX, 0, 0, MPI_COMM_WORLD);
+
+ MPI_Send(NULL, 1, MPI_LONG, 0, 0, MPI_COMM_WORLD);
+}
+
+void positiveTests() {
+ char buf;
+ MPI_Send(&buf, 1, MPI_CHAR, 0, 0, MPI_COMM_WORLD);
+
+ int buf2;
+ MPI_Send(&buf2, 1, MPI_INT, 0, 0, MPI_COMM_WORLD);
+
+ long buf3;
+ MPI_Send(&buf3, 1, MPI_LONG, 0, 0, MPI_COMM_WORLD);
+
+ int8_t buf4;
+ MPI_Send(&buf4, 1, MPI_INT8_T, 0, 0, MPI_COMM_WORLD);
+
+ long double _Complex buf5;
+ MPI_Send(&buf5, 1, MPI_C_LONG_DOUBLE_COMPLEX, 0, 0, MPI_COMM_WORLD);
+
+ std::complex<float> buf6;
+ MPI_Send(&buf6, 1, MPI_CXX_FLOAT_COMPLEX, 0, 0, MPI_COMM_WORLD);
+
+ uint8_t buf7;
+ MPI_Send(&buf7, 1, MPI_UINT8_T, 0, 0, MPI_COMM_WORLD);
+
+ uint16_t buf8;
+ MPI_Send(&buf8, 1, MPI_UINT16_T, 0, 0, MPI_COMM_WORLD);
+
+ // On some systems like PPC or ARM, 'char' is unsigned by default which is why
+ // distinct signedness for the buffer and MPI type is tolerated.
+ unsigned char buf9;
+ MPI_Send(&buf9, 1, MPI_CHAR, 0, 0, MPI_COMM_WORLD);
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/objc-avoid-nserror-init.m
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/objc-avoid-nserror-init.m?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/objc-avoid-nserror-init.m (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/objc-avoid-nserror-init.m Fri Oct 11 05:05:42 2019
@@ -0,0 +1,12 @@
+// RUN: %check_clang_tidy %s objc-avoid-nserror-init %t
+ at interface NSError
++ (instancetype)alloc;
+- (instancetype)init;
+ at end
+
+ at implementation foo
+- (void)bar {
+ NSError *error = [[NSError alloc] init];
+ // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: use errorWithDomain:code:userInfo: or initWithDomain:code:userInfo: to create a new NSError [objc-avoid-nserror-init]
+}
+ at end
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/objc-forbidden-subclassing-custom.m
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/objc-forbidden-subclassing-custom.m?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/objc-forbidden-subclassing-custom.m (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/objc-forbidden-subclassing-custom.m Fri Oct 11 05:05:42 2019
@@ -0,0 +1,39 @@
+// RUN: %check_clang_tidy %s objc-forbidden-subclassing %t \
+// RUN: -config='{CheckOptions: \
+// RUN: [{key: objc-forbidden-subclassing.ClassNames, value: "Foo;Quux"}]}' \
+// RUN: --
+
+ at interface UIImagePickerController
+ at end
+
+// Make sure custom config options replace (not add to) the default list.
+ at interface Waldo : UIImagePickerController
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:12: warning: Objective-C interface 'Waldo' subclasses 'UIImagePickerController', which is not intended to be subclassed [objc-forbidden-subclassing]
+ at end
+
+ at interface Foo
+ at end
+
+ at interface Bar : Foo
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: Objective-C interface 'Bar' subclasses 'Foo', which is not intended to be subclassed [objc-forbidden-subclassing]
+ at end
+
+// Check subclasses of subclasses.
+ at interface Baz : Bar
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: Objective-C interface 'Baz' subclasses 'Foo', which is not intended to be subclassed [objc-forbidden-subclassing]
+ at end
+
+ at interface Quux
+ at end
+
+// Check that more than one forbidden superclass can be specified.
+ at interface Xyzzy : Quux
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: Objective-C interface 'Xyzzy' subclasses 'Quux', which is not intended to be subclassed [objc-forbidden-subclassing]
+ at end
+
+ at interface Plugh
+ at end
+
+ at interface Corge : Plugh
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:12: warning: Objective-C interface 'Corge' subclasses 'Plugh', which is not intended to be subclassed [objc-forbidden-subclassing]
+ at end
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/objc-forbidden-subclassing.m
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/objc-forbidden-subclassing.m?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/objc-forbidden-subclassing.m (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/objc-forbidden-subclassing.m Fri Oct 11 05:05:42 2019
@@ -0,0 +1,21 @@
+// RUN: %check_clang_tidy %s objc-forbidden-subclassing %t
+
+ at interface UIImagePickerController
+ at end
+
+ at interface Foo : UIImagePickerController
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: Objective-C interface 'Foo' subclasses 'UIImagePickerController', which is not intended to be subclassed [objc-forbidden-subclassing]
+ at end
+
+// Check subclasses of subclasses.
+ at interface Bar : Foo
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: Objective-C interface 'Bar' subclasses 'UIImagePickerController', which is not intended to be subclassed [objc-forbidden-subclassing]
+ at end
+
+ at interface Baz
+ at end
+
+// Make sure innocent subclasses aren't caught by the check.
+ at interface Blech : Baz
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:12: warning: Objective-C interface 'Blech' subclasses 'Baz', which is not intended to be subclassed [objc-forbidden-subclassing]
+ at end
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/objc-missing-hash.m
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/objc-missing-hash.m?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/objc-missing-hash.m (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/objc-missing-hash.m Fri Oct 11 05:05:42 2019
@@ -0,0 +1,68 @@
+// RUN: %check_clang_tidy %s objc-missing-hash %t
+
+typedef _Bool BOOL;
+#define YES 1
+#define NO 0
+typedef unsigned int NSUInteger;
+typedef void *id;
+
+ at interface NSObject
+- (NSUInteger)hash;
+- (BOOL)isEqual:(id)object;
+ at end
+
+ at interface MissingHash : NSObject
+ at end
+
+ at implementation MissingHash
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: 'MissingHash' implements -isEqual: without implementing -hash [objc-missing-hash]
+
+- (BOOL)isEqual:(id)object {
+ return YES;
+}
+
+ at end
+
+ at interface HasHash : NSObject
+ at end
+
+ at implementation HasHash
+
+- (NSUInteger)hash {
+ return 0;
+}
+
+- (BOOL)isEqual:(id)object {
+ return YES;
+}
+
+ at end
+
+ at interface NSArray : NSObject
+ at end
+
+ at interface MayHaveInheritedHash : NSArray
+ at end
+
+ at implementation MayHaveInheritedHash
+
+- (BOOL)isEqual:(id)object {
+ return YES;
+}
+
+ at end
+
+ at interface AnotherRootClass
+ at end
+
+ at interface NotDerivedFromNSObject : AnotherRootClass
+ at end
+
+ at implementation NotDerivedFromNSObject
+
+- (BOOL)isEqual:(id)object {
+ return NO;
+}
+
+ at end
+
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/objc-property-declaration.m
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/objc-property-declaration.m?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/objc-property-declaration.m (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/objc-property-declaration.m Fri Oct 11 05:05:42 2019
@@ -0,0 +1,55 @@
+// RUN: %check_clang_tidy %s objc-property-declaration %t
+ at class CIColor;
+ at class NSArray;
+ at class NSData;
+ at class NSString;
+ at class UIViewController;
+
+typedef void *CGColorRef;
+
+ at interface Foo
+ at property(assign, nonatomic) int NotCamelCase;
+// CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'NotCamelCase' not using lowerCamelCase style or not prefixed in a category, according to the Apple Coding Guidelines [objc-property-declaration]
+// CHECK-FIXES: @property(assign, nonatomic) int notCamelCase;
+ at property(assign, nonatomic) int camelCase;
+ at property(strong, nonatomic) NSString *URLString;
+ at property(strong, nonatomic) NSString *bundleID;
+ at property(strong, nonatomic) NSData *RGBABytes;
+ at property(strong, nonatomic) UIViewController *notificationsVC;
+ at property(strong, nonatomic) NSString *URL_string;
+// CHECK-MESSAGES: :[[@LINE-1]]:40: warning: property name 'URL_string' not using lowerCamelCase style or not prefixed in a category, according to the Apple Coding Guidelines [objc-property-declaration]
+ at property(strong, nonatomic) NSString *supportURLsCamelCase;
+ at property(strong, nonatomic) NSString *supportURLCamelCase;
+ at property(strong, nonatomic) NSString *VCsPluralToAdd;
+ at property(assign, nonatomic) int centerX;
+ at property(assign, nonatomic) int enable2GBackgroundFetch;
+ at property(assign, nonatomic) int shouldUseCFPreferences;
+ at property(assign, nonatomic) int enableGLAcceleration;
+ at property(assign, nonatomic) int ID;
+ at property(assign, nonatomic) int hasADog;
+ at property(nonatomic, readonly) CGColorRef CGColor;
+ at property(nonatomic, readonly) CIColor *CIColor;
+ at property(nonatomic, copy) NSArray *IDs;
+ at end
+
+ at interface Foo (Bar)
+ at property(assign, nonatomic) int abc_NotCamelCase;
+// CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'abc_NotCamelCase' not using lowerCamelCase style or not prefixed in a category, according to the Apple Coding Guidelines [objc-property-declaration]
+ at property(assign, nonatomic) int abCD_camelCase;
+// CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'abCD_camelCase' not using lowerCamelCase style or not prefixed in a category, according to the Apple Coding Guidelines [objc-property-declaration]
+// CHECK-FIXES: @property(assign, nonatomic) int abcd_camelCase;
+ at property(assign, nonatomic) int abCD_NotCamelCase;
+// CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'abCD_NotCamelCase' not using lowerCamelCase style or not prefixed in a category, according to the Apple Coding Guidelines [objc-property-declaration]
+// CHECK-FIXES: @property(assign, nonatomic) int abcd_notCamelCase;
+ at property(assign, nonatomic) int wrongFormat_;
+// CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'wrongFormat_' not using lowerCamelCase style or not prefixed in a category, according to the Apple Coding Guidelines [objc-property-declaration]
+ at property(strong, nonatomic) NSString *URLStr;
+ at property(assign, nonatomic) int abc_camelCase;
+ at property(strong, nonatomic) NSString *abc_URL;
+ at property(strong, nonatomic) NSString *opac2_sourceComponent;
+ at end
+
+ at interface Foo ()
+ at property(assign, nonatomic) int abc_inClassExtension;
+// CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'abc_inClassExtension' not using lowerCamelCase style or not prefixed in a category, according to the Apple Coding Guidelines [objc-property-declaration]
+ at end
\ No newline at end of file
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/objc-super-self.m
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/objc-super-self.m?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/objc-super-self.m (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/objc-super-self.m Fri Oct 11 05:05:42 2019
@@ -0,0 +1,86 @@
+// RUN: %check_clang_tidy %s objc-super-self %t
+
+ at interface NSObject
+- (instancetype)init;
+- (instancetype)self;
+ at end
+
+ at interface NSObjectDerivedClass : NSObject
+ at end
+
+ at implementation NSObjectDerivedClass
+
+- (instancetype)init {
+ return [super self];
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious invocation of 'self' in initializer; did you mean to invoke a superclass initializer? [objc-super-self]
+// CHECK-FIXES: return [super init];
+}
+
+- (instancetype)initWithObject:(NSObject *)obj {
+ self = [super self];
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious invocation of 'self' in initializer; did you mean to invoke a superclass initializer? [objc-super-self]
+// CHECK-FIXES: self = [super init];
+ if (self) {
+ // ...
+ }
+ return self;
+}
+
+#define INITIALIZE() [super self]
+
+- (instancetype)initWithObject:(NSObject *)objc a:(int)a {
+ return INITIALIZE();
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious invocation of 'self' in initializer; did you mean to invoke a superclass initializer? [objc-super-self]
+// CHECK-FIXES: return INITIALIZE();
+}
+
+#define INITIALIZER_IMPL() return [super self]
+
+- (instancetype)initWithObject:(NSObject *)objc b:(int)b {
+ INITIALIZER_IMPL();
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: suspicious invocation of 'self' in initializer; did you mean to invoke a superclass initializer? [objc-super-self]
+// CHECK-FIXES: INITIALIZER_IMPL();
+}
+
+#define INITIALIZER_METHOD self
+
+- (instancetype)initWithObject:(NSObject *)objc c:(int)c {
+ return [super INITIALIZER_METHOD];
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious invocation of 'self' in initializer; did you mean to invoke a superclass initializer? [objc-super-self]
+// CHECK-FIXES: return [super INITIALIZER_METHOD];
+}
+
+#define RECEIVER super
+
+- (instancetype)initWithObject:(NSObject *)objc d:(int)d {
+ return [RECEIVER self];
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious invocation of 'self' in initializer; did you mean to invoke a superclass initializer? [objc-super-self]
+// CHECK-FIXES: return [RECEIVER self];
+}
+
+- (instancetype)foo {
+ return [super self];
+}
+
+- (instancetype)bar {
+ return [self self];
+}
+
+ at end
+
+ at interface RootClass
+- (instancetype)init;
+- (instancetype)self;
+ at end
+
+ at interface NotNSObjectDerivedClass : RootClass
+ at end
+
+ at implementation NotNSObjectDerivedClass
+
+- (instancetype)init {
+ return [super self];
+}
+
+ at end
+
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/openmp-exception-escape.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/openmp-exception-escape.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/openmp-exception-escape.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/openmp-exception-escape.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,132 @@
+// RUN: %check_clang_tidy %s openmp-exception-escape %t -- -extra-arg=-fopenmp=libomp -extra-arg=-fexceptions -config="{CheckOptions: [{key: openmp-exception-escape.IgnoredExceptions, value: 'ignored, ignored2'}]}" --
+
+int thrower() {
+ throw 42;
+}
+
+class ignored {};
+class ignored2 {};
+namespace std {
+class bad_alloc {};
+} // namespace std
+
+void parallel() {
+#pragma omp parallel
+ thrower();
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: an exception thrown inside of the OpenMP 'parallel' region is not caught in that same region
+}
+
+void ignore() {
+#pragma omp parallel
+ throw ignored();
+}
+
+void ignore2() {
+#pragma omp parallel
+ throw ignored2();
+}
+
+void standalone_directive() {
+#pragma omp taskwait
+ throw ignored(); // not structured block
+}
+
+void ignore_alloc() {
+#pragma omp parallel
+ throw std::bad_alloc();
+}
+
+void parallel_caught() {
+#pragma omp parallel
+ {
+ try {
+ thrower();
+ } catch (...) {
+ }
+ }
+}
+
+void for_header(const int a) {
+ // Only the body of the loop counts.
+#pragma omp for
+ for (int i = 0; i < thrower(); i++)
+ ;
+}
+
+void forloop(const int a) {
+#pragma omp for
+ for (int i = 0; i < a; i++)
+ thrower();
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: an exception thrown inside of the OpenMP 'for' region is not caught in that same region
+}
+
+void parallel_forloop(const int a) {
+#pragma omp parallel
+ {
+#pragma omp for
+ for (int i = 0; i < a; i++)
+ thrower();
+ thrower();
+ // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: an exception thrown inside of the OpenMP 'parallel' region is not caught in that same region
+ // CHECK-MESSAGES: :[[@LINE-3]]:7: warning: an exception thrown inside of the OpenMP 'for' region is not caught in that same region
+ }
+}
+
+void parallel_forloop_caught(const int a) {
+#pragma omp parallel
+ {
+#pragma omp for
+ for (int i = 0; i < a; i++) {
+ try {
+ thrower();
+ } catch (...) {
+ }
+ }
+ thrower();
+ // CHECK-MESSAGES: :[[@LINE-9]]:3: warning: an exception thrown inside of the OpenMP 'parallel' region is not caught in that same region
+ }
+}
+
+void parallel_caught_forloop(const int a) {
+#pragma omp parallel
+ {
+#pragma omp for
+ for (int i = 0; i < a; i++)
+ thrower();
+ try {
+ thrower();
+ } catch (...) {
+ }
+ // CHECK-MESSAGES: :[[@LINE-5]]:7: warning: an exception thrown inside of the OpenMP 'for' region is not caught in that same region
+ }
+}
+
+void parallel_outercaught_forloop(const int a) {
+#pragma omp parallel
+ {
+ try {
+#pragma omp for
+ for (int i = 0; i < a; i++)
+ thrower();
+ thrower();
+ } catch (...) {
+ }
+ // CHECK-MESSAGES: :[[@LINE-4]]:9: warning: an exception thrown inside of the OpenMP 'for' region is not caught in that same region
+ }
+}
+
+void parallel_outercaught_forloop_caught(const int a) {
+#pragma omp parallel
+ {
+ try {
+#pragma omp for
+ for (int i = 0; i < a; i++) {
+ try {
+ thrower();
+ } catch (...) {
+ }
+ }
+ } catch (...) {
+ }
+ }
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/openmp-use-default-none.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/openmp-use-default-none.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/openmp-use-default-none.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/openmp-use-default-none.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,160 @@
+// RUN: %check_clang_tidy %s openmp-use-default-none %t -- -- -fopenmp=libomp -fopenmp-version=40
+// RUN: %check_clang_tidy -std=c11 %s openmp-use-default-none %t -- -- -x c -fopenmp=libomp -fopenmp-version=40
+
+//----------------------------------------------------------------------------//
+// Null cases.
+//----------------------------------------------------------------------------//
+
+// 'for' directive can not have 'default' clause, no diagnostics.
+void n0(const int a) {
+#pragma omp for
+ for (int b = 0; b < a; b++)
+ ;
+}
+
+//----------------------------------------------------------------------------//
+// Single-directive positive cases.
+//----------------------------------------------------------------------------//
+
+// 'parallel' directive.
+
+// 'parallel' directive can have 'default' clause, but said clause is not
+// specified, diagnosed.
+void p0_0() {
+#pragma omp parallel
+ ;
+ // CHECK-NOTES: :[[@LINE-2]]:1: warning: OpenMP directive 'parallel' does not specify 'default' clause, consider specifying 'default(none)' clause
+}
+
+// 'parallel' directive can have 'default' clause, and said clause specified,
+// with 'none' kind, all good.
+void p0_1() {
+#pragma omp parallel default(none)
+ ;
+}
+
+// 'parallel' directive can have 'default' clause, and said clause specified,
+// but with 'shared' kind, which is not 'none', diagnose.
+void p0_2() {
+#pragma omp parallel default(shared)
+ ;
+ // CHECK-NOTES: :[[@LINE-2]]:1: warning: OpenMP directive 'parallel' specifies 'default(shared)' clause, consider using 'default(none)' clause instead
+ // CHECK-NOTES: :[[@LINE-3]]:22: note: existing 'default' clause specified here
+}
+
+// 'task' directive.
+
+// 'task' directive can have 'default' clause, but said clause is not
+// specified, diagnosed.
+void p1_0() {
+#pragma omp task
+ ;
+ // CHECK-NOTES: :[[@LINE-2]]:1: warning: OpenMP directive 'task' does not specify 'default' clause, consider specifying 'default(none)' clause
+}
+
+// 'task' directive can have 'default' clause, and said clause specified,
+// with 'none' kind, all good.
+void p1_1() {
+#pragma omp task default(none)
+ ;
+}
+
+// 'task' directive can have 'default' clause, and said clause specified,
+// but with 'shared' kind, which is not 'none', diagnose.
+void p1_2() {
+#pragma omp task default(shared)
+ ;
+ // CHECK-NOTES: :[[@LINE-2]]:1: warning: OpenMP directive 'task' specifies 'default(shared)' clause, consider using 'default(none)' clause instead
+ // CHECK-NOTES: :[[@LINE-3]]:18: note: existing 'default' clause specified here
+}
+
+// 'teams' directive. (has to be inside of 'target' directive)
+
+// 'teams' directive can have 'default' clause, but said clause is not
+// specified, diagnosed.
+void p2_0() {
+#pragma omp target
+#pragma omp teams
+ ;
+ // CHECK-NOTES: :[[@LINE-2]]:1: warning: OpenMP directive 'teams' does not specify 'default' clause, consider specifying 'default(none)' clause
+}
+
+// 'teams' directive can have 'default' clause, and said clause specified,
+// with 'none' kind, all good.
+void p2_1() {
+#pragma omp target
+#pragma omp teams default(none)
+ ;
+}
+
+// 'teams' directive can have 'default' clause, and said clause specified,
+// but with 'shared' kind, which is not 'none', diagnose.
+void p2_2() {
+#pragma omp target
+#pragma omp teams default(shared)
+ ;
+ // CHECK-NOTES: :[[@LINE-2]]:1: warning: OpenMP directive 'teams' specifies 'default(shared)' clause, consider using 'default(none)' clause instead
+ // CHECK-NOTES: :[[@LINE-3]]:19: note: existing 'default' clause specified here
+}
+
+// 'taskloop' directive.
+
+// 'taskloop' directive can have 'default' clause, but said clause is not
+// specified, diagnosed.
+void p3_0(const int a) {
+#pragma omp taskloop
+ for (int b = 0; b < a; b++)
+ ;
+ // CHECK-NOTES: :[[@LINE-3]]:1: warning: OpenMP directive 'taskloop' does not specify 'default' clause, consider specifying 'default(none)' clause
+}
+
+// 'taskloop' directive can have 'default' clause, and said clause specified,
+// with 'none' kind, all good.
+void p3_1(const int a) {
+#pragma omp taskloop default(none) shared(a)
+ for (int b = 0; b < a; b++)
+ ;
+}
+
+// 'taskloop' directive can have 'default' clause, and said clause specified,
+// but with 'shared' kind, which is not 'none', diagnose.
+void p3_2(const int a) {
+#pragma omp taskloop default(shared)
+ for (int b = 0; b < a; b++)
+ ;
+ // CHECK-NOTES: :[[@LINE-3]]:1: warning: OpenMP directive 'taskloop' specifies 'default(shared)' clause, consider using 'default(none)' clause instead
+ // CHECK-NOTES: :[[@LINE-4]]:22: note: existing 'default' clause specified here
+}
+
+//----------------------------------------------------------------------------//
+// Combined directives.
+// Let's not test every single possible permutation/combination of directives,
+// but just *one* combined directive. The rest will be the same.
+//----------------------------------------------------------------------------//
+
+// 'parallel' directive can have 'default' clause, but said clause is not
+// specified, diagnosed.
+void p4_0(const int a) {
+#pragma omp parallel for
+ for (int b = 0; b < a; b++)
+ ;
+ // CHECK-NOTES: :[[@LINE-3]]:1: warning: OpenMP directive 'parallel for' does not specify 'default' clause, consider specifying 'default(none)' clause
+}
+
+// 'parallel' directive can have 'default' clause, and said clause specified,
+// with 'none' kind, all good.
+void p4_1(const int a) {
+#pragma omp parallel for default(none) shared(a)
+ for (int b = 0; b < a; b++)
+ ;
+}
+
+// 'parallel' directive can have 'default' clause, and said clause specified,
+// but with 'shared' kind, which is not 'none', diagnose.
+void p4_2(const int a) {
+#pragma omp parallel for default(shared)
+ for (int b = 0; b < a; b++)
+ ;
+ // CHECK-NOTES: :[[@LINE-3]]:1: warning: OpenMP directive 'parallel for' specifies 'default(shared)' clause, consider using 'default(none)' clause instead
+ // CHECK-NOTES: :[[@LINE-4]]:26: note: existing 'default' clause specified here
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/performance-faster-string-find.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/performance-faster-string-find.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/performance-faster-string-find.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/performance-faster-string-find.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,110 @@
+// RUN: %check_clang_tidy %s performance-faster-string-find %t -- \
+// RUN: -config="{CheckOptions: \
+// RUN: [{key: performance-faster-string-find.StringLikeClasses, \
+// RUN: value: 'std::basic_string; ::llvm::StringRef;'}]}" --
+
+namespace std {
+template <typename Char>
+struct basic_string {
+ int find(const Char *, int = 0) const;
+ int find(const Char *, int, int) const;
+ int rfind(const Char *) const;
+ int find_first_of(const Char *) const;
+ int find_first_not_of(const Char *) const;
+ int find_last_of(const Char *) const;
+ int find_last_not_of(const Char *) const;
+};
+
+typedef basic_string<char> string;
+typedef basic_string<wchar_t> wstring;
+} // namespace std
+
+namespace llvm {
+struct StringRef {
+ int find(const char *) const;
+};
+} // namespace llvm
+
+struct NotStringRef {
+ int find(const char *);
+};
+
+void StringFind() {
+ std::string Str;
+
+ Str.find("a");
+ // CHECK-MESSAGES: [[@LINE-1]]:12: warning: 'find' called with a string literal consisting of a single character; consider using the more effective overload accepting a character [performance-faster-string-find]
+ // CHECK-FIXES: Str.find('a');
+
+ // Works with the pos argument.
+ Str.find("a", 1);
+ // CHECK-MESSAGES: [[@LINE-1]]:12: warning: 'find' called with a string literal
+ // CHECK-FIXES: Str.find('a', 1);
+
+ // Doens't work with strings smaller or larger than 1 char.
+ Str.find("");
+ Str.find("ab");
+
+ // Doesn't do anything with the 3 argument overload.
+ Str.find("a", 1, 1);
+
+ // Other methods that can also be replaced
+ Str.rfind("a");
+ // CHECK-MESSAGES: [[@LINE-1]]:13: warning: 'rfind' called with a string literal
+ // CHECK-FIXES: Str.rfind('a');
+ Str.find_first_of("a");
+ // CHECK-MESSAGES: [[@LINE-1]]:21: warning: 'find_first_of' called with a string
+ // CHECK-FIXES: Str.find_first_of('a');
+ Str.find_first_not_of("a");
+ // CHECK-MESSAGES: [[@LINE-1]]:25: warning: 'find_first_not_of' called with a
+ // CHECK-FIXES: Str.find_first_not_of('a');
+ Str.find_last_of("a");
+ // CHECK-MESSAGES: [[@LINE-1]]:20: warning: 'find_last_of' called with a string
+ // CHECK-FIXES: Str.find_last_of('a');
+ Str.find_last_not_of("a");
+ // CHECK-MESSAGES: [[@LINE-1]]:24: warning: 'find_last_not_of' called with a
+ // CHECK-FIXES: Str.find_last_not_of('a');
+
+ // std::wstring should work.
+ std::wstring WStr;
+ WStr.find(L"n");
+ // CHECK-MESSAGES: [[@LINE-1]]:13: warning: 'find' called with a string literal
+ // CHECK-FIXES: Str.find(L'n');
+ // Even with unicode that fits in one wide char.
+ WStr.find(L"\x3A9");
+ // CHECK-MESSAGES: [[@LINE-1]]:13: warning: 'find' called with a string literal
+ // CHECK-FIXES: Str.find(L'\x3A9');
+
+ // Also with other types, but only if it was specified in the options.
+ llvm::StringRef sr;
+ sr.find("x");
+ // CHECK-MESSAGES: [[@LINE-1]]:11: warning: 'find' called with a string literal
+ // CHECK-FIXES: sr.find('x');
+ NotStringRef nsr;
+ nsr.find("x");
+}
+
+
+template <typename T>
+int FindTemplateDependant(T value) {
+ return value.find("A");
+}
+template <typename T>
+int FindTemplateNotDependant(T pos) {
+ return std::string().find("A", pos);
+ // CHECK-MESSAGES: [[@LINE-1]]:29: warning: 'find' called with a string literal
+ // CHECK-FIXES: return std::string().find('A', pos);
+}
+
+int FindStr() {
+ return FindTemplateDependant(std::string()) + FindTemplateNotDependant(1);
+}
+
+#define STR_MACRO(str) str.find("A")
+#define POS_MACRO(pos) std::string().find("A",pos)
+
+int Macros() {
+ return STR_MACRO(std::string()) + POS_MACRO(1);
+ // CHECK-MESSAGES: [[@LINE-1]]:10: warning: 'find' called with a string literal
+ // CHECK-MESSAGES: [[@LINE-2]]:37: warning: 'find' called with a string literal
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/performance-for-range-copy-allowed-types.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/performance-for-range-copy-allowed-types.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/performance-for-range-copy-allowed-types.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/performance-for-range-copy-allowed-types.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,126 @@
+// RUN: %check_clang_tidy %s performance-for-range-copy %t -- \
+// RUN: -config="{CheckOptions: [{key: performance-for-range-copy.AllowedTypes, value: '[Pp]ointer$;[Pp]tr$;[Rr]ef(erence)?$'}]}" \
+// RUN: -- -fno-delayed-template-parsing
+
+template <typename T>
+struct Iterator {
+ void operator++() {}
+ const T& operator*() {
+ static T* TT = new T();
+ return *TT;
+ }
+ bool operator!=(const Iterator &) { return false; }
+ typedef const T& const_reference;
+};
+template <typename T>
+struct View {
+ T begin() { return T(); }
+ T begin() const { return T(); }
+ T end() { return T(); }
+ T end() const { return T(); }
+ typedef typename T::const_reference const_reference;
+};
+
+struct SmartPointer {
+ ~SmartPointer();
+};
+
+struct smart_pointer {
+ ~smart_pointer();
+};
+
+struct SmartPtr {
+ ~SmartPtr();
+};
+
+struct smart_ptr {
+ ~smart_ptr();
+};
+
+struct SmartReference {
+ ~SmartReference();
+};
+
+struct smart_reference {
+ ~smart_reference();
+};
+
+struct SmartRef {
+ ~SmartRef();
+};
+
+struct smart_ref {
+ ~smart_ref();
+};
+
+struct OtherType {
+ ~OtherType();
+};
+
+template <typename T> struct SomeComplexTemplate {
+ ~SomeComplexTemplate();
+};
+
+typedef SomeComplexTemplate<int> NotTooComplexRef;
+
+void negativeSmartPointer() {
+ for (auto P : View<Iterator<SmartPointer>>()) {
+ auto P2 = P;
+ }
+}
+
+void negative_smart_pointer() {
+ for (auto p : View<Iterator<smart_pointer>>()) {
+ auto p2 = p;
+ }
+}
+
+void negativeSmartPtr() {
+ for (auto P : View<Iterator<SmartPtr>>()) {
+ auto P2 = P;
+ }
+}
+
+void negative_smart_ptr() {
+ for (auto p : View<Iterator<smart_ptr>>()) {
+ auto p2 = p;
+ }
+}
+
+void negativeSmartReference() {
+ for (auto R : View<Iterator<SmartReference>>()) {
+ auto R2 = R;
+ }
+}
+
+void negative_smart_reference() {
+ for (auto r : View<Iterator<smart_reference>>()) {
+ auto r2 = r;
+ }
+}
+
+void negativeSmartRef() {
+ for (auto R : View<Iterator<SmartRef>>()) {
+ auto R2 = R;
+ }
+}
+
+void negative_smart_ref() {
+ for (auto r : View<Iterator<smart_ref>>()) {
+ auto r2 = r;
+ }
+}
+
+void positiveOtherType() {
+ for (auto O : View<Iterator<OtherType>>()) {
+ // CHECK-MESSAGES: [[@LINE-1]]:13: warning: loop variable is copied but only used as const reference; consider making it a const reference [performance-for-range-copy]
+ // CHECK-FIXES: for (const auto& O : View<Iterator<OtherType>>()) {
+ auto O2 = O;
+ }
+}
+
+void negativeNotTooComplexRef() {
+ for (NotTooComplexRef R : View<Iterator<NotTooComplexRef>>()) {
+ auto R2 = R;
+ }
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/performance-for-range-copy-warn-on-all-auto-copies.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/performance-for-range-copy-warn-on-all-auto-copies.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/performance-for-range-copy-warn-on-all-auto-copies.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/performance-for-range-copy-warn-on-all-auto-copies.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,40 @@
+// RUN: %check_clang_tidy %s performance-for-range-copy %t -- \
+// RUN: -config="{CheckOptions: [{key: "performance-for-range-copy.WarnOnAllAutoCopies", value: 1}]}"
+
+template <typename T>
+struct Iterator {
+ void operator++() {}
+ const T& operator*() {
+ static T* TT = new T();
+ return *TT;
+ }
+ bool operator!=(const Iterator &) { return false; }
+};
+template <typename T>
+struct View {
+ T begin() { return T(); }
+ T begin() const { return T(); }
+ T end() { return T(); }
+ T end() const { return T(); }
+};
+
+struct S {
+ S();
+ S(const S &);
+ ~S();
+ S &operator=(const S &);
+};
+
+void NegativeLoopVariableNotAuto() {
+ for (S S1 : View<Iterator<S>>()) {
+ S* S2 = &S1;
+ }
+}
+
+void PositiveTriggeredForAutoLoopVariable() {
+ for (auto S1 : View<Iterator<S>>()) {
+ // CHECK-MESSAGES: [[@LINE-1]]:13: warning: the loop variable's type is not a reference type; this creates a copy in each iteration; consider making this a reference [performance-for-range-copy]
+ // CHECK-FIXES: for (const auto& S1 : View<Iterator<S>>()) {
+ S* S2 = &S1;
+ }
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/performance-for-range-copy.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/performance-for-range-copy.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/performance-for-range-copy.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/performance-for-range-copy.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,272 @@
+// RUN: %check_clang_tidy %s performance-for-range-copy %t -- -- -fno-delayed-template-parsing
+
+namespace std {
+
+template <typename _Tp>
+struct remove_reference { typedef _Tp type; };
+template <typename _Tp>
+struct remove_reference<_Tp&> { typedef _Tp type; };
+template <typename _Tp>
+struct remove_reference<_Tp&&> { typedef _Tp type; };
+
+template <typename _Tp>
+constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) {
+ return static_cast<typename std::remove_reference<_Tp>::type &&>(__t);
+}
+
+} // std
+
+template <typename T>
+struct Iterator {
+ void operator++() {}
+ const T& operator*() {
+ static T* TT = new T();
+ return *TT;
+ }
+ bool operator!=(const Iterator &) { return false; }
+ typedef const T& const_reference;
+};
+template <typename T>
+struct View {
+ T begin() { return T(); }
+ T begin() const { return T(); }
+ T end() { return T(); }
+ T end() const { return T(); }
+ typedef typename T::const_reference const_reference;
+};
+
+struct ConstructorConvertible {
+};
+
+struct S {
+ S();
+ S(const S &);
+ S(const ConstructorConvertible&) {}
+ ~S();
+ S &operator=(const S &);
+};
+
+struct Convertible {
+ operator S() const {
+ return S();
+ }
+};
+
+void negativeConstReference() {
+ for (const S &S1 : View<Iterator<S>>()) {
+ }
+}
+
+void negativeUserDefinedConversion() {
+ Convertible C[0];
+ for (const S &S1 : C) {
+ }
+}
+
+void negativeImplicitConstructorConversion() {
+ ConstructorConvertible C[0];
+ for (const S &S1 : C) {
+ }
+}
+
+template <typename T>
+void uninstantiated() {
+ for (const S S1 : View<Iterator<S>>()) {}
+ // CHECK-MESSAGES: [[@LINE-1]]:16: warning: the loop variable's type is not a reference type; this creates a copy in each iteration; consider making this a reference [performance-for-range-copy]
+ // CHECK-FIXES: {{^}} for (const S& S1 : View<Iterator<S>>()) {}
+
+ // Don't warn on dependent types.
+ for (const T t1 : View<Iterator<T>>()) {
+ }
+}
+
+template <typename T>
+void instantiated() {
+ for (const S S2 : View<Iterator<S>>()) {}
+ // CHECK-MESSAGES: [[@LINE-1]]:16: warning: the loop variable's type is {{.*}}
+ // CHECK-FIXES: {{^}} for (const S& S2 : View<Iterator<S>>()) {}
+
+ for (const T T2 : View<Iterator<T>>()) {}
+ // CHECK-MESSAGES: [[@LINE-1]]:16: warning: the loop variable's type is {{.*}}
+ // CHECK-FIXES: {{^}} for (const T& T2 : View<Iterator<T>>()) {}
+}
+
+template <typename T>
+void instantiatedNegativeTypedefConstReference() {
+ for (typename T::const_reference T2 : T()) {
+ S S1 = T2;
+ }
+}
+
+void f() {
+ instantiated<int>();
+ instantiated<S>();
+ instantiatedNegativeTypedefConstReference<View<Iterator<S>>>();
+}
+
+struct Mutable {
+ Mutable() {}
+ Mutable(const Mutable &) = default;
+ Mutable(Mutable&&) = default;
+ Mutable(const Mutable &, const Mutable &) {}
+ void setBool(bool B) {}
+ bool constMethod() const {
+ return true;
+ }
+ Mutable& operator[](int I) {
+ return *this;
+ }
+ bool operator==(const Mutable &Other) const {
+ return true;
+ }
+ ~Mutable() {}
+};
+
+struct Point {
+ ~Point() {}
+ int x, y;
+};
+
+Mutable& operator<<(Mutable &Out, bool B) {
+ Out.setBool(B);
+ return Out;
+}
+
+bool operator!=(const Mutable& M1, const Mutable& M2) {
+ return false;
+}
+
+void use(const Mutable &M);
+void use(int I);
+void useTwice(const Mutable &M1, const Mutable &M2);
+void useByValue(Mutable M);
+void useByConstValue(const Mutable M);
+void mutate(Mutable *M);
+void mutate(Mutable &M);
+void onceConstOnceMutated(const Mutable &M1, Mutable &M2);
+
+void negativeVariableIsMutated() {
+ for (auto M : View<Iterator<Mutable>>()) {
+ mutate(M);
+ }
+ for (auto M : View<Iterator<Mutable>>()) {
+ mutate(&M);
+ }
+ for (auto M : View<Iterator<Mutable>>()) {
+ M.setBool(true);
+ }
+}
+
+void negativeOnceConstOnceMutated() {
+ for (auto M : View<Iterator<Mutable>>()) {
+ onceConstOnceMutated(M, M);
+ }
+}
+
+void negativeVarIsMoved() {
+ for (auto M : View<Iterator<Mutable>>()) {
+ auto Moved = std::move(M);
+ }
+}
+
+void negativeNonConstOperatorIsInvoked() {
+ for (auto NonConstOperatorInvokee : View<Iterator<Mutable>>()) {
+ auto& N = NonConstOperatorInvokee[0];
+ }
+}
+
+void negativeNonConstNonMemberOperatorInvoked() {
+ for (auto NonConstOperatorInvokee : View<Iterator<Mutable>>()) {
+ NonConstOperatorInvokee << true;
+ }
+}
+
+void negativeConstCheapToCopy() {
+ for (const int I : View<Iterator<int>>()) {
+ }
+}
+
+void negativeConstCheapToCopyTypedef() {
+ typedef const int ConstInt;
+ for (ConstInt C : View<Iterator<ConstInt>>()) {
+ }
+}
+
+void negativeCheapToCopy() {
+ for (int I : View<Iterator<int>>()) {
+ use(I);
+ }
+}
+
+void negativeCheapToCopyTypedef() {
+ typedef int Int;
+ for (Int I : View<Iterator<Int>>()) {
+ use(I);
+ }
+}
+
+void positiveOnlyConstMethodInvoked() {
+ for (auto M : View<Iterator<Mutable>>()) {
+ // CHECK-MESSAGES: [[@LINE-1]]:13: warning: loop variable is copied but only used as const reference; consider making it a const reference [performance-for-range-copy]
+ // CHECK-FIXES: for (const auto& M : View<Iterator<Mutable>>()) {
+ M.constMethod();
+ }
+}
+
+void positiveOnlyUsedAsConstArguments() {
+ for (auto UsedAsConst : View<Iterator<Mutable>>()) {
+ // CHECK-MESSAGES: [[@LINE-1]]:13: warning: loop variable is copied but only used as const reference; consider making it a const reference [performance-for-range-copy]
+ // CHECK-FIXES: for (const auto& UsedAsConst : View<Iterator<Mutable>>()) {
+ use(UsedAsConst);
+ useTwice(UsedAsConst, UsedAsConst);
+ useByValue(UsedAsConst);
+ useByConstValue(UsedAsConst);
+ }
+}
+
+void positiveOnlyAccessedFieldAsConst() {
+ for (auto UsedAsConst : View<Iterator<Point>>()) {
+ // CHECK-MESSAGES: [[@LINE-1]]:13: warning: loop variable is copied but only used as const reference; consider making it a const reference [performance-for-range-copy]
+ // CHECK-FIXES: for (const auto& UsedAsConst : View<Iterator<Point>>()) {
+ use(UsedAsConst.x);
+ use(UsedAsConst.y);
+ }
+}
+
+void positiveOnlyUsedInCopyConstructor() {
+ for (auto A : View<Iterator<Mutable>>()) {
+ // CHECK-MESSAGES: [[@LINE-1]]:13: warning: loop variable is copied but only used as const reference; consider making it a const reference [performance-for-range-copy]
+ // CHECK-FIXES: for (const auto& A : View<Iterator<Mutable>>()) {
+ Mutable Copy = A;
+ Mutable Copy2(A);
+ }
+}
+
+void positiveTwoConstConstructorArgs() {
+ for (auto A : View<Iterator<Mutable>>()) {
+ // CHECK-MESSAGES: [[@LINE-1]]:13: warning: loop variable is copied but only used as const reference; consider making it a const reference [performance-for-range-copy]
+ // CHECK-FIXES: for (const auto& A : View<Iterator<Mutable>>()) {
+ Mutable Copy(A, A);
+ }
+}
+
+void PositiveConstMemberOperatorInvoked() {
+ for (auto ConstOperatorInvokee : View<Iterator<Mutable>>()) {
+ // CHECK-MESSAGES: [[@LINE-1]]:13: warning: loop variable is copied but only used as const reference; consider making it a const reference [performance-for-range-copy]
+ // CHECK-FIXES: for (const auto& ConstOperatorInvokee : View<Iterator<Mutable>>()) {
+ bool result = ConstOperatorInvokee == Mutable();
+ }
+}
+
+void PositiveConstNonMemberOperatorInvoked() {
+ for (auto ConstOperatorInvokee : View<Iterator<Mutable>>()) {
+ // CHECK-MESSAGES: [[@LINE-1]]:13: warning: loop variable is copied but only used as const reference; consider making it a const reference [performance-for-range-copy]
+ // CHECK-FIXES: for (const auto& ConstOperatorInvokee : View<Iterator<Mutable>>()) {
+ bool result = ConstOperatorInvokee != Mutable();
+ }
+}
+
+void IgnoreLoopVariableNotUsedInLoopBody() {
+ for (auto _ : View<Iterator<S>>()) {
+ }
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/performance-implicit-conversion-in-loop.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/performance-implicit-conversion-in-loop.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/performance-implicit-conversion-in-loop.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/performance-implicit-conversion-in-loop.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,197 @@
+// RUN: %check_clang_tidy %s performance-implicit-conversion-in-loop %t
+
+// ---------- Classes used in the tests ----------
+
+// Iterator returning by value.
+template <typename T>
+struct Iterator {
+ void operator++();
+ T operator*();
+ bool operator!=(const Iterator& other);
+};
+
+// Iterator returning by reference.
+template <typename T>
+struct RefIterator {
+ void operator++();
+ T& operator*();
+ bool operator!=(const RefIterator& other);
+};
+
+// The template argument is an iterator type, and a view is an object you can
+// run a for loop on.
+template <typename T>
+struct View {
+ T begin();
+ T end();
+};
+
+// With this class, the implicit conversion is a call to the (implicit)
+// constructor of the class.
+template <typename T>
+class ImplicitWrapper {
+ public:
+ // Implicit!
+ ImplicitWrapper(const T& t);
+};
+
+// With this class, the implicit conversion is a call to the conversion
+// operators of SimpleClass and ComplexClass.
+template <typename T>
+class OperatorWrapper {
+ public:
+ OperatorWrapper() = delete;
+};
+
+struct SimpleClass {
+ int foo;
+ operator OperatorWrapper<SimpleClass>();
+};
+
+// The materialize expression is not the same when the class has a destructor,
+// so we make sure we cover that case too.
+class ComplexClass {
+ public:
+ ComplexClass();
+ ~ComplexClass();
+ operator OperatorWrapper<ComplexClass>();
+};
+
+typedef View<Iterator<SimpleClass>> SimpleView;
+typedef View<RefIterator<SimpleClass>> SimpleRefView;
+typedef View<Iterator<ComplexClass>> ComplexView;
+typedef View<RefIterator<ComplexClass>> ComplexRefView;
+
+// ---------- The test themselves ----------
+// For each test we do, in the same order, const ref, non const ref, const
+// value, non const value.
+
+void SimpleClassIterator() {
+ for (const SimpleClass& foo : SimpleView()) {}
+ // This line does not compile because a temporary cannot be assigned to a non
+ // const reference.
+ // for (SimpleClass& foo : SimpleView()) {}
+ for (const SimpleClass foo : SimpleView()) {}
+ for (SimpleClass foo : SimpleView()) {}
+}
+
+void SimpleClassRefIterator() {
+ for (const SimpleClass& foo : SimpleRefView()) {}
+ for (SimpleClass& foo : SimpleRefView()) {}
+ for (const SimpleClass foo : SimpleRefView()) {}
+ for (SimpleClass foo : SimpleRefView()) {}
+}
+
+void ComplexClassIterator() {
+ for (const ComplexClass& foo : ComplexView()) {}
+ // for (ComplexClass& foo : ComplexView()) {}
+ for (const ComplexClass foo : ComplexView()) {}
+ for (ComplexClass foo : ComplexView()) {}
+}
+
+void ComplexClassRefIterator() {
+ for (const ComplexClass& foo : ComplexRefView()) {}
+ for (ComplexClass& foo : ComplexRefView()) {}
+ for (const ComplexClass foo : ComplexRefView()) {}
+ for (ComplexClass foo : ComplexRefView()) {}
+}
+
+void ImplicitSimpleClassIterator() {
+ for (const ImplicitWrapper<SimpleClass>& foo : SimpleView()) {}
+ // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the loop variable 'foo' is different from the one returned by the iterator and generates an implicit conversion; you can either change the type to the matching one ('const SimpleClass &' but 'const auto&' is always a valid option) or remove the reference to make it explicit that you are creating a new value [performance-implicit-conversion-in-loop]
+ // for (ImplicitWrapper<SimpleClass>& foo : SimpleView()) {}
+ for (const ImplicitWrapper<SimpleClass> foo : SimpleView()) {}
+ for (ImplicitWrapper<SimpleClass> foo : SimpleView()) {}
+}
+
+void ImplicitSimpleClassRefIterator() {
+ for (const ImplicitWrapper<SimpleClass>& foo : SimpleRefView()) {}
+ // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the{{.*'const SimpleClass &'.*}}
+ // for (ImplicitWrapper<SimpleClass>& foo : SimpleRefView()) {}
+ for (const ImplicitWrapper<SimpleClass> foo : SimpleRefView()) {}
+ for (ImplicitWrapper<SimpleClass> foo : SimpleRefView()) {}
+}
+
+void ImplicitSimpleClassArray() {
+ SimpleClass array[5];
+ for (const ImplicitWrapper<SimpleClass>& foo : array) {}
+ // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the{{.*'const SimpleClass &'.*}}
+ // for (ImplicitWrapper<SimpleClass>& foo : array) {}
+ for (const ImplicitWrapper<SimpleClass> foo : array) {}
+ for (ImplicitWrapper<SimpleClass> foo : array) {}
+}
+
+void ImplicitComplexClassIterator() {
+ for (const ImplicitWrapper<ComplexClass>& foo : ComplexView()) {}
+ // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the{{.*'const ComplexClass &'.*}}
+ // for (ImplicitWrapper<ComplexClass>& foo : ComplexView()) {}
+ for (const ImplicitWrapper<ComplexClass> foo : ComplexView()) {}
+ for (ImplicitWrapper<ComplexClass> foo : ComplexView()) {}
+}
+
+void ImplicitComplexClassRefIterator() {
+ ComplexClass array[5];
+ for (const ImplicitWrapper<ComplexClass>& foo : array) {}
+ // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the{{.*'const ComplexClass &'.*}}
+ // for (ImplicitWrapper<ComplexClass>& foo : array) {}
+ for (const ImplicitWrapper<ComplexClass> foo : array) {}
+ for (ImplicitWrapper<ComplexClass> foo : array) {}
+}
+
+void ImplicitComplexClassArray() {
+ for (const ImplicitWrapper<ComplexClass>& foo : ComplexRefView()) {}
+ // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the{{.*'const ComplexClass &'.*}}
+ // for (ImplicitWrapper<ComplexClass>& foo : ComplexRefView()) {}
+ for (const ImplicitWrapper<ComplexClass> foo : ComplexRefView()) {}
+ for (ImplicitWrapper<ComplexClass> foo : ComplexRefView()) {}
+}
+
+void OperatorSimpleClassIterator() {
+ for (const OperatorWrapper<SimpleClass>& foo : SimpleView()) {}
+ // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the{{.*'const SimpleClass &'.*}}
+ // for (OperatorWrapper<SimpleClass>& foo : SimpleView()) {}
+ for (const OperatorWrapper<SimpleClass> foo : SimpleView()) {}
+ for (OperatorWrapper<SimpleClass> foo : SimpleView()) {}
+}
+
+void OperatorSimpleClassRefIterator() {
+ for (const OperatorWrapper<SimpleClass>& foo : SimpleRefView()) {}
+ // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the{{.*'const SimpleClass &'.*}}
+ // for (OperatorWrapper<SimpleClass>& foo : SimpleRefView()) {}
+ for (const OperatorWrapper<SimpleClass> foo : SimpleRefView()) {}
+ for (OperatorWrapper<SimpleClass> foo : SimpleRefView()) {}
+}
+
+void OperatorSimpleClassArray() {
+ SimpleClass array[5];
+ for (const OperatorWrapper<SimpleClass>& foo : array) {}
+ // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the{{.*'const SimpleClass &'.*}}
+ // for (OperatorWrapper<SimpleClass>& foo : array) {}
+ for (const OperatorWrapper<SimpleClass> foo : array) {}
+ for (OperatorWrapper<SimpleClass> foo : array) {}
+}
+
+void OperatorComplexClassIterator() {
+ for (const OperatorWrapper<ComplexClass>& foo : ComplexView()) {}
+ // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the{{.*'const ComplexClass &'.*}}
+ // for (OperatorWrapper<ComplexClass>& foo : ComplexView()) {}
+ for (const OperatorWrapper<ComplexClass> foo : ComplexView()) {}
+ for (OperatorWrapper<ComplexClass> foo : ComplexView()) {}
+}
+
+void OperatorComplexClassRefIterator() {
+ for (const OperatorWrapper<ComplexClass>& foo : ComplexRefView()) {}
+ // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the{{.*'const ComplexClass &'.*}}
+ // for (OperatorWrapper<ComplexClass>& foo : ComplexRefView()) {}
+ for (const OperatorWrapper<ComplexClass> foo : ComplexRefView()) {}
+ for (OperatorWrapper<ComplexClass> foo : ComplexRefView()) {}
+}
+
+void OperatorComplexClassArray() {
+ ComplexClass array[5];
+ for (const OperatorWrapper<ComplexClass>& foo : array) {}
+ // CHECK-MESSAGES: [[@LINE-1]]:{{[0-9]*}}: warning: the type of the{{.*'const ComplexClass &'.*}}
+ // for (OperatorWrapper<ComplexClass>& foo : array) {}
+ for (const OperatorWrapper<ComplexClass> foo : array) {}
+ for (OperatorWrapper<ComplexClass> foo : array) {}
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/performance-inefficient-algorithm.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/performance-inefficient-algorithm.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/performance-inefficient-algorithm.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/performance-inefficient-algorithm.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,167 @@
+// RUN: %check_clang_tidy -std=c++11,c++14 %s performance-inefficient-algorithm %t
+// FIXME: Fix the checker to work in C++17 mode.
+
+namespace std {
+template <typename T> struct less {
+ bool operator()(const T &lhs, const T &rhs) { return lhs < rhs; }
+};
+
+template <typename T> struct greater {
+ bool operator()(const T &lhs, const T &rhs) { return lhs > rhs; }
+};
+
+struct iterator_type {};
+
+template <typename K, typename Cmp = less<K>> struct set {
+ typedef iterator_type iterator;
+ iterator find(const K &k);
+ unsigned count(const K &k);
+
+ iterator begin();
+ iterator end();
+ iterator begin() const;
+ iterator end() const;
+};
+
+struct other_iterator_type {};
+
+template <typename K, typename V, typename Cmp = less<K>> struct map {
+ typedef other_iterator_type iterator;
+ iterator find(const K &k);
+ unsigned count(const K &k);
+
+ iterator begin();
+ iterator end();
+ iterator begin() const;
+ iterator end() const;
+};
+
+template <typename K, typename V> struct multimap : map<K, V> {};
+template <typename K> struct unordered_set : set<K> {};
+template <typename K, typename V> struct unordered_map : map<K, V> {};
+template <typename K> struct unordered_multiset : set<K> {};
+template <typename K, typename V> struct unordered_multimap : map<K, V> {};
+
+template <typename K, typename Cmp = less<K>> struct multiset : set<K, Cmp> {};
+
+template <typename FwIt, typename K>
+FwIt find(FwIt, FwIt end, const K &) { return end; }
+
+template <typename FwIt, typename K, typename Cmp>
+FwIt find(FwIt, FwIt end, const K &, Cmp) { return end; }
+
+template <typename FwIt, typename Pred>
+FwIt find_if(FwIt, FwIt end, Pred) { return end; }
+
+template <typename FwIt, typename K>
+unsigned count(FwIt, FwIt, const K &) { return 0; }
+
+template <typename FwIt, typename K>
+FwIt lower_bound(FwIt, FwIt end, const K &) { return end; }
+
+template <typename FwIt, typename K, typename Ord>
+FwIt lower_bound(FwIt, FwIt end, const K &, Ord) { return end; }
+}
+
+#define FIND_IN_SET(x) find(x.begin(), x.end(), 10)
+// CHECK-FIXES: #define FIND_IN_SET(x) find(x.begin(), x.end(), 10)
+
+template <typename T> void f(const T &t) {
+ std::set<int> s;
+ find(s.begin(), s.end(), 46);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this STL algorithm call should be
+ // CHECK-FIXES: {{^ }}s.find(46);{{$}}
+
+ find(t.begin(), t.end(), 46);
+ // CHECK-FIXES: {{^ }}find(t.begin(), t.end(), 46);{{$}}
+}
+
+int main() {
+ std::set<int> s;
+ auto it = std::find(s.begin(), s.end(), 43);
+ // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: this STL algorithm call should be replaced with a container method [performance-inefficient-algorithm]
+ // CHECK-FIXES: {{^ }}auto it = s.find(43);{{$}}
+ auto c = count(s.begin(), s.end(), 43);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: this STL algorithm call should be
+ // CHECK-FIXES: {{^ }}auto c = s.count(43);{{$}}
+
+#define SECOND(x, y, z) y
+ SECOND(q,std::count(s.begin(), s.end(), 22),w);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: this STL algorithm call should be
+ // CHECK-FIXES: {{^ }}SECOND(q,s.count(22),w);{{$}}
+
+ it = find_if(s.begin(), s.end(), [](int) { return false; });
+
+ std::multiset<int> ms;
+ find(ms.begin(), ms.end(), 46);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this STL algorithm call should be
+ // CHECK-FIXES: {{^ }}ms.find(46);{{$}}
+
+ const std::multiset<int> &msref = ms;
+ find(msref.begin(), msref.end(), 46);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this STL algorithm call should be
+ // CHECK-FIXES: {{^ }}msref.find(46);{{$}}
+
+ std::multiset<int> *msptr = &ms;
+ find(msptr->begin(), msptr->end(), 46);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this STL algorithm call should be
+ // CHECK-FIXES: {{^ }}msptr->find(46);{{$}}
+
+ it = std::find(s.begin(), s.end(), 43, std::greater<int>());
+ // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: different comparers used in the algorithm and the container [performance-inefficient-algorithm]
+
+ FIND_IN_SET(s);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this STL algorithm call should be
+ // CHECK-FIXES: {{^ }}FIND_IN_SET(s);{{$}}
+
+ f(s);
+
+ std::unordered_set<int> us;
+ lower_bound(us.begin(), us.end(), 10);
+ // CHECK-FIXES: {{^ }}lower_bound(us.begin(), us.end(), 10);{{$}}
+ find(us.begin(), us.end(), 10);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this STL algorithm call should be
+ // CHECK-FIXES: {{^ }}us.find(10);{{$}}
+
+ std::unordered_multiset<int> ums;
+ find(ums.begin(), ums.end(), 10);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this STL algorithm call should be
+ // CHECK-FIXES: {{^ }}ums.find(10);{{$}}
+
+ std::map<int, int> intmap;
+ find(intmap.begin(), intmap.end(), 46);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this STL algorithm call should be
+ // CHECK-FIXES: {{^ }}find(intmap.begin(), intmap.end(), 46);{{$}}
+
+ std::multimap<int, int> intmmap;
+ find(intmmap.begin(), intmmap.end(), 46);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this STL algorithm call should be
+ // CHECK-FIXES: {{^ }}find(intmmap.begin(), intmmap.end(), 46);{{$}}
+
+ std::unordered_map<int, int> umap;
+ find(umap.begin(), umap.end(), 46);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this STL algorithm call should be
+ // CHECK-FIXES: {{^ }}find(umap.begin(), umap.end(), 46);{{$}}
+
+ std::unordered_multimap<int, int> ummap;
+ find(ummap.begin(), ummap.end(), 46);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this STL algorithm call should be
+ // CHECK-FIXES: {{^ }}find(ummap.begin(), ummap.end(), 46);{{$}}
+}
+
+struct Value {
+ int value;
+};
+
+struct Ordering {
+ bool operator()(const Value &lhs, const Value &rhs) const {
+ return lhs.value < rhs.value;
+ }
+ bool operator()(int lhs, const Value &rhs) const { return lhs < rhs.value; }
+};
+
+void g(std::set<Value, Ordering> container, int value) {
+ lower_bound(container.begin(), container.end(), value, Ordering());
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this STL algorithm call should be
+ // CHECK-FIXES: {{^ }}lower_bound(container.begin(), container.end(), value, Ordering());{{$}}
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/performance-inefficient-string-concatenation.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/performance-inefficient-string-concatenation.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/performance-inefficient-string-concatenation.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/performance-inefficient-string-concatenation.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,48 @@
+// RUN: %check_clang_tidy %s performance-inefficient-string-concatenation %t
+
+namespace std {
+template <typename T>
+class basic_string {
+public:
+ basic_string() {}
+ ~basic_string() {}
+ basic_string<T> *operator+=(const basic_string<T> &) {}
+ friend basic_string<T> operator+(const basic_string<T> &, const basic_string<T> &) {}
+};
+typedef basic_string<char> string;
+typedef basic_string<wchar_t> wstring;
+}
+
+void f(std::string) {}
+std::string g(std::string) {}
+
+int main() {
+ std::string mystr1, mystr2;
+ std::wstring mywstr1, mywstr2;
+ auto myautostr1 = mystr1;
+ auto myautostr2 = mystr2;
+
+ for (int i = 0; i < 10; ++i) {
+ f(mystr1 + mystr2 + mystr1);
+ // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: string concatenation results in allocation of unnecessary temporary strings; consider using 'operator+=' or 'string::append()' instead
+ mystr1 = mystr1 + mystr2;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: string concatenation
+ mystr1 = mystr2 + mystr2 + mystr2;
+ // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: string concatenation
+ mystr1 = mystr2 + mystr1;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: string concatenation
+ mywstr1 = mywstr2 + mywstr1;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: string concatenation
+ mywstr1 = mywstr2 + mywstr2 + mywstr2;
+ // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: string concatenation
+ myautostr1 = myautostr1 + myautostr2;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: string concatenation
+
+ mywstr1 = mywstr2 + mywstr2;
+ mystr1 = mystr2 + mystr2;
+ mystr1 += mystr2;
+ f(mystr2 + mystr1);
+ mystr1 = g(mystr1);
+ }
+ return 0;
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/performance-inefficient-vector-operation.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/performance-inefficient-vector-operation.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/performance-inefficient-vector-operation.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/performance-inefficient-vector-operation.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,361 @@
+// RUN: %check_clang_tidy %s performance-inefficient-vector-operation %t -- \
+// RUN: -format-style=llvm \
+// RUN: -config='{CheckOptions: \
+// RUN: [{key: performance-inefficient-vector-operation.EnableProto, value: 1}]}'
+
+namespace std {
+
+typedef int size_t;
+
+template<class E> class initializer_list {
+public:
+ using value_type = E;
+ using reference = E&;
+ using const_reference = const E&;
+ using size_type = size_t;
+ using iterator = const E*;
+ using const_iterator = const E*;
+ initializer_list();
+ size_t size() const; // number of elements
+ const E* begin() const; // first element
+ const E* end() const; // one past the last element
+};
+
+// initializer list range access
+template<class E> const E* begin(initializer_list<E> il);
+template<class E> const E* end(initializer_list<E> il);
+
+template <class T>
+class vector {
+ public:
+ typedef T* iterator;
+ typedef const T* const_iterator;
+ typedef T& reference;
+ typedef const T& const_reference;
+ typedef size_t size_type;
+
+ explicit vector();
+ explicit vector(size_type n);
+
+ void push_back(const T& val);
+
+ template <class... Args> void emplace_back(Args &&... args);
+
+ void reserve(size_t n);
+ void resize(size_t n);
+
+ size_t size();
+ const_reference operator[] (size_type) const;
+ reference operator[] (size_type);
+
+ const_iterator begin() const;
+ const_iterator end() const;
+};
+} // namespace std
+
+class Foo {
+ public:
+ explicit Foo(int);
+};
+
+class Bar {
+ public:
+ Bar(int);
+};
+
+int Op(int);
+
+namespace proto2 {
+class MessageLite {};
+class Message : public MessageLite {};
+} // namespace proto2
+
+class FooProto : public proto2::Message {
+ public:
+ int *add_x(); // repeated int x;
+ void add_x(int x);
+ void mutable_x();
+ void mutable_y();
+ int add_z() const; // optional int add_z;
+};
+
+class BarProto : public proto2::Message {
+ public:
+ int *add_x();
+ void add_x(int x);
+ void mutable_x();
+ void mutable_y();
+};
+
+void f(std::vector<int>& t) {
+ {
+ std::vector<int> v0;
+ // CHECK-FIXES: v0.reserve(10);
+ for (int i = 0; i < 10; ++i)
+ v0.push_back(i);
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called inside a loop; consider pre-allocating the container capacity before the loop
+ }
+ {
+ std::vector<int> v1;
+ // CHECK-FIXES: v1.reserve(10);
+ for (int i = 0; i < 10; i++)
+ v1.push_back(i);
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called
+ }
+ {
+ std::vector<int> v2;
+ // CHECK-FIXES: v2.reserve(10);
+ for (int i = 0; i < 10; ++i)
+ v2.push_back(0);
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called
+ }
+ {
+ std::vector<int> v3;
+ // CHECK-FIXES: v3.reserve(5);
+ for (int i = 0; i < 5; ++i) {
+ v3.push_back(i);
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called
+ }
+ // CHECK-FIXES-NOT: v3.reserve(10);
+ for (int i = 0; i < 10; ++i) {
+ // No fix for this loop as we encounter the prior loops.
+ v3.push_back(i);
+ }
+ }
+ {
+ std::vector<int> v4;
+ std::vector<int> v5;
+ v5.reserve(3);
+ // CHECK-FIXES: v4.reserve(10);
+ for (int i = 0; i < 10; ++i)
+ v4.push_back(i);
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called
+ }
+ {
+ std::vector<int> v6;
+ // CHECK-FIXES: v6.reserve(t.size());
+ for (std::size_t i = 0; i < t.size(); ++i) {
+ v6.push_back(t[i]);
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called
+ }
+ }
+ {
+ std::vector<int> v7;
+ // CHECK-FIXES: v7.reserve(t.size() - 1);
+ for (std::size_t i = 0; i < t.size() - 1; ++i) {
+ v7.push_back(t[i]);
+ } // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called
+ }
+ {
+ std::vector<int> v8;
+ // CHECK-FIXES: v8.reserve(t.size());
+ for (const auto &e : t) {
+ v8.push_back(e);
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called
+ }
+ }
+ {
+ std::vector<int> v9;
+ // CHECK-FIXES: v9.reserve(t.size());
+ for (const auto &e : t) {
+ v9.push_back(Op(e));
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called
+ }
+ }
+ {
+ std::vector<Foo> v10;
+ // CHECK-FIXES: v10.reserve(t.size());
+ for (const auto &e : t) {
+ v10.push_back(Foo(e));
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called
+ }
+ }
+ {
+ std::vector<Bar> v11;
+ // CHECK-FIXES: v11.reserve(t.size());
+ for (const auto &e : t) {
+ v11.push_back(e);
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called
+ }
+ }
+ {
+ std::vector<Foo> v12;
+ // CHECK-FIXES: v12.reserve(t.size());
+ for (const auto &e : t) {
+ v12.emplace_back(e);
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'emplace_back' is called
+ }
+ }
+
+ {
+ FooProto foo;
+ // CHECK-FIXES: foo.mutable_x()->Reserve(5);
+ for (int i = 0; i < 5; i++) {
+ foo.add_x(i);
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'add_x' is called inside a loop; consider pre-allocating the container capacity before the loop
+ }
+ }
+
+ // ---- Non-fixed Cases ----
+ {
+ std::vector<int> z0;
+ z0.reserve(20);
+ // CHECK-FIXES-NOT: z0.reserve(10);
+ // There is a "reserve" call already.
+ for (int i = 0; i < 10; ++i) {
+ z0.push_back(i);
+ }
+ }
+ {
+ std::vector<int> z1;
+ z1.reserve(5);
+ // CHECK-FIXES-NOT: z1.reserve(10);
+ // There is a "reserve" call already.
+ for (int i = 0; i < 10; ++i) {
+ z1.push_back(i);
+ }
+ }
+ {
+ std::vector<int> z2;
+ z2.resize(5);
+ // CHECK-FIXES-NOT: z2.reserve(10);
+ // There is a ref usage of v before the loop.
+ for (int i = 0; i < 10; ++i) {
+ z2.push_back(i);
+ }
+ }
+ {
+ std::vector<int> z3;
+ z3.push_back(0);
+ // CHECK-FIXES-NOT: z3.reserve(10);
+ // There is a ref usage of v before the loop.
+ for (int i = 0; i < 10; ++i) {
+ z3.push_back(i);
+ }
+ }
+ {
+ std::vector<int> z4;
+ f(z4);
+ // CHECK-FIXES-NOT: z4.reserve(10);
+ // There is a ref usage of z4 before the loop.
+ for (int i = 0; i < 10; ++i) {
+ z4.push_back(i);
+ }
+ }
+ {
+ std::vector<int> z5(20);
+ // CHECK-FIXES-NOT: z5.reserve(10);
+ // z5 is not constructed with default constructor.
+ for (int i = 0; i < 10; ++i) {
+ z5.push_back(i);
+ }
+ }
+ {
+ std::vector<int> z6;
+ // CHECK-FIXES-NOT: z6.reserve(10);
+ // For-loop is not started with 0.
+ for (int i = 1; i < 10; ++i) {
+ z6.push_back(i);
+ }
+ }
+ {
+ std::vector<int> z7;
+ // CHECK-FIXES-NOT: z7.reserve(t.size());
+ // z7 isn't referenced in for-loop body.
+ for (std::size_t i = 0; i < t.size(); ++i) {
+ t.push_back(i);
+ }
+ }
+ {
+ std::vector<int> z8;
+ int k;
+ // CHECK-FIXES-NOT: z8.reserve(10);
+ // For-loop isn't a fixable loop.
+ for (std::size_t i = 0; k < 10; ++i) {
+ z8.push_back(t[i]);
+ }
+ }
+ {
+ std::vector<int> z9;
+ // CHECK-FIXES-NOT: z9.reserve(i + 1);
+ // The loop end expression refers to the loop variable i.
+ for (int i = 0; i < i + 1; i++)
+ z9.push_back(i);
+ }
+ {
+ std::vector<int> z10;
+ int k;
+ // CHECK-FIXES-NOT: z10.reserve(10);
+ // For-loop isn't a fixable loop.
+ for (std::size_t i = 0; i < 10; ++k) {
+ z10.push_back(t[i]);
+ }
+ }
+ {
+ std::vector<int> z11;
+ // initializer_list should not trigger the check.
+ for (int e : {1, 2, 3, 4, 5}) {
+ z11.push_back(e);
+ }
+ }
+ {
+ std::vector<int> z12;
+ std::vector<int>* z13 = &t;
+ // We only support detecting the range init expression which references
+ // container directly.
+ // Complex range init expressions like `*z13` is not supported.
+ for (const auto &e : *z13) {
+ z12.push_back(e);
+ }
+ }
+
+ {
+ FooProto foo;
+ foo.mutable_x();
+ // CHECK-FIXES-NOT: foo.mutable_x()->Reserve(5);
+ for (int i = 0; i < 5; i++) {
+ foo.add_x(i);
+ }
+ }
+ {
+ FooProto foo;
+ // CHECK-FIXES-NOT: foo.mutable_x()->Reserve(5);
+ for (int i = 0; i < 5; i++) {
+ foo.add_x(i);
+ foo.add_x(i);
+ }
+ }
+ {
+ FooProto foo;
+ // CHECK-FIXES-NOT: foo.mutable_x()->Reserve(5);
+ foo.add_x(-1);
+ for (int i = 0; i < 5; i++) {
+ foo.add_x(i);
+ }
+ }
+ {
+ FooProto foo;
+ BarProto bar;
+ bar.mutable_x();
+ // CHECK-FIXES-NOT: foo.mutable_x()->Reserve(5);
+ for (int i = 0; i < 5; i++) {
+ foo.add_x();
+ bar.add_x();
+ }
+ }
+ {
+ FooProto foo;
+ foo.mutable_y();
+ // CHECK-FIXES-NOT: foo.mutable_x()->Reserve(5);
+ for (int i = 0; i < 5; i++) {
+ foo.add_x(i);
+ }
+ }
+ {
+ FooProto foo;
+ // CHECK-FIXES-NOT: foo.mutable_z()->Reserve(5);
+ for (int i = 0; i < 5; i++) {
+ foo.add_z();
+ }
+ }
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/performance-move-const-arg-trivially-copyable.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/performance-move-const-arg-trivially-copyable.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/performance-move-const-arg-trivially-copyable.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/performance-move-const-arg-trivially-copyable.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,97 @@
+// RUN: %check_clang_tidy %s performance-move-const-arg %t \
+// RUN: -config='{CheckOptions: \
+// RUN: [{key: performance-move-const-arg.CheckTriviallyCopyableMove, value: 0}]}'
+
+namespace std {
+
+template <typename> struct remove_reference;
+template <typename _Tp> struct remove_reference { typedef _Tp type; };
+template <typename _Tp> struct remove_reference<_Tp &> { typedef _Tp type; };
+template <typename _Tp> struct remove_reference<_Tp &&> { typedef _Tp type; };
+
+template <typename _Tp>
+constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) {
+ return static_cast<typename std::remove_reference<_Tp>::type &&>(__t);
+}
+
+template <typename _Tp>
+constexpr _Tp &&
+forward(typename remove_reference<_Tp>::type &__t) noexcept {
+ return static_cast<_Tp &&>(__t);
+}
+
+} // namespace std
+
+class NoMoveSemantics {
+ public:
+ NoMoveSemantics();
+ NoMoveSemantics(const NoMoveSemantics &);
+
+ NoMoveSemantics &operator=(const NoMoveSemantics &);
+};
+
+void callByConstRef(const NoMoveSemantics &);
+void callByConstRef(int i, const NoMoveSemantics &);
+
+void moveToConstReferencePositives() {
+ NoMoveSemantics obj;
+
+ // Basic case. It is here just to have a single "detected and fixed" case.
+ callByConstRef(std::move(obj));
+ // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]
+ // CHECK-FIXES: callByConstRef(obj);
+}
+
+struct TriviallyCopyable {
+ int i;
+};
+
+void f(TriviallyCopyable) {}
+
+void g() {
+ TriviallyCopyable obj;
+ f(std::move(obj));
+}
+
+class MoveSemantics {
+ public:
+ MoveSemantics();
+ MoveSemantics(MoveSemantics &&);
+
+ MoveSemantics &operator=(MoveSemantics &&);
+};
+
+void fmovable(MoveSemantics);
+
+void lambda1() {
+ auto f = [](MoveSemantics m) {
+ fmovable(std::move(m));
+ };
+ f(MoveSemantics());
+}
+
+template<class T> struct function {};
+
+template<typename Result, typename... Args>
+class function<Result(Args...)> {
+public:
+ function() = default;
+ void operator()(Args... args) const {
+ fmovable(std::forward<Args>(args)...);
+ }
+};
+
+void functionInvocation() {
+ function<void(MoveSemantics)> callback;
+ MoveSemantics m;
+ callback(std::move(m));
+}
+
+void lambda2() {
+ function<void(MoveSemantics)> callback;
+
+ auto f = [callback = std::move(callback)](MoveSemantics m) mutable {
+ callback(std::move(m));
+ };
+ f(MoveSemantics());
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/performance-move-const-arg.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/performance-move-const-arg.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/performance-move-const-arg.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/performance-move-const-arg.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,248 @@
+// RUN: %check_clang_tidy %s performance-move-const-arg %t
+
+namespace std {
+template <typename>
+struct remove_reference;
+
+template <typename _Tp>
+struct remove_reference {
+ typedef _Tp type;
+};
+
+template <typename _Tp>
+struct remove_reference<_Tp &> {
+ typedef _Tp type;
+};
+
+template <typename _Tp>
+struct remove_reference<_Tp &&> {
+ typedef _Tp type;
+};
+
+template <typename _Tp>
+constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) {
+ return static_cast<typename std::remove_reference<_Tp>::type &&>(__t);
+}
+
+template <typename _Tp>
+constexpr _Tp &&
+forward(typename remove_reference<_Tp>::type &__t) noexcept {
+ return static_cast<_Tp &&>(__t);
+}
+
+} // namespace std
+
+class A {
+public:
+ A() {}
+ A(const A &rhs) {}
+ A(A &&rhs) {}
+};
+
+struct TriviallyCopyable {
+ int i;
+};
+
+void f(TriviallyCopyable) {}
+
+void g() {
+ TriviallyCopyable obj;
+ f(std::move(obj));
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: std::move of the variable 'obj' of the trivially-copyable type 'TriviallyCopyable' has no effect; remove std::move() [performance-move-const-arg]
+ // CHECK-FIXES: f(obj);
+}
+
+int f1() {
+ return std::move(42);
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the expression of the trivially-copyable type 'int' has no effect; remove std::move() [performance-move-const-arg]
+ // CHECK-FIXES: return 42;
+}
+
+int f2(int x2) {
+ return std::move(x2);
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the variable 'x2' of the trivially-copyable type 'int'
+ // CHECK-FIXES: return x2;
+}
+
+int *f3(int *x3) {
+ return std::move(x3);
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the variable 'x3' of the trivially-copyable type 'int *'
+ // CHECK-FIXES: return x3;
+}
+
+A f4(A x4) { return std::move(x4); }
+
+A f5(const A x5) {
+ return std::move(x5);
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the const variable 'x5' has no effect; remove std::move() or make the variable non-const [performance-move-const-arg]
+ // CHECK-FIXES: return x5;
+}
+
+template <typename T>
+T f6(const T x6) {
+ return std::move(x6);
+}
+
+void f7() { int a = f6(10); }
+
+#define M1(x) x
+void f8() {
+ const A a;
+ M1(A b = std::move(a);)
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: std::move of the const variable 'a' has no effect; remove std::move() or make the variable non-const
+ // CHECK-FIXES: M1(A b = a;)
+}
+
+#define M2(x) std::move(x)
+int f9() { return M2(1); }
+
+template <typename T>
+T f10(const int x10) {
+ return std::move(x10);
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the const variable 'x10' of the trivially-copyable type 'const int' has no effect; remove std::move() [performance-move-const-arg]
+ // CHECK-FIXES: return x10;
+}
+void f11() {
+ f10<int>(1);
+ f10<double>(1);
+}
+
+class NoMoveSemantics {
+public:
+ NoMoveSemantics();
+ NoMoveSemantics(const NoMoveSemantics &);
+
+ NoMoveSemantics &operator=(const NoMoveSemantics &);
+};
+
+void callByConstRef(const NoMoveSemantics &);
+void callByConstRef(int i, const NoMoveSemantics &);
+
+void moveToConstReferencePositives() {
+ NoMoveSemantics obj;
+
+ // Basic case.
+ callByConstRef(std::move(obj));
+ // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: passing result of std::move() as
+ // CHECK-FIXES: callByConstRef(obj);
+
+ // Also works for second argument.
+ callByConstRef(1, std::move(obj));
+ // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: passing result of std::move() as
+ // CHECK-FIXES: callByConstRef(1, obj);
+
+ // Works if std::move() applied to a temporary.
+ callByConstRef(std::move(NoMoveSemantics()));
+ // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: passing result of std::move() as
+ // CHECK-FIXES: callByConstRef(NoMoveSemantics());
+
+ // Works if calling a copy constructor.
+ NoMoveSemantics other(std::move(obj));
+ // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: passing result of std::move() as
+ // CHECK-FIXES: NoMoveSemantics other(obj);
+
+ // Works if calling assignment operator.
+ other = std::move(obj);
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: passing result of std::move() as
+ // CHECK-FIXES: other = obj;
+}
+
+class MoveSemantics {
+public:
+ MoveSemantics();
+ MoveSemantics(MoveSemantics &&);
+
+ MoveSemantics &operator=(MoveSemantics &&);
+};
+
+void callByValue(MoveSemantics);
+
+void callByRValueRef(MoveSemantics &&);
+
+template <class T>
+void templateFunction(T obj) {
+ T other = std::move(obj);
+}
+
+#define M3(T, obj) \
+ do { \
+ T other = std::move(obj); \
+ } while (true)
+
+#define CALL(func) (func)()
+
+void moveToConstReferenceNegatives() {
+ // No warning when actual move takes place.
+ MoveSemantics move_semantics;
+ callByValue(std::move(move_semantics));
+ callByRValueRef(std::move(move_semantics));
+ MoveSemantics other(std::move(move_semantics));
+ other = std::move(move_semantics);
+
+ // No warning if std::move() not used.
+ NoMoveSemantics no_move_semantics;
+ callByConstRef(no_move_semantics);
+
+ // No warning if instantiating a template.
+ templateFunction(no_move_semantics);
+
+ // No warning inside of macro expansions.
+ M3(NoMoveSemantics, no_move_semantics);
+
+ // No warning inside of macro expansion, even if the macro expansion is inside
+ // a lambda that is, in turn, an argument to a macro.
+ CALL([no_move_semantics] { M3(NoMoveSemantics, no_move_semantics); });
+
+ auto lambda = [] {};
+ auto lambda2 = std::move(lambda);
+}
+
+class MoveOnly {
+public:
+ MoveOnly(const MoveOnly &other) = delete;
+ MoveOnly &operator=(const MoveOnly &other) = delete;
+ MoveOnly(MoveOnly &&other) = default;
+ MoveOnly &operator=(MoveOnly &&other) = default;
+};
+template <class T>
+void Q(T);
+void moveOnlyNegatives(MoveOnly val) {
+ Q(std::move(val));
+}
+
+void fmovable(MoveSemantics);
+
+void lambda1() {
+ auto f = [](MoveSemantics m) {
+ fmovable(std::move(m));
+ };
+ f(MoveSemantics());
+}
+
+template<class T> struct function {};
+
+template<typename Result, typename... Args>
+class function<Result(Args...)> {
+public:
+ function() = default;
+ void operator()(Args... args) const {
+ fmovable(std::forward<Args>(args)...);
+ }
+};
+
+void functionInvocation() {
+ function<void(MoveSemantics)> callback;
+ MoveSemantics m;
+ callback(std::move(m));
+}
+
+void lambda2() {
+ function<void(MoveSemantics)> callback;
+
+ auto f = [callback = std::move(callback)](MoveSemantics m) mutable {
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: std::move of the variable 'callback' of the trivially-copyable type 'function<void (MoveSemantics)>' has no effect; remove std::move()
+ // CHECK-FIXES: auto f = [callback = callback](MoveSemantics m) mutable {
+ callback(std::move(m));
+ };
+ f(MoveSemantics());
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/performance-move-constructor-init.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/performance-move-constructor-init.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/performance-move-constructor-init.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/performance-move-constructor-init.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,156 @@
+// RUN: %check_clang_tidy %s performance-move-constructor-init,modernize-pass-by-value %t -- \
+// RUN: -config='{CheckOptions: \
+// RUN: [{key: modernize-pass-by-value.ValuesOnly, value: 1}]}' \
+// RUN: -- -isystem %S/Inputs/Headers
+
+#include <s.h>
+
+// CHECK-FIXES: #include <utility>
+
+template <class T> struct remove_reference {typedef T type;};
+template <class T> struct remove_reference<T&> {typedef T type;};
+template <class T> struct remove_reference<T&&> {typedef T type;};
+
+template <typename T>
+typename remove_reference<T>::type&& move(T&& arg) {
+ return static_cast<typename remove_reference<T>::type&&>(arg);
+}
+
+struct C {
+ C() = default;
+ C(const C&) = default;
+};
+
+struct B {
+ B() {}
+ B(const B&) {}
+ B(B &&) {}
+};
+
+struct D : B {
+ D() : B() {}
+ D(const D &RHS) : B(RHS) {}
+ // CHECK-NOTES: :[[@LINE+3]]:16: warning: move constructor initializes base class by calling a copy constructor [performance-move-constructor-init]
+ // CHECK-NOTES: 26:3: note: copy constructor being called
+ // CHECK-NOTES: 27:3: note: candidate move constructor here
+ D(D &&RHS) : B(RHS) {}
+};
+
+struct E : B {
+ E() : B() {}
+ E(const E &RHS) : B(RHS) {}
+ E(E &&RHS) : B(move(RHS)) {} // ok
+};
+
+struct F {
+ C M;
+
+ F(F &&) : M(C()) {} // ok
+};
+
+struct G {
+ G() = default;
+ G(const G&) = default;
+ G(G&&) = delete;
+};
+
+struct H : G {
+ H() = default;
+ H(const H&) = default;
+ H(H &&RHS) : G(RHS) {} // ok
+};
+
+struct I {
+ I(const I &) = default; // suppresses move constructor creation
+};
+
+struct J : I {
+ J(J &&RHS) : I(RHS) {} // ok
+};
+
+struct K {}; // Has implicit copy and move constructors, is trivially copyable
+struct L : K {
+ L(L &&RHS) : K(RHS) {} // ok
+};
+
+struct M {
+ B Mem;
+ // CHECK-NOTES: :[[@LINE+1]]:16: warning: move constructor initializes class member by calling a copy constructor [performance-move-constructor-init]
+ M(M &&RHS) : Mem(RHS.Mem) {}
+ // CHECK-NOTES: 26:3: note: copy constructor being called
+ // CHECK-NOTES: 27:3: note: candidate move constructor here
+};
+
+struct N {
+ B Mem;
+ N(N &&RHS) : Mem(move(RHS.Mem)) {}
+};
+
+struct O {
+ O(O&& other) : b(other.b) {} // ok
+ const B b;
+};
+
+struct P {
+ P(O&& other) : b(other.b) {} // ok
+ B b;
+};
+
+struct Movable {
+ Movable(Movable &&) = default;
+ Movable(const Movable &) = default;
+ Movable &operator=(const Movable &) = default;
+ ~Movable() {}
+};
+
+struct TriviallyCopyable {
+ TriviallyCopyable() = default;
+ TriviallyCopyable(TriviallyCopyable &&) = default;
+ TriviallyCopyable(const TriviallyCopyable &) = default;
+};
+
+struct Positive {
+ Positive(Movable M) : M_(M) {}
+ // CHECK-NOTES: [[@LINE-1]]:12: warning: pass by value and use std::move [modernize-pass-by-value]
+ // CHECK-FIXES: Positive(Movable M) : M_(std::move(M)) {}
+ Movable M_;
+};
+
+struct NegativeMultipleInitializerReferences {
+ NegativeMultipleInitializerReferences(Movable M) : M_(M), n_(M) {}
+ Movable M_;
+ Movable n_;
+};
+
+struct NegativeReferencedInConstructorBody {
+ NegativeReferencedInConstructorBody(Movable M) : M_(M) { M_ = M; }
+ Movable M_;
+};
+
+struct NegativeParamTriviallyCopyable {
+ NegativeParamTriviallyCopyable(TriviallyCopyable T) : T_(T) {}
+ NegativeParamTriviallyCopyable(int I) : I_(I) {}
+
+ TriviallyCopyable T_;
+ int I_;
+};
+
+struct NegativeNotPassedByValue {
+ // This const ref constructor isn't warned about because the ValuesOnly option is set.
+ NegativeNotPassedByValue(const Movable &M) : M_(M) {}
+ NegativeNotPassedByValue(const Movable M) : M_(M) {}
+ NegativeNotPassedByValue(Movable &M) : M_(M) {}
+ NegativeNotPassedByValue(Movable *M) : M_(*M) {}
+ NegativeNotPassedByValue(const Movable *M) : M_(*M) {}
+ Movable M_;
+};
+
+struct Immovable {
+ Immovable(const Immovable &) = default;
+ Immovable(Immovable &&) = delete;
+};
+
+struct NegativeImmovableParameter {
+ NegativeImmovableParameter(Immovable I) : I_(I) {}
+ Immovable I_;
+};
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/performance-noexcept-move-constructor-fix.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/performance-noexcept-move-constructor-fix.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/performance-noexcept-move-constructor-fix.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/performance-noexcept-move-constructor-fix.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,67 @@
+// RUN: %check_clang_tidy %s performance-noexcept-move-constructor %t
+
+struct C_1 {
+ ~C_1() {}
+ C_1(int a) {}
+ C_1(C_1&& a) :C_1(5) {}
+ // CHECK-FIXES: ){{.*}}noexcept{{.*}}:
+ C_1& operator=(C_1&&) { return *this; }
+ // CHECK-FIXES: ){{.*}}noexcept{{.*}} {
+};
+
+struct C_2 {
+ ~C_2() {}
+ C_2(C_2&& a);
+// CHECK-FIXES: ){{.*}}noexcept{{.*}};
+ C_2& operator=(C_2&&);
+// CHECK-FIXES: ){{.*}}noexcept{{.*}};
+};
+
+C_2::C_2(C_2&& a) {}
+// CHECK-FIXES: ){{.*}}noexcept{{.*}} {}
+C_2& C_2::operator=(C_2&&) { return *this; }
+// CHECK-FIXES: ){{.*}}noexcept{{.*}} {
+
+struct C_3 {
+ ~C_3() {}
+ C_3(C_3&& a);
+// CHECK-FIXES: ){{.*}}noexcept{{.*}};
+ C_3& operator=(C_3&& a);
+// CHECK-FIXES: ){{.*}}noexcept{{.*}};
+};
+
+C_3::C_3(C_3&& a) = default;
+// CHECK-FIXES: ){{.*}}noexcept{{.*}} = default;
+C_3& C_3::operator=(C_3&& a) = default;
+// CHECK-FIXES: ){{.*}}noexcept{{.*}} = default;
+
+template <class T>
+struct C_4 {
+ C_4(C_4<T>&&) {}
+// CHECK-FIXES: ){{.*}}noexcept{{.*}} {}
+ ~C_4() {}
+ C_4& operator=(C_4&& a) = default;
+// CHECK-FIXES: ){{.*}}noexcept{{.*}} = default;
+};
+
+template <class T>
+struct C_5 {
+ C_5(C_5<T>&&) {}
+// CHECK-FIXES:){{.*}}noexcept{{.*}} {}
+ ~C_5() {}
+ auto operator=(C_5&& a)->C_5<T> = default;
+// CHECK-FIXES:){{.*}}noexcept{{.*}} = default;
+};
+
+template <class T>
+struct C_6 {
+ C_6(C_6<T>&&) {}
+// CHECK-FIXES:){{.*}}noexcept{{.*}} {}
+ ~C_6() {}
+ auto operator=(C_6&& a)->C_6<T>;
+// CHECK-FIXES:){{.*}}noexcept{{.*}};
+};
+
+template <class T>
+auto C_6<T>::operator=(C_6<T>&& a) -> C_6<T> {}
+// CHECK-FIXES: ){{.*}}noexcept{{.*}} {}
\ No newline at end of file
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/performance-noexcept-move-constructor.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/performance-noexcept-move-constructor.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/performance-noexcept-move-constructor.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/performance-noexcept-move-constructor.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,54 @@
+// RUN: %check_clang_tidy %s performance-noexcept-move-constructor %t
+
+class A {
+ A(A &&);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: move constructors should be marked noexcept [performance-noexcept-move-constructor]
+ A &operator=(A &&);
+ // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: move assignment operators should
+};
+
+struct B {
+ static constexpr bool kFalse = false;
+ B(B &&) noexcept(kFalse);
+ // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: noexcept specifier on the move constructor evaluates to 'false' [performance-noexcept-move-constructor]
+};
+
+class OK {};
+
+void f() {
+ OK a;
+ a = OK();
+}
+
+class OK1 {
+public:
+ OK1();
+ OK1(const OK1 &);
+ OK1(OK1 &&) noexcept;
+ OK1 &operator=(OK1 &&) noexcept;
+ void f();
+ void g() noexcept;
+};
+
+class OK2 {
+ static constexpr bool kTrue = true;
+
+public:
+ OK2(OK2 &&) noexcept(true) {}
+ OK2 &operator=(OK2 &&) noexcept(kTrue) { return *this; }
+};
+
+struct OK3 {
+ OK3(OK3 &&) noexcept(false) {}
+ OK3 &operator=(OK3 &&) = delete;
+};
+
+struct OK4 {
+ OK4(OK4 &&) noexcept = default;
+ OK4 &operator=(OK4 &&) noexcept = default;
+};
+
+struct OK5 {
+ OK5(OK5 &&) noexcept(true) = default;
+ OK5 &operator=(OK5 &&) noexcept(true) = default;
+};
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/performance-type-promotion-in-math-fn.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/performance-type-promotion-in-math-fn.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/performance-type-promotion-in-math-fn.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/performance-type-promotion-in-math-fn.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,316 @@
+// RUN: %check_clang_tidy %s performance-type-promotion-in-math-fn %t
+
+// CHECK-FIXES: #include <cmath>
+
+double acos(double);
+double acosh(double);
+double asin(double);
+double asinh(double);
+double atan2(double, double);
+double atan(double);
+double atanh(double);
+double cbrt(double);
+double ceil(double);
+double copysign(double, double);
+double cos(double);
+double cosh(double);
+double erfc(double);
+double erf(double);
+double exp2(double);
+double exp(double);
+double expm1(double);
+double fabs(double);
+double fdim(double, double);
+double floor(double);
+double fma(double, double, double);
+double fmax(double, double);
+double fmin(double, double);
+double fmod(double, double);
+double frexp(double, int *);
+double hypot(double, double);
+double ilogb(double);
+double ldexp(double, double);
+double lgamma(double);
+long long llrint(double);
+double log10(double);
+double log1p(double);
+double log2(double);
+double logb(double);
+double log(double);
+long lrint(double);
+double modf(double);
+double nearbyint(double);
+double nextafter(double, double);
+double nexttoward(double, long double);
+double pow(double, double);
+double remainder(double, double);
+double remquo(double, double, int *);
+double rint(double);
+double round(double);
+double scalbln(double, long);
+double scalbn(double, int);
+double sin(double);
+double sinh(double);
+double sqrt(double);
+double tan(double);
+double tanh(double);
+double tgamma(double);
+double trunc(double);
+long long llround(double);
+long lround(double);
+
+void check_all_fns() {
+ float a, b, c;
+ int i;
+ long l;
+ int *int_ptr;
+
+ acos(a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'acos' promotes float to double [performance-type-promotion-in-math-fn]
+ // CHECK-FIXES: {{^}} std::acos(a);{{$}}
+ acosh(a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'acosh'
+ // CHECK-FIXES: {{^}} std::acosh(a);{{$}}
+ asin(a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'asin'
+ // CHECK-FIXES: {{^}} std::asin(a);{{$}}
+ asinh(a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'asinh'
+ // CHECK-FIXES: {{^}} std::asinh(a);{{$}}
+ atan2(a, b);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'atan2'
+ // CHECK-FIXES: {{^}} std::atan2(a, b);{{$}}
+ atan(a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'atan'
+ // CHECK-FIXES: {{^}} std::atan(a);{{$}}
+ atanh(a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'atanh'
+ // CHECK-FIXES: {{^}} std::atanh(a);{{$}}
+ cbrt(a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'cbrt'
+ // CHECK-FIXES: {{^}} std::cbrt(a);{{$}}
+ ceil(a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'ceil'
+ // CHECK-FIXES: {{^}} std::ceil(a);{{$}}
+ copysign(a, b);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'copysign'
+ // CHECK-FIXES: {{^}} std::copysign(a, b);{{$}}
+ cos(a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'cos'
+ // CHECK-FIXES: {{^}} std::cos(a);{{$}}
+ cosh(a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'cosh'
+ // CHECK-FIXES: {{^}} std::cosh(a);{{$}}
+ erf(a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'erf'
+ // CHECK-FIXES: {{^}} std::erf(a);{{$}}
+ erfc(a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'erfc'
+ // CHECK-FIXES: {{^}} std::erfc(a);{{$}}
+ exp2(a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'exp2'
+ // CHECK-FIXES: {{^}} std::exp2(a);{{$}}
+ exp(a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'exp'
+ // CHECK-FIXES: {{^}} std::exp(a);{{$}}
+ expm1(a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'expm1'
+ // CHECK-FIXES: {{^}} std::expm1(a);{{$}}
+ fabs(a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'fabs'
+ // CHECK-FIXES: {{^}} std::fabs(a);{{$}}
+ fdim(a, b);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'fdim'
+ // CHECK-FIXES: {{^}} std::fdim(a, b);{{$}}
+ floor(a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'floor'
+ // CHECK-FIXES: {{^}} std::floor(a);{{$}}
+ fma(a, b, c);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'fma'
+ // CHECK-FIXES: {{^}} std::fma(a, b, c);{{$}}
+ fmax(a, b);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'fmax'
+ // CHECK-FIXES: {{^}} std::fmax(a, b);{{$}}
+ fmin(a, b);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'fmin'
+ // CHECK-FIXES: {{^}} std::fmin(a, b);{{$}}
+ fmod(a, b);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'fmod'
+ // CHECK-FIXES: {{^}} std::fmod(a, b);{{$}}
+ frexp(a, int_ptr);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'frexp'
+ // CHECK-FIXES: {{^}} std::frexp(a, int_ptr);{{$}}
+ hypot(a, b);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'hypot'
+ // CHECK-FIXES: {{^}} std::hypot(a, b);{{$}}
+ ilogb(a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'ilogb'
+ // CHECK-FIXES: {{^}} std::ilogb(a);{{$}}
+ ldexp(a, b);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'ldexp'
+ // CHECK-FIXES: {{^}} std::ldexp(a, b);{{$}}
+ lgamma(a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'lgamma'
+ // CHECK-FIXES: {{^}} std::lgamma(a);{{$}}
+ llrint(a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'llrint'
+ // CHECK-FIXES: {{^}} std::llrint(a);{{$}}
+ llround(a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'llround'
+ // CHECK-FIXES: {{^}} std::llround(a);{{$}}
+ log10(a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'log10'
+ // CHECK-FIXES: {{^}} std::log10(a);{{$}}
+ log1p(a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'log1p'
+ // CHECK-FIXES: {{^}} std::log1p(a);{{$}}
+ log2(a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'log2'
+ // CHECK-FIXES: {{^}} std::log2(a);{{$}}
+ log(a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'log'
+ // CHECK-FIXES: {{^}} std::log(a);{{$}}
+ logb(a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'logb'
+ // CHECK-FIXES: {{^}} std::logb(a);{{$}}
+ lrint(a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'lrint'
+ // CHECK-FIXES: {{^}} std::lrint(a);{{$}}
+ lround(a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'lround'
+ // CHECK-FIXES: {{^}} std::lround(a);{{$}}
+ nearbyint(a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'nearbyint'
+ // CHECK-FIXES: {{^}} std::nearbyint(a);{{$}}
+ nextafter(a, b);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'nextafter'
+ // CHECK-FIXES: {{^}} std::nextafter(a, b);{{$}}
+ nexttoward(a, b);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'nexttoward'
+ // CHECK-FIXES: {{^}} std::nexttoward(a, b);{{$}}
+ pow(a, b);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'pow'
+ // CHECK-FIXES: {{^}} std::pow(a, b);{{$}}
+ remainder(a, b);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'remainder'
+ // CHECK-FIXES: {{^}} std::remainder(a, b);{{$}}
+ remquo(a, b, int_ptr);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'remquo'
+ // CHECK-FIXES: {{^}} std::remquo(a, b, int_ptr);{{$}}
+ rint(a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'rint'
+ // CHECK-FIXES: {{^}} std::rint(a);{{$}}
+ round(a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'round'
+ // CHECK-FIXES: {{^}} std::round(a);{{$}}
+ scalbln(a, l);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'scalbln'
+ // CHECK-FIXES: {{^}} std::scalbln(a, l);{{$}}
+ scalbn(a, i);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'scalbn'
+ // CHECK-FIXES: {{^}} std::scalbn(a, i);{{$}}
+ sin(a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'sin'
+ // CHECK-FIXES: {{^}} std::sin(a);{{$}}
+ sinh(a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'sinh'
+ // CHECK-FIXES: {{^}} std::sinh(a);{{$}}
+ sqrt(a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'sqrt'
+ // CHECK-FIXES: {{^}} std::sqrt(a);{{$}}
+ tan(a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'tan'
+ // CHECK-FIXES: {{^}} std::tan(a);{{$}}
+ tanh(a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'tanh'
+ // CHECK-FIXES: {{^}} std::tanh(a);{{$}}
+ tgamma(a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'tgamma'
+ // CHECK-FIXES: {{^}} std::tgamma(a);{{$}}
+ trunc(a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'trunc'
+ // CHECK-FIXES: {{^}} std::trunc(a);{{$}}
+}
+
+// nexttoward/nexttowardf are weird -- the second param is always long double.
+// So we warn if the first arg is a float, regardless of what the second arg is.
+void check_nexttoward() {
+ nexttoward(0.f, 0);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'nexttoward'
+ // CHECK-FIXES: {{^}} std::nexttoward(0.f, 0);{{$}}
+ nexttoward(0.f, 0l);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'nexttoward'
+ // CHECK-FIXES: {{^}} std::nexttoward(0.f, 0l);{{$}}
+ nexttoward(0.f, 0.f);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'nexttoward'
+ // CHECK-FIXES: {{^}} std::nexttoward(0.f, 0.f);{{$}}
+ nexttoward(0.f, 0.);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'nexttoward'
+ // CHECK-FIXES: {{^}} std::nexttoward(0.f, 0.);{{$}}
+
+ // No warnings for these.
+ nexttoward(0., 0);
+ nexttoward(0., 0.f);
+ nexttoward(0., 0.);
+}
+
+// The second parameter to scalbn and scalbnf is an int, so we don't care what
+// type you pass as that argument; we warn iff the first argument is a float.
+void check_scalbn() {
+ scalbn(0.f, 0);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'scalbn'
+ // CHECK-FIXES: {{^}} std::scalbn(0.f, 0);{{$}}
+ scalbn(0.f, static_cast<char>(0));
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'scalbn'
+ // CHECK-FIXES: {{^}} std::scalbn(0.f, static_cast<char>(0));{{$}}
+
+ // No warnings for these.
+ scalbn(0., 0);
+ scalbn(0., static_cast<char>(0));
+}
+
+// scalbln/scalblnf are like scalbn/scalbnf except their second arg is a long.
+// Again, doesn't matter what we pass for the second arg; we warn iff the first
+// arg is a float.
+void check_scalbln() {
+ scalbln(0.f, 0);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'scalbln'
+ // CHECK-FIXES: {{^}} std::scalbln(0.f, 0);{{$}}
+ scalbln(0.f, 0l);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'scalbln'
+ // CHECK-FIXES: {{^}} std::scalbln(0.f, 0l);{{$}}
+
+ // No warnings for these.
+ scalbln(0., 0);
+ scalbln(0., 0l);
+}
+
+float cosf(float);
+double foo(double); // not a math.h function
+float cos(float); // not a math.h function (wrong signature)
+double cos(double, double); // not a math.h function (wrong signature)
+
+namespace std {
+void cos(float);
+} // namespace std
+
+void check_no_warnings() {
+ foo(0.); // no warning because not a math.h function.
+
+ sin(0); // no warning because arg is an int
+ cos(0.); // no warning because arg is a double
+ std::cos(0.f); // no warning because not ::cos.
+ cosf(0.f); // no warning; we expect this to take a float
+ cos(0.f); // does not match the expected signature of ::cos
+ cos(0.f, 0.f); // does not match the expected signature of ::cos
+
+ // No warnings because all args are not floats.
+ remainder(0., 0.f);
+ remainder(0.f, 0.);
+ remainder(0, 0.f);
+ remainder(0.f, 0);
+ fma(0.f, 0.f, 0);
+ fma(0.f, 0.f, 0.);
+ fma(0.f, 0., 0.f);
+ fma(0., 0.f, 0.f);
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/performance-unnecessary-copy-initialization-allowed-types.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/performance-unnecessary-copy-initialization-allowed-types.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/performance-unnecessary-copy-initialization-allowed-types.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/performance-unnecessary-copy-initialization-allowed-types.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,98 @@
+// RUN: %check_clang_tidy %s performance-unnecessary-copy-initialization %t -- -config="{CheckOptions: [{key: performance-unnecessary-copy-initialization.AllowedTypes, value: '[Pp]ointer$;[Pp]tr$;[Rr]ef(erence)?$'}]}" --
+
+struct SmartPointer {
+ ~SmartPointer();
+};
+
+struct smart_pointer {
+ ~smart_pointer();
+};
+
+struct SmartPtr {
+ ~SmartPtr();
+};
+
+struct smart_ptr {
+ ~smart_ptr();
+};
+
+struct SmartReference {
+ ~SmartReference();
+};
+
+struct smart_reference {
+ ~smart_reference();
+};
+
+struct SmartRef {
+ ~SmartRef();
+};
+
+struct smart_ref {
+ ~smart_ref();
+};
+
+struct OtherType {
+ ~OtherType();
+};
+
+template <typename T> struct SomeComplexTemplate {
+ ~SomeComplexTemplate();
+};
+
+typedef SomeComplexTemplate<int> NotTooComplexRef;
+
+const SmartPointer &getSmartPointer();
+const smart_pointer &get_smart_pointer();
+const SmartPtr &getSmartPtr();
+const smart_ptr &get_smart_ptr();
+const SmartReference &getSmartReference();
+const smart_reference &get_smart_reference();
+const SmartRef &getSmartRef();
+const smart_ref &get_smart_ref();
+const OtherType &getOtherType();
+const NotTooComplexRef &getNotTooComplexRef();
+
+void negativeSmartPointer() {
+ const auto P = getSmartPointer();
+}
+
+void negative_smart_pointer() {
+ const auto p = get_smart_pointer();
+}
+
+void negativeSmartPtr() {
+ const auto P = getSmartPtr();
+}
+
+void negative_smart_ptr() {
+ const auto p = get_smart_ptr();
+}
+
+void negativeSmartReference() {
+ const auto R = getSmartReference();
+}
+
+void negative_smart_reference() {
+ const auto r = get_smart_reference();
+}
+
+void negativeSmartRef() {
+ const auto R = getSmartRef();
+}
+
+void negative_smart_ref() {
+ const auto r = get_smart_ref();
+}
+
+void positiveOtherType() {
+ const auto O = getOtherType();
+ // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'O' is copy-constructed from a const reference; consider making it a const reference [performance-unnecessary-copy-initialization]
+ // CHECK-FIXES: const auto& O = getOtherType();
+}
+
+void negativeNotTooComplexRef() {
+ const NotTooComplexRef R = getNotTooComplexRef();
+ // Using `auto` here would result in the "canonical" type which does not match
+ // the pattern.
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,389 @@
+// RUN: %check_clang_tidy %s performance-unnecessary-copy-initialization %t
+
+struct ExpensiveToCopyType {
+ ExpensiveToCopyType();
+ virtual ~ExpensiveToCopyType();
+ const ExpensiveToCopyType &reference() const;
+ void nonConstMethod();
+ bool constMethod() const;
+};
+
+struct TrivialToCopyType {
+ const TrivialToCopyType &reference() const;
+};
+
+struct WeirdCopyCtorType {
+ WeirdCopyCtorType();
+ WeirdCopyCtorType(const WeirdCopyCtorType &w, bool oh_yes = true);
+
+ void nonConstMethod();
+ bool constMethod() const;
+};
+
+ExpensiveToCopyType global_expensive_to_copy_type;
+
+const ExpensiveToCopyType &ExpensiveTypeReference();
+const TrivialToCopyType &TrivialTypeReference();
+
+void mutate(ExpensiveToCopyType &);
+void mutate(ExpensiveToCopyType *);
+void useAsConstPointer(const ExpensiveToCopyType *);
+void useAsConstReference(const ExpensiveToCopyType &);
+void useByValue(ExpensiveToCopyType);
+
+void PositiveFunctionCall() {
+ const auto AutoAssigned = ExpensiveTypeReference();
+ // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'AutoAssigned' is copy-constructed from a const reference; consider making it a const reference [performance-unnecessary-copy-initialization]
+ // CHECK-FIXES: const auto& AutoAssigned = ExpensiveTypeReference();
+ const auto AutoCopyConstructed(ExpensiveTypeReference());
+ // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'AutoCopyConstructed'
+ // CHECK-FIXES: const auto& AutoCopyConstructed(ExpensiveTypeReference());
+ const ExpensiveToCopyType VarAssigned = ExpensiveTypeReference();
+ // CHECK-MESSAGES: [[@LINE-1]]:29: warning: the const qualified variable 'VarAssigned'
+ // CHECK-FIXES: const ExpensiveToCopyType& VarAssigned = ExpensiveTypeReference();
+ const ExpensiveToCopyType VarCopyConstructed(ExpensiveTypeReference());
+ // CHECK-MESSAGES: [[@LINE-1]]:29: warning: the const qualified variable 'VarCopyConstructed'
+ // CHECK-FIXES: const ExpensiveToCopyType& VarCopyConstructed(ExpensiveTypeReference());
+}
+
+void PositiveMethodCallConstReferenceParam(const ExpensiveToCopyType &Obj) {
+ const auto AutoAssigned = Obj.reference();
+ // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'AutoAssigned'
+ // CHECK-FIXES: const auto& AutoAssigned = Obj.reference();
+ const auto AutoCopyConstructed(Obj.reference());
+ // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'AutoCopyConstructed'
+ // CHECK-FIXES: const auto& AutoCopyConstructed(Obj.reference());
+ const ExpensiveToCopyType VarAssigned = Obj.reference();
+ // CHECK-MESSAGES: [[@LINE-1]]:29: warning: the const qualified variable 'VarAssigned'
+ // CHECK-FIXES: const ExpensiveToCopyType& VarAssigned = Obj.reference();
+ const ExpensiveToCopyType VarCopyConstructed(Obj.reference());
+ // CHECK-MESSAGES: [[@LINE-1]]:29: warning: the const qualified variable 'VarCopyConstructed'
+ // CHECK-FIXES: const ExpensiveToCopyType& VarCopyConstructed(Obj.reference());
+}
+
+void PositiveMethodCallConstParam(const ExpensiveToCopyType Obj) {
+ const auto AutoAssigned = Obj.reference();
+ // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'AutoAssigned'
+ // CHECK-FIXES: const auto& AutoAssigned = Obj.reference();
+ const auto AutoCopyConstructed(Obj.reference());
+ // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'AutoCopyConstructed'
+ // CHECK-FIXES: const auto& AutoCopyConstructed(Obj.reference());
+ const ExpensiveToCopyType VarAssigned = Obj.reference();
+ // CHECK-MESSAGES: [[@LINE-1]]:29: warning: the const qualified variable 'VarAssigned'
+ // CHECK-FIXES: const ExpensiveToCopyType& VarAssigned = Obj.reference();
+ const ExpensiveToCopyType VarCopyConstructed(Obj.reference());
+ // CHECK-MESSAGES: [[@LINE-1]]:29: warning: the const qualified variable 'VarCopyConstructed'
+ // CHECK-FIXES: const ExpensiveToCopyType& VarCopyConstructed(Obj.reference());
+}
+
+void PositiveMethodCallConstPointerParam(const ExpensiveToCopyType *const Obj) {
+ const auto AutoAssigned = Obj->reference();
+ // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'AutoAssigned'
+ // CHECK-FIXES: const auto& AutoAssigned = Obj->reference();
+ const auto AutoCopyConstructed(Obj->reference());
+ // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'AutoCopyConstructed'
+ // CHECK-FIXES: const auto& AutoCopyConstructed(Obj->reference());
+ const ExpensiveToCopyType VarAssigned = Obj->reference();
+ // CHECK-MESSAGES: [[@LINE-1]]:29: warning: the const qualified variable 'VarAssigned'
+ // CHECK-FIXES: const ExpensiveToCopyType& VarAssigned = Obj->reference();
+ const ExpensiveToCopyType VarCopyConstructed(Obj->reference());
+ // CHECK-MESSAGES: [[@LINE-1]]:29: warning: the const qualified variable 'VarCopyConstructed'
+ // CHECK-FIXES: const ExpensiveToCopyType& VarCopyConstructed(Obj->reference());
+}
+
+void PositiveLocalConstValue() {
+ const ExpensiveToCopyType Obj;
+ const auto UnnecessaryCopy = Obj.reference();
+ // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'UnnecessaryCopy'
+ // CHECK-FIXES: const auto& UnnecessaryCopy = Obj.reference();
+}
+
+void PositiveLocalConstRef() {
+ const ExpensiveToCopyType Obj;
+ const ExpensiveToCopyType &ConstReference = Obj.reference();
+ const auto UnnecessaryCopy = ConstReference.reference();
+ // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'UnnecessaryCopy'
+ // CHECK-FIXES: const auto& UnnecessaryCopy = ConstReference.reference();
+}
+
+void PositiveLocalConstPointer() {
+ const ExpensiveToCopyType Obj;
+ const ExpensiveToCopyType *const ConstPointer = &Obj;
+ const auto UnnecessaryCopy = ConstPointer->reference();
+ // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'UnnecessaryCopy'
+ // CHECK-FIXES: const auto& UnnecessaryCopy = ConstPointer->reference();
+}
+
+void NegativeFunctionCallTrivialType() {
+ const auto AutoAssigned = TrivialTypeReference();
+ const auto AutoCopyConstructed(TrivialTypeReference());
+ const TrivialToCopyType VarAssigned = TrivialTypeReference();
+ const TrivialToCopyType VarCopyConstructed(TrivialTypeReference());
+}
+
+void NegativeStaticLocalVar(const ExpensiveToCopyType &Obj) {
+ static const auto StaticVar = Obj.reference();
+}
+
+void PositiveFunctionCallExpensiveTypeNonConstVariable() {
+ auto AutoAssigned = ExpensiveTypeReference();
+ // CHECK-MESSAGES: [[@LINE-1]]:8: warning: the variable 'AutoAssigned' is copy-constructed from a const reference but is only used as const reference; consider making it a const reference [performance-unnecessary-copy-initialization]
+ // CHECK-FIXES: const auto& AutoAssigned = ExpensiveTypeReference();
+ auto AutoCopyConstructed(ExpensiveTypeReference());
+ // CHECK-MESSAGES: [[@LINE-1]]:8: warning: the variable 'AutoCopyConstructed'
+ // CHECK-FIXES: const auto& AutoCopyConstructed(ExpensiveTypeReference());
+ ExpensiveToCopyType VarAssigned = ExpensiveTypeReference();
+ // CHECK-MESSAGES: [[@LINE-1]]:23: warning: the variable 'VarAssigned'
+ // CHECK-FIXES: const ExpensiveToCopyType& VarAssigned = ExpensiveTypeReference();
+ ExpensiveToCopyType VarCopyConstructed(ExpensiveTypeReference());
+ // CHECK-MESSAGES: [[@LINE-1]]:23: warning: the variable 'VarCopyConstructed'
+ // CHECK-FIXES: const ExpensiveToCopyType& VarCopyConstructed(ExpensiveTypeReference());
+}
+
+void positiveNonConstVarInCodeBlock(const ExpensiveToCopyType &Obj) {
+ {
+ auto Assigned = Obj.reference();
+ // CHECK-MESSAGES: [[@LINE-1]]:10: warning: the variable 'Assigned'
+ // CHECK-FIXES: const auto& Assigned = Obj.reference();
+ Assigned.reference();
+ useAsConstReference(Assigned);
+ useByValue(Assigned);
+ }
+}
+
+void negativeNonConstVarWithNonConstUse(const ExpensiveToCopyType &Obj) {
+ {
+ auto NonConstInvoked = Obj.reference();
+ // CHECK-FIXES: auto NonConstInvoked = Obj.reference();
+ NonConstInvoked.nonConstMethod();
+ }
+ {
+ auto Reassigned = Obj.reference();
+ // CHECK-FIXES: auto Reassigned = Obj.reference();
+ Reassigned = ExpensiveToCopyType();
+ }
+ {
+ auto MutatedByReference = Obj.reference();
+ // CHECK-FIXES: auto MutatedByReference = Obj.reference();
+ mutate(MutatedByReference);
+ }
+ {
+ auto MutatedByPointer = Obj.reference();
+ // CHECK-FIXES: auto MutatedByPointer = Obj.reference();
+ mutate(&MutatedByPointer);
+ }
+}
+
+void PositiveMethodCallNonConstRefNotModified(ExpensiveToCopyType &Obj) {
+ const auto AutoAssigned = Obj.reference();
+ // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'AutoAssigned'
+ // CHECK-FIXES: const auto& AutoAssigned = Obj.reference();
+}
+
+void NegativeMethodCallNonConstRefIsModified(ExpensiveToCopyType &Obj) {
+ const auto AutoAssigned = Obj.reference();
+ const auto AutoCopyConstructed(Obj.reference());
+ const ExpensiveToCopyType VarAssigned = Obj.reference();
+ const ExpensiveToCopyType VarCopyConstructed(Obj.reference());
+ mutate(&Obj);
+}
+
+void PositiveMethodCallNonConstNotModified(ExpensiveToCopyType Obj) {
+ const auto AutoAssigned = Obj.reference();
+ // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'AutoAssigned'
+ // CHECK-FIXES: const auto& AutoAssigned = Obj.reference();
+}
+
+void NegativeMethodCallNonConstValueArgumentIsModified(ExpensiveToCopyType Obj) {
+ Obj.nonConstMethod();
+ const auto AutoAssigned = Obj.reference();
+}
+
+void PositiveMethodCallNonConstPointerNotModified(ExpensiveToCopyType *const Obj) {
+ const auto AutoAssigned = Obj->reference();
+ // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'AutoAssigned'
+ // CHECK-FIXES: const auto& AutoAssigned = Obj->reference();
+ Obj->constMethod();
+}
+
+void NegativeMethodCallNonConstPointerIsModified(ExpensiveToCopyType *const Obj) {
+ const auto AutoAssigned = Obj->reference();
+ const auto AutoCopyConstructed(Obj->reference());
+ const ExpensiveToCopyType VarAssigned = Obj->reference();
+ const ExpensiveToCopyType VarCopyConstructed(Obj->reference());
+ mutate(Obj);
+}
+
+void PositiveLocalVarIsNotModified() {
+ ExpensiveToCopyType LocalVar;
+ const auto AutoAssigned = LocalVar.reference();
+ // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'AutoAssigned'
+ // CHECK-FIXES: const auto& AutoAssigned = LocalVar.reference();
+}
+
+void NegativeLocalVarIsModified() {
+ ExpensiveToCopyType Obj;
+ const auto AutoAssigned = Obj.reference();
+ Obj = AutoAssigned;
+}
+
+struct NegativeConstructor {
+ NegativeConstructor(const ExpensiveToCopyType &Obj) : Obj(Obj) {}
+ ExpensiveToCopyType Obj;
+};
+
+#define UNNECESSARY_COPY_INIT_IN_MACRO_BODY(TYPE) \
+ void functionWith##TYPE(const TYPE &T) { \
+ auto AssignedInMacro = T.reference(); \
+ } \
+// Ensure fix is not applied.
+// CHECK-FIXES: auto AssignedInMacro = T.reference();
+
+UNNECESSARY_COPY_INIT_IN_MACRO_BODY(ExpensiveToCopyType)
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: the variable 'AssignedInMacro' is copy-constructed
+
+#define UNNECESSARY_COPY_INIT_IN_MACRO_ARGUMENT(ARGUMENT) ARGUMENT
+
+void PositiveMacroArgument(const ExpensiveToCopyType &Obj) {
+ UNNECESSARY_COPY_INIT_IN_MACRO_ARGUMENT(auto CopyInMacroArg = Obj.reference());
+ // CHECK-MESSAGES: [[@LINE-1]]:48: warning: the variable 'CopyInMacroArg' is copy-constructed
+ // Ensure fix is not applied.
+ // CHECK-FIXES: auto CopyInMacroArg = Obj.reference()
+}
+
+void PositiveLocalCopyConstMethodInvoked() {
+ ExpensiveToCopyType orig;
+ ExpensiveToCopyType copy_1 = orig;
+ // CHECK-MESSAGES: [[@LINE-1]]:23: warning: local copy 'copy_1' of the variable 'orig' is never modified; consider avoiding the copy [performance-unnecessary-copy-initialization]
+ // CHECK-FIXES: const ExpensiveToCopyType& copy_1 = orig;
+ copy_1.constMethod();
+ orig.constMethod();
+}
+
+void PositiveLocalCopyUsingExplicitCopyCtor() {
+ ExpensiveToCopyType orig;
+ ExpensiveToCopyType copy_2(orig);
+ // CHECK-MESSAGES: [[@LINE-1]]:23: warning: local copy 'copy_2'
+ // CHECK-FIXES: const ExpensiveToCopyType& copy_2(orig);
+ copy_2.constMethod();
+ orig.constMethod();
+}
+
+void PositiveLocalCopyCopyIsArgument(const ExpensiveToCopyType &orig) {
+ ExpensiveToCopyType copy_3 = orig;
+ // CHECK-MESSAGES: [[@LINE-1]]:23: warning: local copy 'copy_3'
+ // CHECK-FIXES: const ExpensiveToCopyType& copy_3 = orig;
+ copy_3.constMethod();
+}
+
+void PositiveLocalCopyUsedAsConstRef() {
+ ExpensiveToCopyType orig;
+ ExpensiveToCopyType copy_4 = orig;
+ // CHECK-MESSAGES: [[@LINE-1]]:23: warning: local copy 'copy_4'
+ // CHECK-FIXES: const ExpensiveToCopyType& copy_4 = orig;
+ useAsConstReference(orig);
+}
+
+void PositiveLocalCopyTwice() {
+ ExpensiveToCopyType orig;
+ ExpensiveToCopyType copy_5 = orig;
+ // CHECK-MESSAGES: [[@LINE-1]]:23: warning: local copy 'copy_5'
+ // CHECK-FIXES: const ExpensiveToCopyType& copy_5 = orig;
+ ExpensiveToCopyType copy_6 = copy_5;
+ // CHECK-MESSAGES: [[@LINE-1]]:23: warning: local copy 'copy_6'
+ // CHECK-FIXES: const ExpensiveToCopyType& copy_6 = copy_5;
+ copy_5.constMethod();
+ copy_6.constMethod();
+ orig.constMethod();
+}
+
+
+void PositiveLocalCopyWeirdCopy() {
+ WeirdCopyCtorType orig;
+ WeirdCopyCtorType weird_1(orig);
+ // CHECK-MESSAGES: [[@LINE-1]]:21: warning: local copy 'weird_1'
+ // CHECK-FIXES: const WeirdCopyCtorType& weird_1(orig);
+ weird_1.constMethod();
+
+ WeirdCopyCtorType weird_2 = orig;
+ // CHECK-MESSAGES: [[@LINE-1]]:21: warning: local copy 'weird_2'
+ // CHECK-FIXES: const WeirdCopyCtorType& weird_2 = orig;
+ weird_2.constMethod();
+}
+
+void NegativeLocalCopySimpleTypes() {
+ int i1 = 0;
+ int i2 = i1;
+}
+
+void NegativeLocalCopyCopyIsModified() {
+ ExpensiveToCopyType orig;
+ ExpensiveToCopyType neg_copy_1 = orig;
+ neg_copy_1.nonConstMethod();
+}
+
+void NegativeLocalCopyOriginalIsModified() {
+ ExpensiveToCopyType orig;
+ ExpensiveToCopyType neg_copy_2 = orig;
+ orig.nonConstMethod();
+}
+
+void NegativeLocalCopyUsedAsRefArg() {
+ ExpensiveToCopyType orig;
+ ExpensiveToCopyType neg_copy_3 = orig;
+ mutate(neg_copy_3);
+}
+
+void NegativeLocalCopyUsedAsPointerArg() {
+ ExpensiveToCopyType orig;
+ ExpensiveToCopyType neg_copy_4 = orig;
+ mutate(&neg_copy_4);
+}
+
+void NegativeLocalCopyCopyFromGlobal() {
+ ExpensiveToCopyType neg_copy_5 = global_expensive_to_copy_type;
+}
+
+void NegativeLocalCopyCopyToStatic() {
+ ExpensiveToCopyType orig;
+ static ExpensiveToCopyType neg_copy_6 = orig;
+}
+
+void NegativeLocalCopyNonConstInForLoop() {
+ ExpensiveToCopyType orig;
+ for (ExpensiveToCopyType neg_copy_7 = orig; orig.constMethod();
+ orig.nonConstMethod()) {
+ orig.constMethod();
+ }
+}
+
+void NegativeLocalCopyWeirdNonCopy() {
+ WeirdCopyCtorType orig;
+ WeirdCopyCtorType neg_weird_1(orig, false);
+ WeirdCopyCtorType neg_weird_2(orig, true);
+}
+void WarningOnlyMultiDeclStmt() {
+ ExpensiveToCopyType orig;
+ ExpensiveToCopyType copy = orig, copy2;
+ // CHECK-MESSAGES: [[@LINE-1]]:23: warning: local copy 'copy' of the variable 'orig' is never modified; consider avoiding the copy [performance-unnecessary-copy-initialization]
+ // CHECK-FIXES: ExpensiveToCopyType copy = orig, copy2;
+}
+
+class Element {};
+class Container {
+public:
+ class Iterator {
+ public:
+ void operator++();
+ Element operator*();
+ bool operator!=(const Iterator &);
+ WeirdCopyCtorType c;
+ };
+ const Iterator &begin() const;
+ const Iterator &end() const;
+};
+
+void implicitVarFalsePositive() {
+ for (const Element &E : Container()) {
+ }
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/performance-unnecessary-value-param-allowed-types.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/performance-unnecessary-value-param-allowed-types.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/performance-unnecessary-value-param-allowed-types.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/performance-unnecessary-value-param-allowed-types.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,75 @@
+// RUN: %check_clang_tidy %s performance-unnecessary-value-param %t -- -config="{CheckOptions: [{key: performance-unnecessary-value-param.AllowedTypes, value: '[Pp]ointer$;[Pp]tr$;[Rr]ef(erence)?$'}]}" --
+
+struct SmartPointer {
+ ~SmartPointer();
+};
+
+struct smart_pointer {
+ ~smart_pointer();
+};
+
+struct SmartPtr {
+ ~SmartPtr();
+};
+
+struct smart_ptr {
+ ~smart_ptr();
+};
+
+struct SmartReference {
+ ~SmartReference();
+};
+
+struct smart_reference {
+ ~smart_reference();
+};
+
+struct SmartRef {
+ ~SmartRef();
+};
+
+struct smart_ref {
+ ~smart_ref();
+};
+
+struct OtherType {
+ ~OtherType();
+};
+
+template <typename T> struct SomeComplexTemplate {
+ ~SomeComplexTemplate();
+};
+
+typedef SomeComplexTemplate<int> NotTooComplexRef;
+
+void negativeSmartPointer(SmartPointer P) {
+}
+
+void negative_smart_pointer(smart_pointer p) {
+}
+
+void negativeSmartPtr(SmartPtr P) {
+}
+
+void negative_smart_ptr(smart_ptr p) {
+}
+
+void negativeSmartReference(SmartReference R) {
+}
+
+void negative_smart_reference(smart_reference r) {
+}
+
+void negativeSmartRef(SmartRef R) {
+}
+
+void negative_smart_ref(smart_ref r) {
+}
+
+void positiveOtherType(OtherType O) {
+ // CHECK-MESSAGES: [[@LINE-1]]:34: warning: the parameter 'O' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]
+ // CHECK-FIXES: void positiveOtherType(const OtherType& O) {
+}
+
+void negativeNotTooComplexRef(NotTooComplexRef R) {
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/performance-unnecessary-value-param-arc.m
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/performance-unnecessary-value-param-arc.m?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/performance-unnecessary-value-param-arc.m (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/performance-unnecessary-value-param-arc.m Fri Oct 11 05:05:42 2019
@@ -0,0 +1,16 @@
+// RUN: clang-tidy %s -checks=-*,performance-unnecessary-value-param -- \
+// RUN: -xobjective-c -fobjc-abi-version=2 -fobjc-arc | count 0
+
+#if !__has_feature(objc_arc)
+#error Objective-C ARC not enabled as expected
+#endif
+
+// Passing an Objective-C ARC-managed object to a C function should
+// not raise performance-unnecessary-value-param.
+void foo(id object) { }
+
+// Same for explcitly non-ARC-managed Objective-C objects.
+void bar(__unsafe_unretained id object) { }
+
+// Same for Objective-c classes.
+void baz(Class c) { }
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/performance-unnecessary-value-param-arc.mm
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/performance-unnecessary-value-param-arc.mm?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/performance-unnecessary-value-param-arc.mm (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/performance-unnecessary-value-param-arc.mm Fri Oct 11 05:05:42 2019
@@ -0,0 +1,16 @@
+// RUN: clang-tidy %s -checks=-*,performance-unnecessary-value-param -- \
+// RUN: -xobjective-c++ -fobjc-abi-version=2 -fobjc-arc | count 0
+
+#if !__has_feature(objc_arc)
+#error Objective-C ARC not enabled as expected
+#endif
+
+// Passing an Objective-C ARC-managed object to a C function should
+// not raise performance-unnecessary-value-param.
+void foo(id object) { }
+
+// Same for explcitly non-ARC-managed Objective-C objects.
+void bar(__unsafe_unretained id object) { }
+
+// Same for Objective-c classes.
+void baz(Class c) { }
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/performance-unnecessary-value-param-delayed.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/performance-unnecessary-value-param-delayed.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/performance-unnecessary-value-param-delayed.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/performance-unnecessary-value-param-delayed.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,181 @@
+// RUN: %check_clang_tidy %s performance-unnecessary-value-param %t -- -- -fdelayed-template-parsing
+
+struct ExpensiveToCopyType {
+ const ExpensiveToCopyType & constReference() const {
+ return *this;
+ }
+ void nonConstMethod();
+ virtual ~ExpensiveToCopyType();
+};
+
+void mutate(ExpensiveToCopyType &);
+void mutate(ExpensiveToCopyType *);
+void useAsConstReference(const ExpensiveToCopyType &);
+void useByValue(ExpensiveToCopyType);
+
+// This class simulates std::pair<>. It is trivially copy constructible
+// and trivially destructible, but not trivially copy assignable.
+class SomewhatTrivial {
+ public:
+ SomewhatTrivial();
+ SomewhatTrivial(const SomewhatTrivial&) = default;
+ ~SomewhatTrivial() = default;
+ SomewhatTrivial& operator=(const SomewhatTrivial&);
+};
+
+void positiveExpensiveConstValue(const ExpensiveToCopyType Obj);
+// CHECK-FIXES: void positiveExpensiveConstValue(const ExpensiveToCopyType& Obj);
+void positiveExpensiveConstValue(const ExpensiveToCopyType Obj) {
+ // CHECK-MESSAGES: [[@LINE-1]]:60: warning: the const qualified parameter 'Obj' is copied for each invocation; consider making it a reference [performance-unnecessary-value-param]
+ // CHECK-FIXES: void positiveExpensiveConstValue(const ExpensiveToCopyType& Obj) {
+}
+
+void positiveExpensiveValue(ExpensiveToCopyType Obj);
+// CHECK-FIXES: void positiveExpensiveValue(const ExpensiveToCopyType& Obj);
+void positiveExpensiveValue(ExpensiveToCopyType Obj) {
+ // CHECK-MESSAGES: [[@LINE-1]]:49: warning: the parameter 'Obj' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]
+ // CHECK-FIXES: void positiveExpensiveValue(const ExpensiveToCopyType& Obj) {
+ Obj.constReference();
+ useAsConstReference(Obj);
+ auto Copy = Obj;
+ useByValue(Obj);
+}
+
+void positiveWithComment(const ExpensiveToCopyType /* important */ S);
+// CHECK-FIXES: void positiveWithComment(const ExpensiveToCopyType& /* important */ S);
+void positiveWithComment(const ExpensiveToCopyType /* important */ S) {
+ // CHECK-MESSAGES: [[@LINE-1]]:68: warning: the const qualified
+ // CHECK-FIXES: void positiveWithComment(const ExpensiveToCopyType& /* important */ S) {
+}
+
+void positiveUnnamedParam(const ExpensiveToCopyType) {
+ // CHECK-MESSAGES: [[@LINE-1]]:52: warning: the const qualified parameter #1
+ // CHECK-FIXES: void positiveUnnamedParam(const ExpensiveToCopyType&) {
+}
+
+void positiveAndNegative(const ExpensiveToCopyType ConstCopy, const ExpensiveToCopyType& ConstRef, ExpensiveToCopyType Copy);
+// CHECK-FIXES: void positiveAndNegative(const ExpensiveToCopyType& ConstCopy, const ExpensiveToCopyType& ConstRef, const ExpensiveToCopyType& Copy);
+void positiveAndNegative(const ExpensiveToCopyType ConstCopy, const ExpensiveToCopyType& ConstRef, ExpensiveToCopyType Copy) {
+ // CHECK-MESSAGES: [[@LINE-1]]:52: warning: the const qualified parameter 'ConstCopy'
+ // CHECK-MESSAGES: [[@LINE-2]]:120: warning: the parameter 'Copy'
+ // CHECK-FIXES: void positiveAndNegative(const ExpensiveToCopyType& ConstCopy, const ExpensiveToCopyType& ConstRef, const ExpensiveToCopyType& Copy) {
+}
+
+struct PositiveConstValueConstructor {
+ PositiveConstValueConstructor(const ExpensiveToCopyType ConstCopy) {}
+ // CHECK-MESSAGES: [[@LINE-1]]:59: warning: the const qualified parameter 'ConstCopy'
+ // CHECK-FIXES: PositiveConstValueConstructor(const ExpensiveToCopyType& ConstCopy) {}
+};
+
+template <typename T> void templateWithNonTemplatizedParameter(const ExpensiveToCopyType S, T V) {
+ // CHECK-MESSAGES: [[@LINE-1]]:90: warning: the const qualified parameter 'S'
+ // CHECK-FIXES: template <typename T> void templateWithNonTemplatizedParameter(const ExpensiveToCopyType& S, T V) {
+}
+
+void instantiated() {
+ templateWithNonTemplatizedParameter(ExpensiveToCopyType(), ExpensiveToCopyType());
+ templateWithNonTemplatizedParameter(ExpensiveToCopyType(), 5);
+}
+
+template <typename T> void negativeTemplateType(const T V) {
+}
+
+void negativeArray(const ExpensiveToCopyType[]) {
+}
+
+void negativePointer(ExpensiveToCopyType* Obj) {
+}
+
+void negativeConstPointer(const ExpensiveToCopyType* Obj) {
+}
+
+void negativeConstReference(const ExpensiveToCopyType& Obj) {
+}
+
+void negativeReference(ExpensiveToCopyType& Obj) {
+}
+
+void negativeUniversalReference(ExpensiveToCopyType&& Obj) {
+}
+
+void negativeSomewhatTrivialConstValue(const SomewhatTrivial Somewhat) {
+}
+
+void negativeSomewhatTrivialValue(SomewhatTrivial Somewhat) {
+}
+
+void negativeConstBuiltIn(const int I) {
+}
+
+void negativeValueBuiltIn(int I) {
+}
+
+void negativeValueIsMutatedByReference(ExpensiveToCopyType Obj) {
+ mutate(Obj);
+}
+
+void negativeValueIsMutatatedByPointer(ExpensiveToCopyType Obj) {
+ mutate(&Obj);
+}
+
+void negativeValueIsReassigned(ExpensiveToCopyType Obj) {
+ Obj = ExpensiveToCopyType();
+}
+
+void negativeValueNonConstMethodIsCalled(ExpensiveToCopyType Obj) {
+ Obj.nonConstMethod();
+}
+
+struct PositiveValueUnusedConstructor {
+ PositiveValueUnusedConstructor(ExpensiveToCopyType Copy) {}
+ // CHECK-MESSAGES: [[@LINE-1]]:54: warning: the parameter 'Copy'
+ // CHECK-FIXES: PositiveValueUnusedConstructor(const ExpensiveToCopyType& Copy) {}
+};
+
+struct PositiveValueCopiedConstructor {
+ PositiveValueCopiedConstructor(ExpensiveToCopyType Copy) : Field(Copy) {}
+ // CHECK-MESSAGES: [[@LINE-1]]:54: warning: the parameter 'Copy'
+ // CHECK-FIXES: PositiveValueCopiedConstructor(const ExpensiveToCopyType& Copy) : Field(Copy) {}
+ ExpensiveToCopyType Field;
+};
+
+template <typename T>
+struct Container {
+ typedef const T & const_reference;
+};
+
+void NegativeTypedefParam(const Container<ExpensiveToCopyType>::const_reference Param) {
+}
+
+#define UNNECESSARY_VALUE_PARAM_IN_MACRO_BODY() \
+ void inMacro(const ExpensiveToCopyType T) { \
+ } \
+// Ensure fix is not applied.
+// CHECK-FIXES: void inMacro(const ExpensiveToCopyType T) {
+
+UNNECESSARY_VALUE_PARAM_IN_MACRO_BODY()
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: the const qualified parameter 'T'
+
+#define UNNECESSARY_VALUE_PARAM_IN_MACRO_ARGUMENT(ARGUMENT) \
+ ARGUMENT
+
+UNNECESSARY_VALUE_PARAM_IN_MACRO_ARGUMENT(void inMacroArgument(const ExpensiveToCopyType InMacroArg) {})
+// CHECK-MESSAGES: [[@LINE-1]]:90: warning: the const qualified parameter 'InMacroArg'
+// CHECK-FIXES: void inMacroArgument(const ExpensiveToCopyType InMacroArg) {}
+
+struct VirtualMethod {
+ virtual ~VirtualMethod() {}
+ virtual void handle(ExpensiveToCopyType T) const = 0;
+};
+
+struct NegativeOverriddenMethod : public VirtualMethod {
+ void handle(ExpensiveToCopyType Overridden) const {
+ // CHECK-FIXES: handle(ExpensiveToCopyType Overridden) const {
+ }
+};
+
+struct NegativeDeletedMethod {
+ ~NegativeDeletedMethod() {}
+ NegativeDeletedMethod& operator=(NegativeDeletedMethod N) = delete;
+ // CHECK-FIXES: NegativeDeletedMethod& operator=(NegativeDeletedMethod N) = delete;
+};
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/performance-unnecessary-value-param-header.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/performance-unnecessary-value-param-header.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/performance-unnecessary-value-param-header.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/performance-unnecessary-value-param-header.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,21 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: cp %S/Inputs/performance-unnecessary-value-param/header.h %t/header.h
+// RUN: %check_clang_tidy -std=c++11 %s performance-unnecessary-value-param %t/temp -- -- -I %t
+// RUN: diff %t/header.h %S/Inputs/performance-unnecessary-value-param/header-fixed.h
+// FIXME: Make the test work in all language modes.
+
+#include "header.h"
+
+
+
+int f1(int n, ABC v1, ABC v2) {
+ // CHECK-MESSAGES: [[@LINE-1]]:19: warning: the parameter 'v1' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]
+ // CHECK-MESSAGES: [[@LINE-2]]:27: warning: the parameter 'v2' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]
+ // CHECK-FIXES: int f1(int n, const ABC& v1, const ABC& v2) {
+ return v1.get(n) + v2.get(n);
+}
+int f2(int n, ABC v2) {
+ // CHECK-MESSAGES: [[@LINE-1]]:19: warning: the parameter 'v2' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]
+ // CHECK-FIXES: int f2(int n, const ABC& v2) {
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/performance-unnecessary-value-param-incomplete-type.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/performance-unnecessary-value-param-incomplete-type.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/performance-unnecessary-value-param-incomplete-type.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/performance-unnecessary-value-param-incomplete-type.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,9 @@
+// RUN: %check_clang_tidy %s performance-unnecessary-value-param %t -- -fix-errors
+
+// Ensure that incomplete types result in an error from the frontend and not a
+// clang-tidy diagnostic about IncompleteType being expensive to copy.
+struct IncompleteType;
+void NegativeForIncompleteType(IncompleteType I) {
+ // CHECK-MESSAGES: [[@LINE-1]]:47: error: variable has incomplete type 'IncompleteType' [clang-diagnostic-error]
+}
+
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/performance-unnecessary-value-param.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/performance-unnecessary-value-param.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/performance-unnecessary-value-param.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/performance-unnecessary-value-param.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,383 @@
+// RUN: %check_clang_tidy %s performance-unnecessary-value-param %t
+
+// CHECK-FIXES: #include <utility>
+
+struct ExpensiveToCopyType {
+ const ExpensiveToCopyType & constReference() const {
+ return *this;
+ }
+ void nonConstMethod();
+ virtual ~ExpensiveToCopyType();
+};
+
+void mutate(ExpensiveToCopyType &);
+void mutate(ExpensiveToCopyType *);
+void useAsConstReference(const ExpensiveToCopyType &);
+void useByValue(ExpensiveToCopyType);
+
+template <class T> class Vector {
+ public:
+ using iterator = T*;
+ using const_iterator = const T*;
+
+ Vector(const Vector&);
+ Vector& operator=(const Vector&);
+
+ iterator begin();
+ iterator end();
+ const_iterator begin() const;
+ const_iterator end() const;
+};
+
+// This class simulates std::pair<>. It is trivially copy constructible
+// and trivially destructible, but not trivially copy assignable.
+class SomewhatTrivial {
+ public:
+ SomewhatTrivial();
+ SomewhatTrivial(const SomewhatTrivial&) = default;
+ ~SomewhatTrivial() = default;
+ SomewhatTrivial& operator=(const SomewhatTrivial&);
+};
+
+struct MoveOnlyType {
+ MoveOnlyType(const MoveOnlyType &) = delete;
+ MoveOnlyType(MoveOnlyType &&) = default;
+ ~MoveOnlyType();
+ void constMethod() const;
+};
+
+struct ExpensiveMovableType {
+ ExpensiveMovableType();
+ ExpensiveMovableType(ExpensiveMovableType &&);
+ ExpensiveMovableType(const ExpensiveMovableType &) = default;
+ ExpensiveMovableType &operator=(const ExpensiveMovableType &) = default;
+ ExpensiveMovableType &operator=(ExpensiveMovableType &&);
+ ~ExpensiveMovableType();
+};
+
+void positiveExpensiveConstValue(const ExpensiveToCopyType Obj);
+// CHECK-FIXES: void positiveExpensiveConstValue(const ExpensiveToCopyType& Obj);
+void positiveExpensiveConstValue(const ExpensiveToCopyType Obj) {
+ // CHECK-MESSAGES: [[@LINE-1]]:60: warning: the const qualified parameter 'Obj' is copied for each invocation; consider making it a reference [performance-unnecessary-value-param]
+ // CHECK-FIXES: void positiveExpensiveConstValue(const ExpensiveToCopyType& Obj) {
+}
+
+void positiveExpensiveValue(ExpensiveToCopyType Obj);
+// CHECK-FIXES: void positiveExpensiveValue(const ExpensiveToCopyType& Obj);
+void positiveExpensiveValue(ExpensiveToCopyType Obj) {
+ // CHECK-MESSAGES: [[@LINE-1]]:49: warning: the parameter 'Obj' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]
+ // CHECK-FIXES: void positiveExpensiveValue(const ExpensiveToCopyType& Obj) {
+ Obj.constReference();
+ useAsConstReference(Obj);
+ auto Copy = Obj;
+ useByValue(Obj);
+}
+
+void positiveVector(Vector<ExpensiveToCopyType> V) {
+ // CHECK-MESSAGES: [[@LINE-1]]:49: warning: the parameter 'V' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]
+ // CHECK-FIXES: void positiveVector(const Vector<ExpensiveToCopyType>& V) {
+ for (const auto& Obj : V) {
+ useByValue(Obj);
+ }
+}
+
+void positiveWithComment(const ExpensiveToCopyType /* important */ S);
+// CHECK-FIXES: void positiveWithComment(const ExpensiveToCopyType& /* important */ S);
+void positiveWithComment(const ExpensiveToCopyType /* important */ S) {
+ // CHECK-MESSAGES: [[@LINE-1]]:68: warning: the const qualified
+ // CHECK-FIXES: void positiveWithComment(const ExpensiveToCopyType& /* important */ S) {
+}
+
+void positiveUnnamedParam(const ExpensiveToCopyType) {
+ // CHECK-MESSAGES: [[@LINE-1]]:52: warning: the const qualified parameter #1
+ // CHECK-FIXES: void positiveUnnamedParam(const ExpensiveToCopyType&) {
+}
+
+void positiveAndNegative(const ExpensiveToCopyType ConstCopy, const ExpensiveToCopyType& ConstRef, ExpensiveToCopyType Copy);
+// CHECK-FIXES: void positiveAndNegative(const ExpensiveToCopyType& ConstCopy, const ExpensiveToCopyType& ConstRef, const ExpensiveToCopyType& Copy);
+void positiveAndNegative(const ExpensiveToCopyType ConstCopy, const ExpensiveToCopyType& ConstRef, ExpensiveToCopyType Copy) {
+ // CHECK-MESSAGES: [[@LINE-1]]:52: warning: the const qualified parameter 'ConstCopy'
+ // CHECK-MESSAGES: [[@LINE-2]]:120: warning: the parameter 'Copy'
+ // CHECK-FIXES: void positiveAndNegative(const ExpensiveToCopyType& ConstCopy, const ExpensiveToCopyType& ConstRef, const ExpensiveToCopyType& Copy) {
+}
+
+struct PositiveConstValueConstructor {
+ PositiveConstValueConstructor(const ExpensiveToCopyType ConstCopy) {}
+ // CHECK-MESSAGES: [[@LINE-1]]:59: warning: the const qualified parameter 'ConstCopy'
+ // CHECK-FIXES: PositiveConstValueConstructor(const ExpensiveToCopyType& ConstCopy) {}
+};
+
+template <typename T> void templateWithNonTemplatizedParameter(const ExpensiveToCopyType S, T V) {
+ // CHECK-MESSAGES: [[@LINE-1]]:90: warning: the const qualified parameter 'S'
+ // CHECK-FIXES: template <typename T> void templateWithNonTemplatizedParameter(const ExpensiveToCopyType& S, T V) {
+}
+
+void instantiated() {
+ templateWithNonTemplatizedParameter(ExpensiveToCopyType(), ExpensiveToCopyType());
+ templateWithNonTemplatizedParameter(ExpensiveToCopyType(), 5);
+}
+
+template <typename T> void negativeTemplateType(const T V) {
+}
+
+void negativeArray(const ExpensiveToCopyType[]) {
+}
+
+void negativePointer(ExpensiveToCopyType* Obj) {
+}
+
+void negativeConstPointer(const ExpensiveToCopyType* Obj) {
+}
+
+void negativeConstReference(const ExpensiveToCopyType& Obj) {
+}
+
+void negativeReference(ExpensiveToCopyType& Obj) {
+}
+
+void negativeUniversalReference(ExpensiveToCopyType&& Obj) {
+}
+
+void negativeSomewhatTrivialConstValue(const SomewhatTrivial Somewhat) {
+}
+
+void negativeSomewhatTrivialValue(SomewhatTrivial Somewhat) {
+}
+
+void negativeConstBuiltIn(const int I) {
+}
+
+void negativeValueBuiltIn(int I) {
+}
+
+void negativeValueIsMutatedByReference(ExpensiveToCopyType Obj) {
+ mutate(Obj);
+}
+
+void negativeValueIsMutatatedByPointer(ExpensiveToCopyType Obj) {
+ mutate(&Obj);
+}
+
+void negativeValueIsReassigned(ExpensiveToCopyType Obj) {
+ Obj = ExpensiveToCopyType();
+}
+
+void negativeValueNonConstMethodIsCalled(ExpensiveToCopyType Obj) {
+ Obj.nonConstMethod();
+}
+
+struct PositiveValueUnusedConstructor {
+ PositiveValueUnusedConstructor(ExpensiveToCopyType Copy) {}
+ // CHECK-MESSAGES: [[@LINE-1]]:54: warning: the parameter 'Copy'
+ // CHECK-FIXES: PositiveValueUnusedConstructor(const ExpensiveToCopyType& Copy) {}
+};
+
+struct PositiveValueCopiedConstructor {
+ PositiveValueCopiedConstructor(ExpensiveToCopyType Copy) : Field(Copy) {}
+ // CHECK-MESSAGES: [[@LINE-1]]:54: warning: the parameter 'Copy'
+ // CHECK-FIXES: PositiveValueCopiedConstructor(const ExpensiveToCopyType& Copy) : Field(Copy) {}
+ ExpensiveToCopyType Field;
+};
+
+struct PositiveValueMovableConstructor {
+ PositiveValueMovableConstructor(ExpensiveMovableType Copy) : Field(Copy) {}
+ // CHECK-MESSAGES: [[@LINE-1]]:70: warning: parameter 'Copy'
+ // CHECK-FIXES: PositiveValueMovableConstructor(ExpensiveMovableType Copy) : Field(std::move(Copy)) {}
+ ExpensiveMovableType Field;
+};
+
+struct NegativeValueMovedConstructor {
+ NegativeValueMovedConstructor(ExpensiveMovableType Copy) : Field(static_cast<ExpensiveMovableType &&>(Copy)) {}
+ ExpensiveMovableType Field;
+};
+
+template <typename T>
+struct Container {
+ typedef const T & const_reference;
+};
+
+void NegativeTypedefParam(const Container<ExpensiveToCopyType>::const_reference Param) {
+}
+
+#define UNNECESSARY_VALUE_PARAM_IN_MACRO_BODY() \
+ void inMacro(const ExpensiveToCopyType T) { \
+ } \
+// Ensure fix is not applied.
+// CHECK-FIXES: void inMacro(const ExpensiveToCopyType T) {
+
+UNNECESSARY_VALUE_PARAM_IN_MACRO_BODY()
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: the const qualified parameter 'T'
+
+#define UNNECESSARY_VALUE_PARAM_IN_MACRO_ARGUMENT(ARGUMENT) \
+ ARGUMENT
+
+UNNECESSARY_VALUE_PARAM_IN_MACRO_ARGUMENT(void inMacroArgument(const ExpensiveToCopyType InMacroArg) {})
+// CHECK-MESSAGES: [[@LINE-1]]:90: warning: the const qualified parameter 'InMacroArg'
+// CHECK-FIXES: void inMacroArgument(const ExpensiveToCopyType InMacroArg) {}
+
+struct VirtualMethod {
+ virtual ~VirtualMethod() {}
+ virtual void handle(ExpensiveToCopyType T) const = 0;
+};
+
+struct NegativeOverriddenMethod : public VirtualMethod {
+ void handle(ExpensiveToCopyType Overridden) const {
+ // CHECK-FIXES: handle(ExpensiveToCopyType Overridden) const {
+ }
+};
+
+struct VirtualMethodWarningOnly {
+ virtual void methodWithExpensiveValueParam(ExpensiveToCopyType T) {}
+ // CHECK-MESSAGES: [[@LINE-1]]:66: warning: the parameter 'T' is copied
+ // CHECK-FIXES: virtual void methodWithExpensiveValueParam(ExpensiveToCopyType T) {}
+ virtual ~VirtualMethodWarningOnly() {}
+};
+
+struct PositiveNonVirualMethod {
+ void method(const ExpensiveToCopyType T) {}
+ // CHECK-MESSAGES: [[@LINE-1]]:41: warning: the const qualified parameter 'T' is copied
+ // CHECK-FIXES: void method(const ExpensiveToCopyType& T) {}
+};
+
+struct NegativeDeletedMethod {
+ ~NegativeDeletedMethod() {}
+ NegativeDeletedMethod& operator=(NegativeDeletedMethod N) = delete;
+ // CHECK-FIXES: NegativeDeletedMethod& operator=(NegativeDeletedMethod N) = delete;
+};
+
+void NegativeMoveOnlyTypePassedByValue(MoveOnlyType M) {
+ M.constMethod();
+}
+
+void PositiveMoveOnCopyConstruction(ExpensiveMovableType E) {
+ auto F = E;
+ // CHECK-MESSAGES: [[@LINE-1]]:12: warning: parameter 'E' is passed by value and only copied once; consider moving it to avoid unnecessary copies [performance-unnecessary-value-param]
+ // CHECK-FIXES: auto F = std::move(E);
+}
+
+void PositiveConstRefNotMoveSinceReferencedMultipleTimes(ExpensiveMovableType E) {
+ // CHECK-MESSAGES: [[@LINE-1]]:79: warning: the parameter 'E' is copied
+ // CHECK-FIXES: void PositiveConstRefNotMoveSinceReferencedMultipleTimes(const ExpensiveMovableType& E) {
+ auto F = E;
+ auto G = E;
+}
+
+void PositiveMoveOnCopyAssignment(ExpensiveMovableType E) {
+ ExpensiveMovableType F;
+ F = E;
+ // CHECK-MESSAGES: [[@LINE-1]]:7: warning: parameter 'E' is passed by value
+ // CHECK-FIXES: F = std::move(E);
+}
+
+struct NotCopyAssigned {
+ NotCopyAssigned &operator=(const ExpensiveMovableType &);
+};
+
+void PositiveNoMoveForNonCopyAssigmentOperator(ExpensiveMovableType E) {
+ // CHECK-MESSAGES: [[@LINE-1]]:69: warning: the parameter 'E' is copied
+ // CHECK-FIXES: void PositiveNoMoveForNonCopyAssigmentOperator(const ExpensiveMovableType& E) {
+ NotCopyAssigned N;
+ N = E;
+}
+
+// The argument could be moved but is not since copy statement is inside a loop.
+void PositiveNoMoveInsideLoop(ExpensiveMovableType E) {
+ // CHECK-MESSAGES: [[@LINE-1]]:52: warning: the parameter 'E' is copied
+ // CHECK-FIXES: void PositiveNoMoveInsideLoop(const ExpensiveMovableType& E) {
+ for (;;) {
+ auto F = E;
+ }
+}
+
+void PositiveConstRefNotMoveConstructible(ExpensiveToCopyType T) {
+ // CHECK-MESSAGES: [[@LINE-1]]:63: warning: the parameter 'T' is copied
+ // CHECK-FIXES: void PositiveConstRefNotMoveConstructible(const ExpensiveToCopyType& T) {
+ auto U = T;
+}
+
+void PositiveConstRefNotMoveAssignable(ExpensiveToCopyType A) {
+ // CHECK-MESSAGES: [[@LINE-1]]:60: warning: the parameter 'A' is copied
+ // CHECK-FIXES: void PositiveConstRefNotMoveAssignable(const ExpensiveToCopyType& A) {
+ ExpensiveToCopyType B;
+ B = A;
+}
+
+// Case where parameter in declaration is already const-qualified but not in
+// implementation. Make sure a second 'const' is not added to the declaration.
+void PositiveConstDeclaration(const ExpensiveToCopyType A);
+// CHECK-FIXES: void PositiveConstDeclaration(const ExpensiveToCopyType& A);
+void PositiveConstDeclaration(ExpensiveToCopyType A) {
+ // CHECK-MESSAGES: [[@LINE-1]]:51: warning: the parameter 'A' is copied
+ // CHECK-FIXES: void PositiveConstDeclaration(const ExpensiveToCopyType& A) {
+}
+
+void PositiveNonConstDeclaration(ExpensiveToCopyType A);
+// CHECK-FIXES: void PositiveNonConstDeclaration(const ExpensiveToCopyType& A);
+void PositiveNonConstDeclaration(const ExpensiveToCopyType A) {
+ // CHECK-MESSAGES: [[@LINE-1]]:60: warning: the const qualified parameter 'A'
+ // CHECK-FIXES: void PositiveNonConstDeclaration(const ExpensiveToCopyType& A) {
+}
+
+void PositiveOnlyMessageAsReferencedInCompilationUnit(ExpensiveToCopyType A) {
+ // CHECK-MESSAGES: [[@LINE-1]]:75: warning: the parameter 'A' is copied
+ // CHECK-FIXES: void PositiveOnlyMessageAsReferencedInCompilationUnit(ExpensiveToCopyType A) {
+}
+
+void ReferenceFunctionOutsideOfCallExpr() {
+ void (*ptr)(ExpensiveToCopyType) = &PositiveOnlyMessageAsReferencedInCompilationUnit;
+}
+
+void PositiveMessageAndFixAsFunctionIsCalled(ExpensiveToCopyType A) {
+ // CHECK-MESSAGES: [[@LINE-1]]:66: warning: the parameter 'A' is copied
+ // CHECK-FIXES: void PositiveMessageAndFixAsFunctionIsCalled(const ExpensiveToCopyType& A) {
+}
+
+void ReferenceFunctionByCallingIt() {
+ PositiveMessageAndFixAsFunctionIsCalled(ExpensiveToCopyType());
+}
+
+// Virtual method overrides of dependent types cannot be recognized unless they
+// are marked as override or final. Test that check is not triggered on methods
+// marked with override or final.
+template <typename T>
+struct NegativeDependentTypeInterface {
+ virtual void Method(ExpensiveToCopyType E) = 0;
+};
+
+template <typename T>
+struct NegativeOverrideImpl : public NegativeDependentTypeInterface<T> {
+ void Method(ExpensiveToCopyType E) override {}
+};
+
+template <typename T>
+struct NegativeFinalImpl : public NegativeDependentTypeInterface<T> {
+ void Method(ExpensiveToCopyType E) final {}
+};
+
+struct PositiveConstructor {
+ PositiveConstructor(ExpensiveToCopyType E) : E(E) {}
+ // CHECK-MESSAGES: [[@LINE-1]]:43: warning: the parameter 'E' is copied
+ // CHECK-FIXES: PositiveConstructor(const ExpensiveToCopyType& E) : E(E) {}
+
+ ExpensiveToCopyType E;
+};
+
+struct NegativeUsingConstructor : public PositiveConstructor {
+ using PositiveConstructor::PositiveConstructor;
+};
+
+void fun() {
+ ExpensiveToCopyType E;
+ NegativeUsingConstructor S(E);
+}
+
+template<typename T>
+void templateFunction(T) {
+}
+
+template<>
+void templateFunction<ExpensiveToCopyType>(ExpensiveToCopyType E) {
+ // CHECK-MESSAGES: [[@LINE-1]]:64: warning: the parameter 'E' is copied
+ // CHECK-FIXES: void templateFunction<ExpensiveToCopyType>(ExpensiveToCopyType E) {
+ E.constReference();
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/portability-simd-intrinsics-ppc.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/portability-simd-intrinsics-ppc.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/portability-simd-intrinsics-ppc.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/portability-simd-intrinsics-ppc.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,14 @@
+// RUN: %check_clang_tidy -std=c++11,c++14,c++17 %s portability-simd-intrinsics %t -- \
+// RUN: -config='{CheckOptions: [ \
+// RUN: {key: portability-simd-intrinsics.Suggest, value: 1} \
+// RUN: ]}' -- -target ppc64le -maltivec
+// FIXME: Fix the checker to work in C++2a mode.
+
+vector int vec_add(vector int, vector int);
+
+void PPC() {
+ vector int i0, i1;
+
+ vec_add(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [portability-simd-intrinsics]
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/portability-simd-intrinsics-x86.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/portability-simd-intrinsics-x86.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/portability-simd-intrinsics-x86.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/portability-simd-intrinsics-x86.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,26 @@
+// RUN: %check_clang_tidy -std=c++11,c++14,c++17 %s portability-simd-intrinsics %t -- \
+// RUN: -config='{CheckOptions: [ \
+// RUN: {key: portability-simd-intrinsics.Suggest, value: 1} \
+// RUN: ]}' -- -target x86_64
+// FIXME: Fix the checker to work in C++2a mode.
+
+typedef long long __m128i __attribute__((vector_size(16)));
+typedef double __m256 __attribute__((vector_size(32)));
+
+__m128i _mm_add_epi32(__m128i, __m128i);
+__m256 _mm256_load_pd(double const *);
+void _mm256_store_pd(double *, __m256);
+
+int _mm_add_fake(int, int);
+
+void X86() {
+ __m128i i0, i1;
+ __m256 d0;
+
+ _mm_add_epi32(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [portability-simd-intrinsics]
+ d0 = _mm256_load_pd(0);
+ _mm256_store_pd(0, d0);
+
+ _mm_add_fake(0, 1);
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-avoid-const-params-in-decls.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-avoid-const-params-in-decls.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-avoid-const-params-in-decls.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-avoid-const-params-in-decls.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,133 @@
+// RUN: %check_clang_tidy %s readability-avoid-const-params-in-decls %t
+
+using alias_type = bool;
+using alias_const_type = const bool;
+
+
+void F1(const int i);
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 'i' is const-qualified in the function declaration; const-qualification of parameters only has an effect in function definitions [readability-avoid-const-params-in-decls]
+// CHECK-FIXES: void F1(int i);
+
+void F2(const int *const i);
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 'i' is const-qualified
+// CHECK-FIXES: void F2(const int *i);
+
+void F3(int const i);
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 'i' is const-qualified
+// CHECK-FIXES: void F3(int i);
+
+void F4(alias_type const i);
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 'i' is const-qualified
+// CHECK-FIXES: void F4(alias_type i);
+
+void F5(const int);
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 1 is const-qualified
+// CHECK-FIXES: void F5(int);
+
+void F6(const int *const);
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 1 is const-qualified
+// CHECK-FIXES: void F6(const int *);
+
+void F7(int, const int);
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: parameter 2 is const-qualified
+// CHECK-FIXES: void F7(int, int);
+
+void F8(const int, const int);
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 1 is const-qualified
+// CHECK-MESSAGES: :[[@LINE-2]]:20: warning: parameter 2 is const-qualified
+// CHECK-FIXES: void F8(int, int);
+
+void F9(const int long_name);
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 'long_name'
+// CHECK-FIXES: void F9(int long_name);
+
+void F10(const int *const *const long_name);
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: parameter 'long_name'
+// CHECK-FIXES: void F10(const int *const *long_name);
+
+void F11(const unsigned int /*v*/);
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: parameter 1
+// CHECK-FIXES: void F11(unsigned int /*v*/);
+
+void F12(const bool b = true);
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: parameter 'b'
+// CHECK-FIXES: void F12(bool b = true);
+
+template<class T>
+int F13(const bool b = true);
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 'b'
+// CHECK-FIXES: int F13(bool b = true);
+int f13 = F13<int>();
+
+struct Foo {
+ Foo(const int i);
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: parameter 'i'
+ // CHECK-FIXES: Foo(int i);
+
+ void operator()(const int i);
+ // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: parameter 'i'
+ // CHECK-FIXES: void operator()(int i);
+};
+
+template <class T>
+struct FooT {
+ FooT(const int i);
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: parameter 'i'
+ // CHECK-FIXES: FooT(int i);
+
+ void operator()(const int i);
+ // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: parameter 'i'
+ // CHECK-FIXES: void operator()(int i);
+};
+FooT<int> f(1);
+
+// Do not match on definitions
+void NF1(const int i) {}
+void NF2(const int *const i) {}
+void NF3(int const i) {}
+void NF4(alias_type const i) {}
+void NF5(const int) {}
+void NF6(const int *const) {}
+void NF7(int, const int) {}
+void NF8(const int, const int) {}
+template <class T>
+int NF9(const int, const int) { return 0; }
+int nf9 = NF9<int>(1, 2);
+
+// Do not match on inline member functions
+struct Bar {
+ Bar(const int i) {}
+
+ void operator()(const int i) {}
+};
+
+// Do not match on inline member functions of a templated class
+template <class T>
+struct BarT {
+ BarT(const int i) {}
+
+ void operator()(const int i) {}
+};
+BarT<int> b(1);
+
+// Do not match on other stuff
+void NF(const alias_type& i);
+void NF(const int &i);
+void NF(const int *i);
+void NF(alias_const_type i);
+void NF(const alias_type&);
+void NF(const int&);
+void NF(const int*);
+void NF(const int* const*);
+void NF(alias_const_type);
+
+// Regression test for when the 'const' token is not in the code.
+#define CONCAT(a, b) a##b
+void ConstNotVisible(CONCAT(cons, t) int i);
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: parameter 'i'
+// We warn, but we can't give a fix
+// CHECK-FIXES: void ConstNotVisible(CONCAT(cons, t) int i);
+
+// Regression test. We should not warn (or crash) on lambda expressions
+auto lambda_with_name = [](const int n) {};
+auto lambda_without_name = [](const int) {};
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-avoid-underscore-in-googletest-name.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-avoid-underscore-in-googletest-name.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-avoid-underscore-in-googletest-name.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-avoid-underscore-in-googletest-name.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,108 @@
+// RUN: %check_clang_tidy %s google-readability-avoid-underscore-in-googletest-name %t
+
+#define TEST(test_case_name, test_name) void test_case_name##test_name()
+#define TEST_F(test_case_name, test_name) void test_case_name##test_name()
+#define TEST_P(test_case_name, test_name) void test_case_name##test_name()
+#define TYPED_TEST(test_case_name, test_name) void test_case_name##test_name()
+#define TYPED_TEST_P(test_case_name, test_name) void test_case_name##test_name()
+#define FRIEND_TEST(test_case_name, test_name) void test_case_name##test_name()
+
+TEST(TestCaseName, Illegal_TestName) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: avoid using "_" in test name "Illegal_TestName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
+
+TEST(TestCaseName, DISABLED_Illegal_TestName) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: avoid using "_" in test name "Illegal_TestName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
+TEST(TestCaseName, Illegal_Test_Name) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: avoid using "_" in test name "Illegal_Test_Name" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
+TEST(Illegal_TestCaseName, TestName) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: avoid using "_" in test case name "Illegal_TestCaseName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
+TEST(Illegal_Test_CaseName, TestName) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: avoid using "_" in test case name "Illegal_Test_CaseName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
+TEST(Illegal_TestCaseName, Illegal_TestName) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: avoid using "_" in test case name "Illegal_TestCaseName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
+// CHECK-MESSAGES: :[[@LINE-2]]:28: warning: avoid using "_" in test name "Illegal_TestName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
+
+TEST_F(TestCaseFixtureName, Illegal_TestName) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: avoid using "_" in test name "Illegal_TestName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
+TEST_F(TestCaseFixtureName, DISABLED_Illegal_Test_Name) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: avoid using "_" in test name "Illegal_Test_Name" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
+TEST_F(TestCaseFixtureName, Illegal_Test_Name) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: avoid using "_" in test name "Illegal_Test_Name" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
+
+TEST_F(Illegal_TestCaseFixtureName, TestName) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: avoid using "_" in test case name "Illegal_TestCaseFixtureName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
+TEST_F(Illegal_TestCaseFixtureName, Illegal_TestName) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: avoid using "_" in test case name "Illegal_TestCaseFixtureName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
+// CHECK-MESSAGES: :[[@LINE-2]]:37: warning: avoid using "_" in test name "Illegal_TestName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
+
+TEST_F(Illegal_Test_CaseFixtureName, TestName) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: avoid using "_" in test case name "Illegal_Test_CaseFixtureName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
+
+TEST_P(ParameterizedTestCaseFixtureName, Illegal_TestName) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:42: warning: avoid using "_" in test name "Illegal_TestName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
+TEST_P(ParameterizedTestCaseFixtureName, DISABLED_Illegal_TestName) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:42: warning: avoid using "_" in test name "Illegal_TestName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
+TEST_P(ParameterizedTestCaseFixtureName, Illegal_Test_Name) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:42: warning: avoid using "_" in test name "Illegal_Test_Name" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
+
+TEST_P(Illegal_ParameterizedTestCaseFixtureName, TestName) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: avoid using "_" in test case name "Illegal_ParameterizedTestCaseFixtureName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
+TEST_P(Illegal_ParameterizedTestCaseFixtureName, Illegal_TestName) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: avoid using "_" in test case name "Illegal_ParameterizedTestCaseFixtureName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
+// CHECK-MESSAGES: :[[@LINE-2]]:50: warning: avoid using "_" in test name "Illegal_TestName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
+
+TEST_P(Illegal_Parameterized_TestCaseFixtureName, TestName) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: avoid using "_" in test case name "Illegal_Parameterized_TestCaseFixtureName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
+
+TYPED_TEST(TypedTestCaseName, Illegal_TestName) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:31: warning: avoid using "_" in test name "Illegal_TestName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
+TYPED_TEST(TypedTestCaseName, DISABLED_Illegal_TestName) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:31: warning: avoid using "_" in test name "Illegal_TestName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
+TYPED_TEST(TypedTestCaseName, Illegal_Test_Name) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:31: warning: avoid using "_" in test name "Illegal_Test_Name" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
+
+TYPED_TEST(Illegal_TypedTestCaseName, TestName) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: avoid using "_" in test case name "Illegal_TypedTestCaseName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
+TYPED_TEST(Illegal_TypedTestCaseName, Illegal_TestName) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: avoid using "_" in test case name "Illegal_TypedTestCaseName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
+// CHECK-MESSAGES: :[[@LINE-2]]:39: warning: avoid using "_" in test name "Illegal_TestName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
+
+TYPED_TEST(Illegal_Typed_TestCaseName, TestName) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: avoid using "_" in test case name "Illegal_Typed_TestCaseName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
+
+TYPED_TEST_P(TypeParameterizedTestCaseName, Illegal_TestName) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:45: warning: avoid using "_" in test name "Illegal_TestName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
+TYPED_TEST_P(TypeParameterizedTestCaseName, DISABLED_Illegal_TestName) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:45: warning: avoid using "_" in test name "Illegal_TestName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
+TYPED_TEST_P(TypeParameterizedTestCaseName, Illegal_Test_Name) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:45: warning: avoid using "_" in test name "Illegal_Test_Name" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
+
+TYPED_TEST_P(Illegal_TypeParameterizedTestCaseName, TestName) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: avoid using "_" in test case name "Illegal_TypeParameterizedTestCaseName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
+TYPED_TEST_P(Illegal_TypeParameterizedTestCaseName, Illegal_TestName) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: avoid using "_" in test case name "Illegal_TypeParameterizedTestCaseName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
+// CHECK-MESSAGES: :[[@LINE-2]]:53: warning: avoid using "_" in test name "Illegal_TestName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
+
+TYPED_TEST_P(Illegal_Type_ParameterizedTestCaseName, TestName) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: avoid using "_" in test case name "Illegal_Type_ParameterizedTestCaseName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
+
+// Underscores are allowed to disable a test with the DISABLED_ prefix.
+// https://github.com/google/googletest/blob/master/googletest/docs/faq.md#why-should-test-suite-names-and-test-names-not-contain-underscore
+TEST(TestCaseName, TestName) {}
+TEST(TestCaseName, DISABLED_TestName) {}
+
+TEST_F(TestCaseFixtureName, TestName) {}
+TEST_F(TestCaseFixtureName, DISABLED_TestName) {}
+
+TEST_P(ParameterizedTestCaseFixtureName, TestName) {}
+TEST_P(ParameterizedTestCaseFixtureName, DISABLED_TestName) {}
+
+TYPED_TEST(TypedTestName, TestName) {}
+TYPED_TEST(TypedTestName, DISABLED_TestName) {}
+
+TYPED_TEST_P(TypeParameterizedTestName, TestName) {}
+TYPED_TEST_P(TypeParameterizedTestName, DISABLED_TestName) {}
+
+FRIEND_TEST(FriendTest, Is_NotChecked) {}
+FRIEND_TEST(Friend_Test, IsNotChecked) {}
+FRIEND_TEST(Friend_Test, Is_NotChecked) {}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-braces-around-statements-assert-failure.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-braces-around-statements-assert-failure.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-braces-around-statements-assert-failure.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-braces-around-statements-assert-failure.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,12 @@
+// RUN: not clang-tidy -checks='-*,readability-braces-around-statements' %s --
+
+// Note: this test expects no assert failure happened in clang-tidy.
+
+int test_failure() {
+ if (std::rand()) {
+ }
+}
+
+void test_failure2() {
+ for (a b c;;
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-braces-around-statements-few-lines.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-braces-around-statements-few-lines.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-braces-around-statements-few-lines.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-braces-around-statements-few-lines.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,30 @@
+// RUN: %check_clang_tidy %s readability-braces-around-statements %t -- -config="{CheckOptions: [{key: readability-braces-around-statements.ShortStatementLines, value: 4}]}" --
+
+void do_something(const char *) {}
+
+bool cond(const char *) {
+ return false;
+}
+
+void test() {
+ if (cond("if1") /*comment*/) do_something("same-line");
+
+ if (cond("if2"))
+ do_something("single-line");
+
+ if (cond("if3") /*comment*/)
+ // some comment
+ do_something("three"
+ "lines");
+
+ if (cond("if4") /*comment*/)
+ // some comment
+ do_something("many"
+ "many"
+ "many"
+ "many"
+ "lines");
+ // CHECK-MESSAGES: :[[@LINE-7]]:31: warning: statement should be inside braces
+ // CHECK-FIXES: if (cond("if4") /*comment*/) {
+ // CHECK-FIXES: }
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-braces-around-statements-format.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-braces-around-statements-format.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-braces-around-statements-format.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-braces-around-statements-format.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,33 @@
+// RUN: %check_clang_tidy %s readability-braces-around-statements %t -- -format-style="{IndentWidth: 3}" --
+
+void do_something(const char *) {}
+
+bool cond(const char *) {
+ return false;
+}
+
+void test() {
+ if (cond("if0") /*comment*/) do_something("same-line");
+ // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: statement should be inside braces
+ // CHECK-FIXES: {{^}} if (cond("if0") /*comment*/) {{{$}}
+ // CHECK-FIXES-NEXT: {{^}} do_something("same-line");{{$}}
+ // CHECK-FIXES-NEXT: {{^}} }{{$}}
+
+ if (1) while (2) if (3) for (;;) do ; while(false) /**/;/**/
+ // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: statement should be inside braces
+ // CHECK-MESSAGES: :[[@LINE-2]]:19: warning: statement should be inside braces
+ // CHECK-MESSAGES: :[[@LINE-3]]:26: warning: statement should be inside braces
+ // CHECK-MESSAGES: :[[@LINE-4]]:35: warning: statement should be inside braces
+ // CHECK-MESSAGES: :[[@LINE-5]]:38: warning: statement should be inside braces
+ // CHECK-FIXES: {{^}} if (1) {{{$}}
+ // CHECK-FIXES-NEXT: {{^}} while (2) {
+ // CHECK-FIXES-NEXT: {{^}} if (3) {
+ // CHECK-FIXES-NEXT: {{^}} for (;;) {
+ // CHECK-FIXES-NEXT: {{^}} do {
+ // CHECK-FIXES-NEXT: {{^}} ;
+ // CHECK-FIXES-NEXT: {{^}} } while (false) /**/; /**/
+ // CHECK-FIXES-NEXT: {{^}} }
+ // CHECK-FIXES-NEXT: {{^}} }
+ // CHECK-FIXES-NEXT: {{^}} }
+ // CHECK-FIXES-NEXT: {{^}} }
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-braces-around-statements-same-line.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-braces-around-statements-same-line.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-braces-around-statements-same-line.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-braces-around-statements-same-line.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,36 @@
+// RUN: %check_clang_tidy %s readability-braces-around-statements %t -- -config="{CheckOptions: [{key: readability-braces-around-statements.ShortStatementLines, value: 1}]}" --
+
+void do_something(const char *) {}
+
+bool cond(const char *) {
+ return false;
+}
+
+void test() {
+ if (cond("if1") /*comment*/) do_something("same-line");
+
+ if (cond("if2"))
+ do_something("single-line");
+ // CHECK-MESSAGES: :[[@LINE-2]]:19: warning: statement should be inside braces
+ // CHECK-FIXES: if (cond("if2")) {
+ // CHECK-FIXES: }
+
+ if (cond("if3") /*comment*/)
+ // some comment
+ do_something("three"
+ "lines");
+ // CHECK-MESSAGES: :[[@LINE-4]]:31: warning: statement should be inside braces
+ // CHECK-FIXES: if (cond("if3") /*comment*/) {
+ // CHECK-FIXES: }
+
+ if (cond("if4") /*comment*/)
+ // some comment
+ do_something("many"
+ "many"
+ "many"
+ "many"
+ "lines");
+ // CHECK-MESSAGES: :[[@LINE-7]]:31: warning: statement should be inside braces
+ // CHECK-FIXES: if (cond("if4") /*comment*/) {
+ // CHECK-FIXES: }
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-braces-around-statements-single-line.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-braces-around-statements-single-line.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-braces-around-statements-single-line.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-braces-around-statements-single-line.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,33 @@
+// RUN: %check_clang_tidy %s readability-braces-around-statements %t -- -config="{CheckOptions: [{key: readability-braces-around-statements.ShortStatementLines, value: 2}]}" --
+
+void do_something(const char *) {}
+
+bool cond(const char *) {
+ return false;
+}
+
+void test() {
+ if (cond("if1") /*comment*/) do_something("same-line");
+
+ if (cond("if2"))
+ do_something("single-line");
+
+ if (cond("if3") /*comment*/)
+ // some comment
+ do_something("three"
+ "lines");
+ // CHECK-MESSAGES: :[[@LINE-4]]:31: warning: statement should be inside braces
+ // CHECK-FIXES: if (cond("if3") /*comment*/) {
+ // CHECK-FIXES: }
+
+ if (cond("if4") /*comment*/)
+ // some comment
+ do_something("many"
+ "many"
+ "many"
+ "many"
+ "lines");
+ // CHECK-MESSAGES: :[[@LINE-7]]:31: warning: statement should be inside braces
+ // CHECK-FIXES: if (cond("if4") /*comment*/) {
+ // CHECK-FIXES: }
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-braces-around-statements.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-braces-around-statements.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-braces-around-statements.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-braces-around-statements.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,206 @@
+// RUN: %check_clang_tidy %s readability-braces-around-statements %t
+
+void do_something(const char *) {}
+
+bool cond(const char *) {
+ return false;
+}
+
+#define EMPTY_MACRO
+#define EMPTY_MACRO_FUN()
+
+void test() {
+ if (cond("if0") /*comment*/) do_something("same-line");
+ // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: statement should be inside braces
+ // CHECK-FIXES: if (cond("if0") /*comment*/) { do_something("same-line");
+ // CHECK-FIXES: }
+
+ if (cond("if0.1"))
+ do_something("single-line");
+ // CHECK-MESSAGES: :[[@LINE-2]]:21: warning: statement should be inside braces
+ // CHECK-FIXES: if (cond("if0.1")) {
+ // CHECK-FIXES: }
+
+ if (cond("if1") /*comment*/)
+ // some comment
+ do_something("if1");
+ // CHECK-MESSAGES: :[[@LINE-3]]:31: warning: statement should be inside braces
+ // CHECK-FIXES: if (cond("if1") /*comment*/) {
+ // CHECK-FIXES: }
+ if (cond("if2")) {
+ do_something("if2");
+ }
+ if (cond("if3"))
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:19: warning: statement should be inside braces
+ // CHECK-FIXES: if (cond("if3")) {
+ // CHECK-FIXES: }
+
+ if (cond("if-else1"))
+ do_something("if-else1");
+ // CHECK-MESSAGES: :[[@LINE-2]]:24: warning: statement should be inside braces
+ // CHECK-FIXES: if (cond("if-else1")) {
+ // CHECK-FIXES: } else {
+ else
+ do_something("if-else1 else");
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: statement should be inside braces
+ // CHECK-FIXES: }
+ if (cond("if-else2")) {
+ do_something("if-else2");
+ } else {
+ do_something("if-else2 else");
+ }
+
+ if (cond("if-else if-else1"))
+ do_something("if");
+ // CHECK-MESSAGES: :[[@LINE-2]]:32: warning: statement should be inside braces
+ // CHECK-FIXES: } else if (cond("else if1")) {
+ else if (cond("else if1"))
+ do_something("else if");
+ // CHECK-MESSAGES: :[[@LINE-2]]:29: warning: statement should be inside braces
+ else
+ do_something("else");
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: statement should be inside braces
+ // CHECK-FIXES: }
+ if (cond("if-else if-else2")) {
+ do_something("if");
+ } else if (cond("else if2")) {
+ do_something("else if");
+ } else {
+ do_something("else");
+ }
+
+ for (;;)
+ do_something("for");
+ // CHECK-MESSAGES: :[[@LINE-2]]:11: warning: statement should be inside braces
+ // CHECK-FIXES: for (;;) {
+ // CHECK-FIXES: }
+ for (;;) {
+ do_something("for");
+ }
+ for (;;)
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:11: warning: statement should be inside braces
+ // CHECK-FIXES: for (;;) {
+ // CHECK-FIXES: }
+
+ int arr[4] = {1, 2, 3, 4};
+ for (int a : arr)
+ do_something("for-range");
+ // CHECK-MESSAGES: :[[@LINE-2]]:20: warning: statement should be inside braces
+ // CHECK-FIXES: for (int a : arr) {
+ // CHECK-FIXES: }
+ for (int a : arr) {
+ do_something("for-range");
+ }
+ for (int a : arr)
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:20: warning: statement should be inside braces
+ // CHECK-FIXES: for (int a : arr) {
+ // CHECK-FIXES: }
+
+ while (cond("while1"))
+ do_something("while");
+ // CHECK-MESSAGES: :[[@LINE-2]]:25: warning: statement should be inside braces
+ // CHECK-FIXES: while (cond("while1")) {
+ // CHECK-FIXES: }
+ while (cond("while2")) {
+ do_something("while");
+ }
+ while (false)
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:16: warning: statement should be inside braces
+ // CHECK-FIXES: while (false) {
+ // CHECK-FIXES: }
+
+ do
+ do_something("do1");
+ while (cond("do1"));
+ // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: statement should be inside braces
+ // CHECK-FIXES: do {
+ // CHECK-FIXES: } while (cond("do1"));
+ do {
+ do_something("do2");
+ } while (cond("do2"));
+
+ do
+ ;
+ while (false);
+ // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: statement should be inside braces
+ // CHECK-FIXES: do {
+ // CHECK-FIXES: } while (false);
+
+ if (cond("ifif1"))
+ // comment
+ if (cond("ifif2"))
+ // comment
+ /*comment*/ ; // comment
+ // CHECK-MESSAGES: :[[@LINE-5]]:21: warning: statement should be inside braces
+ // CHECK-MESSAGES: :[[@LINE-4]]:23: warning: statement should be inside braces
+ // CHECK-FIXES: if (cond("ifif1")) {
+ // CHECK-FIXES: if (cond("ifif2")) {
+ // CHECK-FIXES: }
+ // CHECK-FIXES-NEXT: }
+
+ if (cond("ifif3"))
+ // comment
+ if (cond("ifif4")) {
+ // comment
+ /*comment*/; // comment
+ }
+ // CHECK-MESSAGES: :[[@LINE-6]]:21: warning: statement should be inside braces
+ // CHECK-FIXES: if (cond("ifif3")) {
+ // CHECK-FIXES: }
+
+ if (cond("ifif5"))
+ ; /* multi-line
+ comment */
+ // CHECK-MESSAGES: :[[@LINE-3]]:21: warning: statement should be inside braces
+ // CHECK-FIXES: if (cond("ifif5")) {
+ // CHECK-FIXES: }/* multi-line
+
+ if (1) while (2) if (3) for (;;) do ; while(false) /**/;/**/
+ // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: statement should be inside braces
+ // CHECK-MESSAGES: :[[@LINE-2]]:19: warning: statement should be inside braces
+ // CHECK-MESSAGES: :[[@LINE-3]]:26: warning: statement should be inside braces
+ // CHECK-MESSAGES: :[[@LINE-4]]:35: warning: statement should be inside braces
+ // CHECK-MESSAGES: :[[@LINE-5]]:38: warning: statement should be inside braces
+ // CHECK-FIXES: if (1) { while (2) { if (3) { for (;;) { do { ; } while(false) /**/;/**/
+ // CHECK-FIXES-NEXT: }
+ // CHECK-FIXES-NEXT: }
+ // CHECK-FIXES-NEXT: }
+ // CHECK-FIXES-NEXT: }
+}
+
+void f(const char *p) {
+ if (!p)
+ f("\
+");
+} // end of f
+// CHECK-MESSAGES: :[[@LINE-4]]:10: warning: statement should be inside braces
+// CHECK-FIXES: {{^}} if (!p) {{{$}}
+// CHECK-FIXES-NEXT: {{^}} f("\{{$}}
+// CHECK-FIXES-NEXT: {{^}}");{{$}}
+// CHECK-FIXES-NEXT: {{^}}}{{$}}
+// CHECK-FIXES-NEXT: {{^}}} // end of f{{$}}
+
+#define M(x) x
+
+int test_macros(bool b) {
+ if (b) {
+ return 1;
+ } else
+ M(return 2);
+ // CHECK-MESSAGES: :[[@LINE-2]]:9: warning: statement should be inside braces
+ // CHECK-FIXES: } else {
+ // CHECK-FIXES-NEXT: M(return 2);
+ // CHECK-FIXES-NEXT: }
+ M(
+ for (;;)
+ ;
+ );
+ // CHECK-MESSAGES: :[[@LINE-3]]:13: warning: statement should be inside braces
+ // CHECK-FIXES: {{^}} for (;;) {{{$}}
+ // CHECK-FIXES-NEXT: {{^ ;$}}
+ // CHECK-FIXES-NEXT: {{^}$}}
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-const-return-type.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-const-return-type.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-const-return-type.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-const-return-type.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,234 @@
+// RUN: %check_clang_tidy %s readability-const-return-type %t
+
+// p# = positive test
+// n# = negative test
+
+namespace std {
+template< class T >
+struct add_cv { typedef const volatile T type; };
+
+template< class T> struct add_const { typedef const T type; };
+
+template< class T> struct add_volatile { typedef volatile T type; };
+}
+
+const int p1() {
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const int' is 'const'-qualified at the top level, which may reduce code readability without improving const correctness
+// CHECK-FIXES: int p1() {
+ return 1;
+}
+
+const int p15();
+// CHECK-FIXES: int p15();
+
+template <typename T>
+const int p31(T v) { return 2; }
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const int' is 'const'-qu
+// CHECK-FIXES: int p31(T v) { return 2; }
+
+// We detect const-ness even without instantiating T.
+template <typename T>
+const T p32(T t) { return t; }
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const T' is 'const'-qual
+// CHECK-FIXES: T p32(T t) { return t; }
+
+// However, if the return type is itself a template instantiation, Clang does
+// not consider it const-qualified without knowing `T`.
+template <typename T>
+typename std::add_const<T>::type n15(T v) { return v; }
+
+template <typename A>
+class Klazz {
+public:
+ Klazz(A) {}
+};
+
+class Clazz {
+ public:
+ Clazz *const p2() {
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: return type 'Clazz *const' is 'co
+ // CHECK-FIXES: Clazz *p2() {
+ return this;
+ }
+
+ Clazz *const p3();
+ // CHECK-FIXES: Clazz *p3();
+
+ const int p4() const {
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: return type 'const int' is 'const
+ // CHECK-FIXES: int p4() const {
+ return 4;
+ }
+
+ const Klazz<const int>* const p5() const;
+ // CHECK-FIXES: const Klazz<const int>* p5() const;
+
+ const Clazz operator++(int x) { // p12
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: return type 'const Clazz' is 'const
+ // CHECK-FIXES: Clazz operator++(int x) {
+ }
+
+ struct Strukt {
+ int i;
+ };
+
+ const Strukt p6() {}
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: return type 'const Clazz::Strukt' i
+ // CHECK-FIXES: Strukt p6() {}
+
+ // No warning is emitted here, because this is only the declaration. The
+ // warning will be associated with the definition, below.
+ const Strukt* const p7();
+ // CHECK-FIXES: const Strukt* p7();
+
+ // const-qualifier is the first `const` token, but not the first token.
+ static const int p8() {}
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: return type 'const int' is 'const'-
+ // CHECK-FIXES: static int p8() {}
+
+ static const Strukt p9() {}
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: return type 'const Clazz::Strukt' i
+ // CHECK-FIXES: static Strukt p9() {}
+
+ int n0() const { return 0; }
+ const Klazz<const int>& n11(const Klazz<const int>) const;
+};
+
+Clazz *const Clazz::p3() {
+ // CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'Clazz *const' is 'cons
+ // CHECK-FIXES: Clazz *Clazz::p3() {
+ return this;
+}
+
+const Klazz<const int>* const Clazz::p5() const {}
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz<const int> *
+// CHECK-FIXES: const Klazz<const int>* Clazz::p5() const {}
+
+const Clazz::Strukt* const Clazz::p7() {}
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Clazz::Strukt *con
+// CHECK-FIXES: const Clazz::Strukt* Clazz::p7() {}
+
+Clazz *const p10();
+// CHECK-FIXES: Clazz *p10();
+
+Clazz *const p10() {
+ // CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'Clazz *const' is 'cons
+ // CHECK-FIXES: Clazz *p10() {
+ return new Clazz();
+}
+
+const Clazz bar;
+const Clazz *const p11() {
+ // CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Clazz *const' is
+ // CHECK-FIXES: const Clazz *p11() {
+ return &bar;
+}
+
+const Klazz<const int> p12() {}
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz<const int>'
+// CHECK-FIXES: Klazz<const int> p12() {}
+
+const Klazz<const int>* const p13() {}
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz<const int> *
+// CHECK-FIXES: const Klazz<const int>* p13() {}
+
+// re-declaration of p15.
+const int p15();
+// CHECK-FIXES: int p15();
+
+const int p15() {
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning:
+// CHECK-FIXES: int p15() {
+ return 0;
+}
+
+// Exercise the lexer.
+
+const /* comment */ /* another comment*/ int p16() { return 0; }
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning:
+// CHECK-FIXES: /* comment */ /* another comment*/ int p16() { return 0; }
+
+/* comment */ const
+// CHECK-MESSAGES: [[@LINE-1]]:15: warning:
+// CHECK-FIXES: /* comment */
+// more
+/* another comment*/ int p17() { return 0; }
+
+// Test cases where the `const` token lexically is hidden behind some form of
+// indirection.
+
+#define CONSTINT const int
+CONSTINT p18() {}
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const int' is 'const'-qu
+
+#define CONST const
+CONST int p19() {}
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const int' is 'const'-qu
+
+using ty = const int;
+ty p21() {}
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'ty' (aka 'const int') is
+
+typedef const int ty2;
+ty2 p22() {}
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'ty2' (aka 'const int') i
+
+// Declaration uses a macro, while definition doesn't. In this case, we won't
+// fix the declaration, and will instead issue a warning.
+CONST int p23();
+// CHECK-NOTE: [[@LINE-1]]:1: note: could not transform this declaration
+
+const int p23();
+// CHECK-FIXES: int p23();
+
+const int p23() { return 3; }
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const int' is 'const'-qu
+// CHECK-FIXES: int p23() { return 3; }
+
+int const p24() { return 3; }
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const int' is 'const'-qu
+// CHECK-FIXES: int p24() { return 3; }
+
+int const * const p25(const int* p) { return p; }
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const int *const' is 'co
+// CHECK-FIXES: int const * p25(const int* p) { return p; }
+
+// We cannot (yet) fix instances that use trailing return types, but we can
+// warn.
+auto p26() -> const int { return 3; }
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const int' is 'const'-qu
+auto p27() -> int const { return 3; }
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const int' is 'const'-qu
+
+std::add_const<int>::type p28() { return 3; }
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'std::add_const<int>::typ
+
+// p29, p30 are based on
+// llvm/projects/test-suite/SingleSource/Benchmarks/Misc-C++-EH/spirit.cpp:
+template <class T>
+Klazz<T const> const p29(T const &t) { return {}; }
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz<const T>' is
+// CHECK-FIXES: Klazz<T const> p29(T const &t) { return {}; }
+
+Klazz<char const *> const p30(char const *s) { return s; }
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz<const char *
+// CHECK-FIXES: Klazz<char const *> p30(char const *s) { return s; }
+
+const int n1 = 1;
+const Clazz n2 = Clazz();
+const Clazz* n3 = new Clazz();
+Clazz *const n4 = new Clazz();
+const Clazz *const n5 = new Clazz();
+constexpr int n6 = 6;
+constexpr int n7() { return 8; }
+const int eight = 8;
+constexpr const int* n8() { return &eight; }
+Klazz<const int> n9();
+const Klazz<const int>* n10();
+const Klazz<const int>& Clazz::n11(const Klazz<const int>) const {}
+
+// Declaration only.
+const int n14();
+
+int **const * n_multiple_ptr();
+int *const & n_pointer_ref();
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-container-size-empty.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-container-size-empty.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-container-size-empty.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-container-size-empty.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,444 @@
+// RUN: %check_clang_tidy %s readability-container-size-empty %t
+
+namespace std {
+template <typename T> struct vector {
+ vector();
+ bool operator==(const vector<T>& other) const;
+ bool operator!=(const vector<T>& other) const;
+ unsigned long size() const;
+ bool empty() const;
+};
+
+template <typename T> struct basic_string {
+ basic_string();
+ bool operator==(const basic_string<T>& other) const;
+ bool operator!=(const basic_string<T>& other) const;
+ bool operator==(const char *) const;
+ bool operator!=(const char *) const;
+ basic_string<T> operator+(const basic_string<T>& other) const;
+ unsigned long size() const;
+ bool empty() const;
+};
+
+typedef basic_string<char> string;
+typedef basic_string<wchar_t> wstring;
+
+inline namespace __v2 {
+template <typename T> struct set {
+ set();
+ bool operator==(const set<T>& other) const;
+ bool operator!=(const set<T>& other) const;
+ unsigned long size() const;
+ bool empty() const;
+};
+}
+
+}
+
+template <typename T>
+class TemplatedContainer {
+public:
+ bool operator==(const TemplatedContainer<T>& other) const;
+ bool operator!=(const TemplatedContainer<T>& other) const;
+ int size() const;
+ bool empty() const;
+};
+
+template <typename T>
+class PrivateEmpty {
+public:
+ bool operator==(const PrivateEmpty<T>& other) const;
+ bool operator!=(const PrivateEmpty<T>& other) const;
+ int size() const;
+private:
+ bool empty() const;
+};
+
+struct BoolSize {
+ bool size() const;
+ bool empty() const;
+};
+
+struct EnumSize {
+ enum E { one };
+ enum E size() const;
+ bool empty() const;
+};
+
+class Container {
+public:
+ bool operator==(const Container& other) const;
+ int size() const;
+ bool empty() const;
+};
+
+class Derived : public Container {
+};
+
+class Container2 {
+public:
+ int size() const;
+ bool empty() const { return size() == 0; }
+};
+
+class Container3 {
+public:
+ int size() const;
+ bool empty() const;
+};
+
+bool Container3::empty() const { return this->size() == 0; }
+
+class Container4 {
+public:
+ bool operator==(const Container4& rhs) const;
+ int size() const;
+ bool empty() const { return *this == Container4(); }
+};
+
+std::string s_func() {
+ return std::string();
+}
+
+int main() {
+ std::set<int> intSet;
+ std::string str;
+ std::string str2;
+ std::wstring wstr;
+ (void)(str.size() + 0);
+ (void)(str.size() - 0);
+ (void)(0 + str.size());
+ (void)(0 - str.size());
+ if (intSet.size() == 0)
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness instead of 'size' [readability-container-size-empty]
+ // CHECK-FIXES: {{^ }}if (intSet.empty()){{$}}
+ // CHECK-MESSAGES: :32:8: note: method 'set'::empty() defined here
+ if (intSet == std::set<int>())
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness
+ // CHECK-FIXES: {{^ }}if (intSet.empty()){{$}}
+ // CHECK-MESSAGES: :32:8: note: method 'set'::empty() defined here
+ if (s_func() == "")
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (s_func().empty()){{$}}
+ if (str.size() == 0)
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (str.empty()){{$}}
+ if ((str + str2).size() == 0)
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if ((str + str2).empty()){{$}}
+ if (str == "")
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (str.empty()){{$}}
+ if (str + str2 == "")
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if ((str + str2).empty()){{$}}
+ if (wstr.size() == 0)
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (wstr.empty()){{$}}
+ if (wstr == "")
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (wstr.empty()){{$}}
+ std::vector<int> vect;
+ if (vect.size() == 0)
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (vect.empty()){{$}}
+ if (vect == std::vector<int>())
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (vect.empty()){{$}}
+ if (vect.size() != 0)
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (!vect.empty()){{$}}
+ if (vect != std::vector<int>())
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (!vect.empty()){{$}}
+ if (0 == vect.size())
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:12: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (vect.empty()){{$}}
+ if (0 != vect.size())
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:12: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (!vect.empty()){{$}}
+ if (std::vector<int>() == vect)
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (vect.empty()){{$}}
+ if (std::vector<int>() != vect)
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (!vect.empty()){{$}}
+ if (vect.size() > 0)
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (!vect.empty()){{$}}
+ if (0 < vect.size())
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:11: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (!vect.empty()){{$}}
+ if (vect.size() < 1)
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (vect.empty()){{$}}
+ if (1 > vect.size())
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:11: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (vect.empty()){{$}}
+ if (vect.size() >= 1)
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (!vect.empty()){{$}}
+ if (1 <= vect.size())
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:12: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (!vect.empty()){{$}}
+ if (vect.size() > 1) // no warning
+ ;
+ if (1 < vect.size()) // no warning
+ ;
+ if (vect.size() <= 1) // no warning
+ ;
+ if (1 >= vect.size()) // no warning
+ ;
+ if (!vect.size())
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:8: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (vect.empty()){{$}}
+ if (vect.size())
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (!vect.empty()){{$}}
+
+ if (vect.empty())
+ ;
+
+ const std::vector<int> vect2;
+ if (vect2.size() != 0)
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (!vect2.empty()){{$}}
+
+ std::vector<int> *vect3 = new std::vector<int>();
+ if (vect3->size() == 0)
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (vect3->empty()){{$}}
+ if ((*vect3).size() == 0)
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if ((*vect3).empty()){{$}}
+ if ((*vect3) == std::vector<int>())
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (vect3->empty()){{$}}
+ if (*vect3 == std::vector<int>())
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (vect3->empty()){{$}}
+
+ delete vect3;
+
+ const std::vector<int> &vect4 = vect2;
+ if (vect4.size() == 0)
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (vect4.empty()){{$}}
+ if (vect4 == std::vector<int>())
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (vect4.empty()){{$}}
+
+ TemplatedContainer<void> templated_container;
+ if (templated_container.size() == 0)
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (templated_container.empty()){{$}}
+ if (templated_container == TemplatedContainer<void>())
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (templated_container.empty()){{$}}
+ if (templated_container.size() != 0)
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (!templated_container.empty()){{$}}
+ if (templated_container != TemplatedContainer<void>())
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (!templated_container.empty()){{$}}
+ if (0 == templated_container.size())
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:12: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (templated_container.empty()){{$}}
+ if (TemplatedContainer<void>() == templated_container)
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (templated_container.empty()){{$}}
+ if (0 != templated_container.size())
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:12: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (!templated_container.empty()){{$}}
+ if (TemplatedContainer<void>() != templated_container)
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (!templated_container.empty()){{$}}
+ if (templated_container.size() > 0)
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (!templated_container.empty()){{$}}
+ if (0 < templated_container.size())
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:11: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (!templated_container.empty()){{$}}
+ if (templated_container.size() < 1)
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (templated_container.empty()){{$}}
+ if (1 > templated_container.size())
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:11: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (templated_container.empty()){{$}}
+ if (templated_container.size() >= 1)
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (!templated_container.empty()){{$}}
+ if (1 <= templated_container.size())
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:12: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (!templated_container.empty()){{$}}
+ if (templated_container.size() > 1) // no warning
+ ;
+ if (1 < templated_container.size()) // no warning
+ ;
+ if (templated_container.size() <= 1) // no warning
+ ;
+ if (1 >= templated_container.size()) // no warning
+ ;
+ if (!templated_container.size())
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:8: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (templated_container.empty()){{$}}
+ if (templated_container.size())
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (!templated_container.empty()){{$}}
+
+ if (templated_container.empty())
+ ;
+
+ // No warnings expected.
+ PrivateEmpty<void> private_empty;
+ if (private_empty.size() == 0)
+ ;
+ if (private_empty == PrivateEmpty<void>())
+ ;
+ if (private_empty.size() != 0)
+ ;
+ if (private_empty != PrivateEmpty<void>())
+ ;
+ if (0 == private_empty.size())
+ ;
+ if (PrivateEmpty<void>() == private_empty)
+ ;
+ if (0 != private_empty.size())
+ ;
+ if (PrivateEmpty<void>() != private_empty)
+ ;
+ if (private_empty.size() > 0)
+ ;
+ if (0 < private_empty.size())
+ ;
+ if (private_empty.size() < 1)
+ ;
+ if (1 > private_empty.size())
+ ;
+ if (private_empty.size() >= 1)
+ ;
+ if (1 <= private_empty.size())
+ ;
+ if (private_empty.size() > 1)
+ ;
+ if (1 < private_empty.size())
+ ;
+ if (private_empty.size() <= 1)
+ ;
+ if (1 >= private_empty.size())
+ ;
+ if (!private_empty.size())
+ ;
+ if (private_empty.size())
+ ;
+
+ // Types with weird size() return type.
+ BoolSize bs;
+ if (bs.size() == 0)
+ ;
+ EnumSize es;
+ if (es.size() == 0)
+ ;
+
+ Derived derived;
+ if (derived.size() == 0)
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (derived.empty()){{$}}
+ if (derived == Derived())
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}if (derived.empty()){{$}}
+}
+
+#define CHECKSIZE(x) if (x.size()) {}
+// CHECK-FIXES: #define CHECKSIZE(x) if (x.size()) {}
+
+template <typename T> void f() {
+ std::vector<T> v;
+ if (v.size())
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness instead of 'size' [readability-container-size-empty]
+ // CHECK-MESSAGES: :9:8: note: method 'vector'::empty() defined here
+ // CHECK-FIXES: {{^ }}if (!v.empty()){{$}}
+ if (v == std::vector<T>())
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness instead of comparing to an empty object [readability-container-size-empty]
+ // CHECK-FIXES: {{^ }}if (v.empty()){{$}}
+ // CHECK-FIXES-NEXT: ;
+ CHECKSIZE(v);
+ // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: the 'empty' method should be used
+ // CHECK-MESSAGES: :9:8: note: method 'vector'::empty() defined here
+ // CHECK-FIXES: CHECKSIZE(v);
+
+ TemplatedContainer<T> templated_container;
+ if (templated_container.size())
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+ // CHECK-MESSAGES: :44:8: note: method 'TemplatedContainer'::empty() defined here
+ // CHECK-FIXES: {{^ }}if (!templated_container.empty()){{$}}
+ if (templated_container != TemplatedContainer<T>())
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+ // CHECK-MESSAGES: :44:8: note: method 'TemplatedContainer'::empty() defined here
+ // CHECK-FIXES: {{^ }}if (!templated_container.empty()){{$}}
+ // CHECK-FIXES-NEXT: ;
+ CHECKSIZE(templated_container);
+ // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: the 'empty' method should be used
+ // CHECK-MESSAGES: :44:8: note: method 'TemplatedContainer'::empty() defined here
+ // CHECK-FIXES: CHECKSIZE(templated_container);
+}
+
+void g() {
+ f<int>();
+ f<double>();
+ f<char *>();
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-convert-member-functions-to-static.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-convert-member-functions-to-static.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-convert-member-functions-to-static.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-convert-member-functions-to-static.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,218 @@
+// RUN: %check_clang_tidy %s readability-convert-member-functions-to-static %t
+
+class DoNotMakeEmptyStatic {
+ void emptyMethod() {}
+ void empty_method_out_of_line();
+};
+
+void DoNotMakeEmptyStatic::empty_method_out_of_line() {}
+
+class A {
+ int field;
+ const int const_field;
+ static int static_field;
+
+ void no_use() {
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: method 'no_use' can be made static
+ // CHECK-FIXES: {{^}} static void no_use() {
+ int i = 1;
+ }
+
+ int read_field() {
+ return field;
+ }
+
+ void write_field() {
+ field = 1;
+ }
+
+ int call_non_const_member() { return read_field(); }
+
+ int call_static_member() {
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: method 'call_static_member' can be made static
+ // CHECK-FIXES: {{^}} static int call_static_member() {
+ already_static();
+ }
+
+ int read_static() {
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: method 'read_static' can be made static
+ // CHECK-FIXES: {{^}} static int read_static() {
+ return static_field;
+ }
+ void write_static() {
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: method 'write_static' can be made static
+ // CHECK-FIXES: {{^}} static void write_static() {
+ static_field = 1;
+ }
+
+ static int already_static() { return static_field; }
+
+ int already_const() const { return field; }
+
+ int already_const_convert_to_static() const {
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: method 'already_const_convert_to_static' can be made static
+ // CHECK-FIXES: {{^}} static int already_const_convert_to_static() {
+ return static_field;
+ }
+
+ static int out_of_line_already_static();
+
+ void out_of_line_call_static();
+ // CHECK-FIXES: {{^}} static void out_of_line_call_static();
+ int out_of_line_const_to_static() const;
+ // CHECK-FIXES: {{^}} static int out_of_line_const_to_static() ;
+};
+
+int A::out_of_line_already_static() { return 0; }
+
+void A::out_of_line_call_static() {
+ // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: method 'out_of_line_call_static' can be made static
+ // CHECK-FIXES: {{^}}void A::out_of_line_call_static() {
+ already_static();
+}
+
+int A::out_of_line_const_to_static() const {
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: method 'out_of_line_const_to_static' can be made static
+ // CHECK-FIXES: {{^}}int A::out_of_line_const_to_static() {
+ return 0;
+}
+
+struct KeepVirtual {
+ virtual int f() { return 0; }
+ virtual int h() const { return 0; }
+};
+
+struct KeepVirtualDerived : public KeepVirtual {
+ int f() { return 0; }
+ int h() const override { return 0; }
+};
+
+// Don't add 'static' to special member functions and operators.
+struct KeepSpecial {
+ KeepSpecial() { int L = 0; }
+ ~KeepSpecial() { int L = 0; }
+ int operator+() { return 0; }
+ operator int() { return 0; }
+};
+
+void KeepLambdas() {
+ using FT = int (*)();
+ auto F = static_cast<FT>([]() { return 0; });
+ auto F2 = []() { return 0; };
+}
+
+template <class Base>
+struct KeepWithTemplateBase : public Base {
+ int i;
+ // We cannot make these methods static because they might need to override
+ // a function from Base.
+ int static_f() { return 0; }
+};
+
+template <class T>
+struct KeepTemplateClass {
+ int i;
+ // We cannot make these methods static because a specialization
+ // might use *this differently.
+ int static_f() { return 0; }
+};
+
+struct KeepTemplateMethod {
+ int i;
+ // We cannot make these methods static because a specialization
+ // might use *this differently.
+ template <class T>
+ static int static_f() { return 0; }
+};
+
+void instantiate() {
+ struct S {};
+ KeepWithTemplateBase<S> I1;
+ I1.static_f();
+
+ KeepTemplateClass<int> I2;
+ I2.static_f();
+
+ KeepTemplateMethod I3;
+ I3.static_f<int>();
+}
+
+struct Trailing {
+ auto g() const -> int {
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: method 'g' can be made static
+ // CHECK-FIXES: {{^}} static auto g() -> int {
+ return 0;
+ }
+
+ void vol() volatile {
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: method 'vol' can be made static
+ return;
+ }
+
+ void ref() const & {
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: method 'ref' can be made static
+ return;
+ }
+ void refref() const && {
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: method 'refref' can be made static
+ return;
+ }
+
+ void restr() __restrict {
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: method 'restr' can be made static
+ return;
+ }
+};
+
+struct UnevaluatedContext {
+ void f() { sizeof(this); }
+
+ void noex() noexcept(noexcept(this));
+};
+
+struct LambdaCapturesThis {
+ int Field;
+
+ int explicitCapture() {
+ return [this]() { return Field; }();
+ }
+
+ int implicitCapture() {
+ return [&]() { return Field; }();
+ }
+};
+
+struct NoFixitInMacro {
+#define CONST const
+ int no_use_macro_const() CONST {
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: method 'no_use_macro_const' can be made static
+ return 0;
+ }
+
+#define ADD_CONST(F) F const
+ int ADD_CONST(no_use_macro2()) {
+ return 0;
+ }
+
+#define FUN no_use_macro()
+ int i;
+ int FUN {
+ return i;
+ }
+
+#define T(FunctionName, Keyword) \
+ Keyword int FunctionName() { return 0; }
+#define EMPTY
+ T(A, EMPTY)
+ T(B, static)
+
+#define T2(FunctionName) \
+ int FunctionName() { return 0; }
+ T2(A2)
+
+#define VOLATILE volatile
+ void volatileMacro() VOLATILE {
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: method 'volatileMacro' can be made static
+ return;
+ }
+};
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-delete-null-pointer.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-delete-null-pointer.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-delete-null-pointer.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-delete-null-pointer.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,95 @@
+// RUN: %check_clang_tidy %s readability-delete-null-pointer %t
+
+#define NULL 0
+
+void f() {
+ int *ps = 0;
+ if (ps /**/) // #0
+ delete ps;
+ // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: 'if' statement is unnecessary; deleting null pointer has no effect [readability-delete-null-pointer]
+
+ // CHECK-FIXES: int *ps = 0;
+ // CHECK-FIXES-NEXT: {{^ }}// #0
+ // CHECK-FIXES-NEXT: delete ps;
+
+ int *p = 0;
+
+ // #1
+ if (p) { // #2
+ delete p;
+ } // #3
+ // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: 'if' statement is unnecessary; deleting null pointer has no effect [readability-delete-null-pointer]
+
+ // CHECK-FIXES: {{^ }}// #1
+ // CHECK-FIXES-NEXT: {{^ }}// #2
+ // CHECK-FIXES-NEXT: delete p;
+ // CHECK-FIXES-NEXT: {{^ }}// #3
+
+ int *p2 = new int[3];
+ // #4
+ if (p2) // #5
+ delete[] p2;
+ // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: 'if' statement is unnecessary;
+
+ // CHECK-FIXES: // #4
+ // CHECK-FIXES-NEXT: {{^ }}// #5
+ // CHECK-FIXES-NEXT: delete[] p2;
+
+ int *p3 = 0;
+ if (NULL != p3) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'if' statement is unnecessary;
+ delete p3;
+ }
+ // CHECK-FIXES-NOT: if (NULL != p3) {
+ // CHECK-FIXES: delete p3;
+
+ int *p4 = nullptr;
+ if (p4 != nullptr) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'if' statement is unnecessary;
+ delete p4;
+ }
+ // CHECK-FIXES-NOT: if (p4 != nullptr) {
+ // CHECK-FIXES: delete p4;
+
+ char *c;
+ if (c != 0) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'if' statement is unnecessary;
+ delete c;
+ }
+ // CHECK-FIXES-NOT: if (c != 0) {
+ // CHECK-FIXES: delete c;
+
+ char *c2;
+ if (c2) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'if' statement is unnecessary;
+ // CHECK-FIXES: } else {
+ // CHECK-FIXES: c2 = c;
+ delete c2;
+ } else {
+ c2 = c;
+ }
+ struct A {
+ void foo() {
+ if (mp) // #6
+ delete mp;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: 'if' statement is unnecessary; deleting null pointer has no effect [readability-delete-null-pointer]
+ // CHECK-FIXES: {{^ }}// #6
+ // CHECK-FIXES-NEXT: delete mp;
+ }
+ int *mp;
+ };
+}
+
+void g() {
+ int *p5, *p6;
+ if (p5)
+ delete p6;
+
+ if (p5 && p6)
+ delete p5;
+
+ if (p6) {
+ int x = 5;
+ delete p6;
+ }
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-deleted-default.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-deleted-default.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-deleted-default.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-deleted-default.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,127 @@
+// RUN: %check_clang_tidy %s readability-deleted-default %t -- -- -fno-ms-compatibility
+
+class NoDefault {
+public:
+ NoDefault() = delete;
+ NoDefault(NoDefault &&Other) = delete;
+ NoDefault(const NoDefault &Other) = delete;
+};
+
+class MissingEverything {
+public:
+ MissingEverything() = default;
+ // CHECK-MESSAGES: warning: default constructor is explicitly defaulted but implicitly deleted, probably because a non-static data member or a base class is lacking a default constructor; definition can either be removed or explicitly deleted [readability-deleted-default]
+ MissingEverything(MissingEverything &&Other) = default;
+ // CHECK-MESSAGES: warning: move constructor is explicitly defaulted but implicitly deleted, probably because a non-static data member or a base class is neither copyable nor movable; definition can either be removed or explicitly deleted [readability-deleted-default]
+ MissingEverything(const MissingEverything &Other) = default;
+ // CHECK-MESSAGES: warning: copy constructor is explicitly defaulted but implicitly deleted, probably because a non-static data member or a base class is not copyable; definition can either be removed or explicitly deleted [readability-deleted-default]
+ MissingEverything &operator=(MissingEverything &&Other) = default;
+ // CHECK-MESSAGES: warning: move assignment operator is explicitly defaulted but implicitly deleted, probably because a base class or a non-static data member is not assignable, e.g. because the latter is marked 'const'; definition can either be removed or explicitly deleted [readability-deleted-default]
+ MissingEverything &operator=(const MissingEverything &Other) = default;
+ // CHECK-MESSAGES: warning: copy assignment operator is explicitly defaulted but implicitly deleted, probably because a base class or a non-static data member is not assignable, e.g. because the latter is marked 'const'; definition can either be removed or explicitly deleted [readability-deleted-default]
+
+private:
+ NoDefault ND;
+};
+
+class NotAssignable {
+public:
+ NotAssignable(NotAssignable &&Other) = default;
+ NotAssignable(const NotAssignable &Other) = default;
+ NotAssignable &operator=(NotAssignable &&Other) = default;
+ // CHECK-MESSAGES: warning: move assignment operator is explicitly defaulted but implicitly deleted
+ NotAssignable &operator=(const NotAssignable &Other) = default;
+ // CHECK-MESSAGES: warning: copy assignment operator is explicitly defaulted but implicitly deleted
+
+private:
+ const int I = 0;
+};
+
+class Movable {
+public:
+ Movable() = default;
+ Movable(Movable &&Other) = default;
+ Movable(const Movable &Other) = delete;
+ Movable &operator=(Movable &&Other) = default;
+ Movable &operator=(const Movable &Other) = delete;
+};
+
+class NotCopyable {
+public:
+ NotCopyable(NotCopyable &&Other) = default;
+ NotCopyable(const NotCopyable &Other) = default;
+ // CHECK-MESSAGES: warning: copy constructor is explicitly defaulted but implicitly deleted
+ NotCopyable &operator=(NotCopyable &&Other) = default;
+ NotCopyable &operator=(const NotCopyable &Other) = default;
+ // CHECK-MESSAGES: warning: copy assignment operator is explicitly defaulted but implicitly deleted
+private:
+ Movable M;
+};
+
+template <typename T> class Templated {
+public:
+ // No warning here, it is a templated class.
+ Templated() = default;
+ Templated(Templated &&Other) = default;
+ Templated(const Templated &Other) = default;
+ Templated &operator=(Templated &&Other) = default;
+ Templated &operator=(const Templated &Other) = default;
+
+ class InnerTemplated {
+ public:
+ // This class is not in itself templated, but we still don't have warning.
+ InnerTemplated() = default;
+ InnerTemplated(InnerTemplated &&Other) = default;
+ InnerTemplated(const InnerTemplated &Other) = default;
+ InnerTemplated &operator=(InnerTemplated &&Other) = default;
+ InnerTemplated &operator=(const InnerTemplated &Other) = default;
+
+ private:
+ T TVar;
+ };
+
+ class InnerNotTemplated {
+ public:
+ // This one could technically have warnings, but currently doesn't.
+ InnerNotTemplated() = default;
+ InnerNotTemplated(InnerNotTemplated &&Other) = default;
+ InnerNotTemplated(const InnerNotTemplated &Other) = default;
+ InnerNotTemplated &operator=(InnerNotTemplated &&Other) = default;
+ InnerNotTemplated &operator=(const InnerNotTemplated &Other) = default;
+
+ private:
+ int I;
+ };
+
+private:
+ const T TVar{};
+};
+
+int FunctionWithInnerClass() {
+ class InnerNotAssignable {
+ public:
+ InnerNotAssignable &operator=(InnerNotAssignable &&Other) = default;
+ // CHECK-MESSAGES: warning: move assignment operator is explicitly defaulted but implicitly deleted
+ private:
+ const int I = 0;
+ };
+ return 1;
+};
+
+template <typename T>
+int TemplateFunctionWithInnerClass() {
+ class InnerNotAssignable {
+ public:
+ InnerNotAssignable &operator=(InnerNotAssignable &&Other) = default;
+ private:
+ const T TVar{};
+ };
+ return 1;
+};
+
+void Foo() {
+ Templated<const int> V1;
+ Templated<int>::InnerTemplated V2;
+ Templated<float>::InnerNotTemplated V3;
+ TemplateFunctionWithInnerClass<int>();
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-else-after-return-if-constexpr.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-else-after-return-if-constexpr.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-else-after-return-if-constexpr.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-else-after-return-if-constexpr.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,22 @@
+// RUN: %check_clang_tidy %s readability-else-after-return %t -- -- -std=c++17
+
+// Constexpr if is an exception to the rule, we cannot remove the else.
+void f() {
+ if (sizeof(int) > 4)
+ return;
+ else
+ return;
+ // CHECK-MESSAGES: [[@LINE-2]]:3: warning: do not use 'else' after 'return'
+
+ if constexpr (sizeof(int) > 4)
+ return;
+ else
+ return;
+
+ if constexpr (sizeof(int) > 4)
+ return;
+ else if constexpr (sizeof(long) > 4)
+ return;
+ else
+ return;
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-else-after-return.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-else-after-return.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-else-after-return.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-else-after-return.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,119 @@
+// RUN: %check_clang_tidy %s readability-else-after-return %t -- -- -fexceptions
+
+namespace std {
+struct string {
+ string(const char *);
+ ~string();
+};
+} // namespace std
+
+struct my_exception {
+ my_exception(const std::string &s);
+};
+
+void f(int a) {
+ if (a > 0)
+ return;
+ else // comment-0
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use 'else' after 'return'
+ // CHECK-FIXES: {{^}} // comment-0
+ return;
+
+ if (a > 0) {
+ return;
+ } else { // comment-1
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not use 'else' after 'return'
+ // CHECK-FIXES: {{^}} } // comment-1
+ return;
+ }
+
+ if (a > 0) {
+ f(0);
+ if (a > 10)
+ return;
+ } else {
+ return;
+ }
+
+ if (a > 0)
+ f(0);
+ else if (a > 10)
+ return;
+ else // comment-2
+ // CHECK-FIXES-NOT: {{^}} // comment-2
+ f(0);
+
+ if (a > 0)
+ if (a < 10)
+ return;
+ else // comment-3
+ // CHECK-FIXES-NOT: {{^}} // comment-3
+ f(0);
+ else
+ if (a > 10)
+ return;
+ else // comment-4
+ // CHECK-FIXES-NOT: {{^}} // comment-4
+ f(0);
+
+ if (a > 0) {
+ if (a < 10)
+ return;
+ else // comment-5
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not use 'else' after 'return'
+ // CHECK-FIXES: {{^}} // comment-5
+ f(0);
+ } else {
+ if (a > 10)
+ return;
+ else // comment-6
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not use 'else' after 'return'
+ // CHECK-FIXES: {{^}} // comment-6
+ f(0);
+ }
+}
+
+void foo() {
+ for (unsigned x = 0; x < 42; ++x) {
+ if (x) {
+ continue;
+ } else { // comment-7
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: do not use 'else' after 'continue'
+ // CHECK-FIXES: {{^}} } // comment-7
+ x++;
+ }
+ if (x) {
+ break;
+ } else { // comment-8
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: do not use 'else' after 'break'
+ // CHECK-FIXES: {{^}} } // comment-8
+ x++;
+ }
+ if (x) {
+ throw 42;
+ } else { // comment-9
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: do not use 'else' after 'throw'
+ // CHECK-FIXES: {{^}} } // comment-9
+ x++;
+ }
+ if (x) {
+ throw my_exception("foo");
+ } else { // comment-10
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: do not use 'else' after 'throw'
+ // CHECK-FIXES: {{^}} } // comment-10
+ x++;
+ }
+ }
+}
+
+extern int *g();
+extern void h(int **x);
+
+int *decl_in_condition() {
+ if (int *x = g()) {
+ return x;
+ } else {
+ h(&x);
+ return x;
+ }
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-function-size-variables-c++17.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-function-size-variables-c%2B%2B17.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-function-size-variables-c++17.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-function-size-variables-c++17.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,21 @@
+// RUN: %check_clang_tidy %s readability-function-size %t -- -config='{CheckOptions: [{key: readability-function-size.LineThreshold, value: 0}, {key: readability-function-size.StatementThreshold, value: 0}, {key: readability-function-size.BranchThreshold, value: 0}, {key: readability-function-size.ParameterThreshold, value: 5}, {key: readability-function-size.NestingThreshold, value: 2}, {key: readability-function-size.VariableThreshold, value: 1}]}' -- -std=c++17
+
+void structured_bindings() {
+ int a[2] = {1, 2};
+ auto [x, y] = a;
+}
+// CHECK-MESSAGES: :[[@LINE-4]]:6: warning: function 'structured_bindings' exceeds recommended size/complexity thresholds [readability-function-size]
+// CHECK-MESSAGES: :[[@LINE-5]]:6: note: 3 lines including whitespace and comments (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-6]]:6: note: 2 statements (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-7]]:6: note: 3 variables (threshold 1)
+
+#define SWAP(x, y) ({auto& [x0, x1] = x; __typeof__(x) t = {x0, x1}; auto& [y0, y1] = y; auto& [t0, t1] = t; x0 = y0; x1 = y1; y0 = t0; y1 = t1; })
+void variables_13() {
+ int a[2] = {1, 2};
+ int b[2] = {3, 4};
+ SWAP(a, b);
+}
+// CHECK-MESSAGES: :[[@LINE-5]]:6: warning: function 'variables_13' exceeds recommended size/complexity thresholds [readability-function-size]
+// CHECK-MESSAGES: :[[@LINE-6]]:6: note: 4 lines including whitespace and comments (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-7]]:6: note: 11 statements (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-8]]:6: note: 2 variables (threshold 1)
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-function-size.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-function-size.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-function-size.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-function-size.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,309 @@
+// RUN: %check_clang_tidy %s readability-function-size %t -- \
+// RUN: -config='{CheckOptions: [ \
+// RUN: {key: readability-function-size.LineThreshold, value: 0}, \
+// RUN: {key: readability-function-size.StatementThreshold, value: 0}, \
+// RUN: {key: readability-function-size.BranchThreshold, value: 0}, \
+// RUN: {key: readability-function-size.ParameterThreshold, value: 5}, \
+// RUN: {key: readability-function-size.NestingThreshold, value: 2}, \
+// RUN: {key: readability-function-size.VariableThreshold, value: 1} \
+// RUN: ]}'
+
+// Bad formatting is intentional, don't run clang-format over the whole file!
+
+void foo1() {
+}
+
+void foo2() {;}
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'foo2' exceeds recommended size/complexity thresholds [readability-function-size]
+// CHECK-MESSAGES: :[[@LINE-2]]:6: note: 1 statements (threshold 0)
+
+void foo3() {
+;
+
+}
+// CHECK-MESSAGES: :[[@LINE-4]]:6: warning: function 'foo3' exceeds recommended size/complexity
+// CHECK-MESSAGES: :[[@LINE-5]]:6: note: 3 lines including whitespace and comments (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-6]]:6: note: 1 statements (threshold 0)
+
+void foo4(int i) { if (i) {} else; {}
+}
+// CHECK-MESSAGES: :[[@LINE-2]]:6: warning: function 'foo4' exceeds recommended size/complexity
+// CHECK-MESSAGES: :[[@LINE-3]]:6: note: 1 lines including whitespace and comments (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-4]]:6: note: 3 statements (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-5]]:6: note: 1 branches (threshold 0)
+
+void foo5(int i) {for(;i;)while(i)
+do;while(i);
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:6: warning: function 'foo5' exceeds recommended size/complexity
+// CHECK-MESSAGES: :[[@LINE-4]]:6: note: 2 lines including whitespace and comments (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-5]]:6: note: 7 statements (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-6]]:6: note: 3 branches (threshold 0)
+
+template <typename T> T foo6(T i) {return i;
+}
+int x = foo6(0);
+// CHECK-MESSAGES: :[[@LINE-3]]:25: warning: function 'foo6' exceeds recommended size/complexity
+// CHECK-MESSAGES: :[[@LINE-4]]:25: note: 1 lines including whitespace and comments (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-5]]:25: note: 1 statements (threshold 0)
+
+void foo7(int p1, int p2, int p3, int p4, int p5, int p6) {;}
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'foo7' exceeds recommended size/complexity
+// CHECK-MESSAGES: :[[@LINE-2]]:6: note: 1 statements (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-3]]:6: note: 6 parameters (threshold 5)
+
+void bar1() { [](){;;;;;;;;;;;if(1){}}();
+
+
+}
+// CHECK-MESSAGES: :[[@LINE-4]]:6: warning: function 'bar1' exceeds recommended size/complexity
+// CHECK-MESSAGES: :[[@LINE-5]]:6: note: 3 lines including whitespace and comments (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-6]]:6: note: 14 statements (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-7]]:6: note: 1 branches (threshold 0)
+
+void bar2() { class A { void barx() {;;} }; }
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'bar2' exceeds recommended size/complexity
+// CHECK-MESSAGES: :[[@LINE-2]]:6: note: 3 statements (threshold 0)
+//
+// CHECK-MESSAGES: :[[@LINE-4]]:30: warning: function 'barx' exceeds recommended size/complexity
+// CHECK-MESSAGES: :[[@LINE-5]]:30: note: 2 statements (threshold 0)
+
+#define macro() {int x; {int y; {int z;}}}
+
+void baz0() { // 1
+ // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'baz0' exceeds recommended size/complexity
+ // CHECK-MESSAGES: :[[@LINE-2]]:6: note: 28 lines including whitespace and comments (threshold 0)
+ // CHECK-MESSAGES: :[[@LINE-3]]:6: note: 9 statements (threshold 0)
+ int a;
+ { // 2
+ int b;
+ { // 3
+// CHECK-MESSAGES: :[[@LINE-1]]:5: note: nesting level 3 starts here (threshold 2)
+ int c;
+ { // 4
+ int d;
+ }
+ }
+ }
+ { // 2
+ int e;
+ }
+ { // 2
+ { // 3
+// CHECK-MESSAGES: :[[@LINE-1]]:5: note: nesting level 3 starts here (threshold 2)
+ int j;
+ }
+ }
+ macro()
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: note: nesting level 3 starts here (threshold 2)
+ // CHECK-MESSAGES: :[[@LINE-28]]:25: note: expanded from macro 'macro'
+ // CHECK-MESSAGES: :[[@LINE-27]]:6: note: 9 variables (threshold 1)
+}
+
+// check that nested if's are not reported. this was broken initially
+void nesting_if() { // 1
+ // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'nesting_if' exceeds recommended size/complexity
+ // CHECK-MESSAGES: :[[@LINE-2]]:6: note: 23 lines including whitespace and comments (threshold 0)
+ // CHECK-MESSAGES: :[[@LINE-3]]:6: note: 18 statements (threshold 0)
+ // CHECK-MESSAGES: :[[@LINE-4]]:6: note: 6 branches (threshold 0)
+ if (true) { // 2
+ int j;
+ } else if (true) { // 2
+ int j;
+ if (true) { // 3
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: note: nesting level 3 starts here (threshold 2)
+ int j;
+ }
+ } else if (true) { // 2
+ int j;
+ if (true) { // 3
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: note: nesting level 3 starts here (threshold 2)
+ int j;
+ }
+ } else if (true) { // 2
+ int j;
+ }
+ // CHECK-MESSAGES: :[[@LINE-22]]:6: note: 6 variables (threshold 1)
+}
+
+// however this should warn
+void bad_if_nesting() { // 1
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'bad_if_nesting' exceeds recommended size/complexity
+// CHECK-MESSAGES: :[[@LINE-2]]:6: note: 23 lines including whitespace and comments (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-3]]:6: note: 12 statements (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-4]]:6: note: 4 branches (threshold 0)
+ if (true) { // 2
+ int j;
+ } else { // 2
+ if (true) { // 3
+ // CHECK-MESSAGES: :[[@LINE-1]]:15: note: nesting level 3 starts here (threshold 2)
+ int j;
+ } else { // 3
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: note: nesting level 3 starts here (threshold 2)
+ if (true) { // 4
+ int j;
+ } else { // 4
+ if (true) { // 5
+ int j;
+ }
+ }
+ }
+ }
+ // CHECK-MESSAGES: :[[@LINE-22]]:6: note: 4 variables (threshold 1)
+}
+
+void variables_0() {
+ int i;
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:6: warning: function 'variables_0' exceeds recommended size/complexity thresholds [readability-function-size]
+// CHECK-MESSAGES: :[[@LINE-4]]:6: note: 2 lines including whitespace and comments (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-5]]:6: note: 1 statements (threshold 0)
+void variables_1(int i) {
+ int j;
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:6: warning: function 'variables_1' exceeds recommended size/complexity thresholds [readability-function-size]
+// CHECK-MESSAGES: :[[@LINE-4]]:6: note: 2 lines including whitespace and comments (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-5]]:6: note: 1 statements (threshold 0)
+void variables_2(int i, int j) {
+ ;
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:6: warning: function 'variables_2' exceeds recommended size/complexity thresholds [readability-function-size]
+// CHECK-MESSAGES: :[[@LINE-4]]:6: note: 2 lines including whitespace and comments (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-5]]:6: note: 1 statements (threshold 0)
+void variables_3() {
+ int i[2];
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:6: warning: function 'variables_3' exceeds recommended size/complexity thresholds [readability-function-size]
+// CHECK-MESSAGES: :[[@LINE-4]]:6: note: 2 lines including whitespace and comments (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-5]]:6: note: 1 statements (threshold 0)
+void variables_4() {
+ int i;
+ int j;
+}
+// CHECK-MESSAGES: :[[@LINE-4]]:6: warning: function 'variables_4' exceeds recommended size/complexity thresholds [readability-function-size]
+// CHECK-MESSAGES: :[[@LINE-5]]:6: note: 3 lines including whitespace and comments (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-6]]:6: note: 2 statements (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-7]]:6: note: 2 variables (threshold 1)
+void variables_5() {
+ int i, j;
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:6: warning: function 'variables_5' exceeds recommended size/complexity thresholds [readability-function-size]
+// CHECK-MESSAGES: :[[@LINE-4]]:6: note: 2 lines including whitespace and comments (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-5]]:6: note: 1 statements (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-6]]:6: note: 2 variables (threshold 1)
+void variables_6() {
+ for (int i;;)
+ for (int j;;)
+ ;
+}
+// CHECK-MESSAGES: :[[@LINE-5]]:6: warning: function 'variables_6' exceeds recommended size/complexity thresholds [readability-function-size]
+// CHECK-MESSAGES: :[[@LINE-6]]:6: note: 4 lines including whitespace and comments (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-7]]:6: note: 5 statements (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-8]]:6: note: 2 branches (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-9]]:6: note: 2 variables (threshold 1)
+void variables_7() {
+ if (int a = 1)
+ if (int b = 2)
+ ;
+}
+// CHECK-MESSAGES: :[[@LINE-5]]:6: warning: function 'variables_7' exceeds recommended size/complexity thresholds [readability-function-size]
+// CHECK-MESSAGES: :[[@LINE-6]]:6: note: 4 lines including whitespace and comments (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-7]]:6: note: 7 statements (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-8]]:6: note: 2 branches (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-9]]:6: note: 2 variables (threshold 1)
+void variables_8() {
+ int a[2];
+ for (auto i : a)
+ for (auto j : a)
+ ;
+}
+// CHECK-MESSAGES: :[[@LINE-6]]:6: warning: function 'variables_8' exceeds recommended size/complexity thresholds [readability-function-size]
+// CHECK-MESSAGES: :[[@LINE-7]]:6: note: 5 lines including whitespace and comments (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-8]]:6: note: 8 statements (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-9]]:6: note: 2 branches (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-10]]:6: note: 3 variables (threshold 1)
+void variables_9() {
+ int a, b;
+ struct A {
+ A(int c, int d) {
+ int e, f;
+ }
+ };
+}
+// CHECK-MESSAGES: :[[@LINE-8]]:6: warning: function 'variables_9' exceeds recommended size/complexity thresholds [readability-function-size]
+// CHECK-MESSAGES: :[[@LINE-9]]:6: note: 7 lines including whitespace and comments (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-10]]:6: note: 3 statements (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-11]]:6: note: 2 variables (threshold 1)
+// CHECK-MESSAGES: :[[@LINE-9]]:5: warning: function 'A' exceeds recommended size/complexity thresholds [readability-function-size]
+// CHECK-MESSAGES: :[[@LINE-10]]:5: note: 2 lines including whitespace and comments (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-11]]:5: note: 1 statements (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-12]]:5: note: 2 variables (threshold 1)
+void variables_10() {
+ int a, b;
+ struct A {
+ int c;
+ int d;
+ };
+}
+// CHECK-MESSAGES: :[[@LINE-7]]:6: warning: function 'variables_10' exceeds recommended size/complexity thresholds [readability-function-size]
+// CHECK-MESSAGES: :[[@LINE-8]]:6: note: 6 lines including whitespace and comments (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-9]]:6: note: 2 statements (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-10]]:6: note: 2 variables (threshold 1)
+void variables_11() {
+ struct S {
+ void bar() {
+ int a, b;
+ }
+ };
+}
+// CHECK-MESSAGES: :[[@LINE-7]]:6: warning: function 'variables_11' exceeds recommended size/complexity thresholds [readability-function-size]
+// CHECK-MESSAGES: :[[@LINE-8]]:6: note: 6 lines including whitespace and comments (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-7]]:10: warning: function 'bar' exceeds recommended size/complexity thresholds [readability-function-size]
+// CHECK-MESSAGES: :[[@LINE-8]]:10: note: 2 lines including whitespace and comments (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-9]]:10: note: 2 variables (threshold 1)
+void variables_12() {
+ int v;
+ auto test = [](int a, int b) -> void {};
+ test({}, {});
+}
+// CHECK-MESSAGES: :[[@LINE-5]]:6: warning: function 'variables_12' exceeds recommended size/complexity thresholds [readability-function-size]
+// CHECK-MESSAGES: :[[@LINE-6]]:6: note: 4 lines including whitespace and comments (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-7]]:6: note: 3 statements (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-8]]:6: note: 2 variables (threshold 1)
+void variables_13() {
+ int v;
+ auto test = []() -> void {
+ int a;
+ int b;
+ };
+ test();
+}
+// CHECK-MESSAGES: :[[@LINE-8]]:6: warning: function 'variables_13' exceeds recommended size/complexity thresholds [readability-function-size]
+// CHECK-MESSAGES: :[[@LINE-9]]:6: note: 7 lines including whitespace and comments (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-10]]:6: note: 5 statements (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-11]]:6: note: 2 variables (threshold 1)
+void variables_14() {
+ (void)({int a = 12; a; });
+ (void)({int a = 12; a; });
+}
+// CHECK-MESSAGES: :[[@LINE-4]]:6: warning: function 'variables_14' exceeds recommended size/complexity thresholds [readability-function-size]
+// CHECK-MESSAGES: :[[@LINE-5]]:6: note: 3 lines including whitespace and comments (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-6]]:6: note: 6 statements (threshold 0)
+#define SWAP(x, y) ({__typeof__(x) temp = x; x = y; y = temp; })
+void variables_15() {
+ int a = 10, b = 12;
+ SWAP(a, b);
+}
+// CHECK-MESSAGES: :[[@LINE-4]]:6: warning: function 'variables_15' exceeds recommended size/complexity thresholds [readability-function-size]
+// CHECK-MESSAGES: :[[@LINE-5]]:6: note: 3 lines including whitespace and comments (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-6]]:6: note: 5 statements (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-7]]:6: note: 2 variables (threshold 1)
+#define vardecl(type, name) type name;
+void variables_16() {
+ vardecl(int, a);
+ vardecl(int, b);
+}
+// CHECK-MESSAGES: :[[@LINE-4]]:6: warning: function 'variables_16' exceeds recommended size/complexity thresholds [readability-function-size]
+// CHECK-MESSAGES: :[[@LINE-5]]:6: note: 3 lines including whitespace and comments (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-6]]:6: note: 4 statements (threshold 0)
+// CHECK-MESSAGES: :[[@LINE-7]]:6: note: 2 variables (threshold 1)
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-identifier-naming-bugfix.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-identifier-naming-bugfix.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-identifier-naming-bugfix.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-identifier-naming-bugfix.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,5 @@
+// RUN: %check_clang_tidy -expect-clang-tidy-error %s readability-identifier-naming %t
+
+// This used to cause a null pointer dereference.
+auto [left] = right;
+// CHECK-MESSAGES: :[[@LINE-1]]:15: error: use of undeclared identifier 'right'
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-identifier-naming-objc.m
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-identifier-naming-objc.m?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-identifier-naming-objc.m (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-identifier-naming-objc.m Fri Oct 11 05:05:42 2019
@@ -0,0 +1,12 @@
+// RUN: %check_clang_tidy %s readability-identifier-naming %t \
+// RUN: -config='{CheckOptions: \
+// RUN: [{key: readability-identifier-naming.ObjcIvarPrefix, value: '_'}]}' \
+// RUN: --
+
+ at interface Foo {
+ int _bar;
+ int barWithoutPrefix;
+ // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for objc ivar 'barWithoutPrefix' [readability-identifier-naming]
+ // CHECK-FIXES: int _barWithoutPrefix;
+}
+ at end
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-identifier-naming.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-identifier-naming.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-identifier-naming.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-identifier-naming.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,529 @@
+// Remove UNSUPPORTED for powerpc64le when the problem introduced by
+// r288563 is resolved.
+// UNSUPPORTED: powerpc64le
+// RUN: %check_clang_tidy %s readability-identifier-naming %t -- \
+// RUN: -config='{CheckOptions: [ \
+// RUN: {key: readability-identifier-naming.AbstractClassCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.AbstractClassPrefix, value: 'A'}, \
+// RUN: {key: readability-identifier-naming.ClassCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.ClassPrefix, value: 'C'}, \
+// RUN: {key: readability-identifier-naming.ClassConstantCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.ClassConstantPrefix, value: 'k'}, \
+// RUN: {key: readability-identifier-naming.ClassMemberCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.ClassMethodCase, value: camelBack}, \
+// RUN: {key: readability-identifier-naming.ConstantCase, value: UPPER_CASE}, \
+// RUN: {key: readability-identifier-naming.ConstantSuffix, value: '_CST'}, \
+// RUN: {key: readability-identifier-naming.ConstexprFunctionCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.ConstexprMethodCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.ConstexprVariableCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.EnumCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.EnumPrefix, value: 'E'}, \
+// RUN: {key: readability-identifier-naming.EnumConstantCase, value: UPPER_CASE}, \
+// RUN: {key: readability-identifier-naming.FunctionCase, value: camelBack}, \
+// RUN: {key: readability-identifier-naming.GlobalConstantCase, value: UPPER_CASE}, \
+// RUN: {key: readability-identifier-naming.GlobalFunctionCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.GlobalVariableCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.GlobalVariablePrefix, value: 'g_'}, \
+// RUN: {key: readability-identifier-naming.InlineNamespaceCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.LocalConstantCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.LocalConstantPrefix, value: 'k'}, \
+// RUN: {key: readability-identifier-naming.LocalVariableCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.MemberCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.MemberPrefix, value: 'm_'}, \
+// RUN: {key: readability-identifier-naming.ConstantMemberCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.PrivateMemberPrefix, value: '__'}, \
+// RUN: {key: readability-identifier-naming.ProtectedMemberPrefix, value: '_'}, \
+// RUN: {key: readability-identifier-naming.PublicMemberCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.MethodCase, value: camelBack}, \
+// RUN: {key: readability-identifier-naming.PrivateMethodPrefix, value: '__'}, \
+// RUN: {key: readability-identifier-naming.ProtectedMethodPrefix, value: '_'}, \
+// RUN: {key: readability-identifier-naming.NamespaceCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.ParameterCase, value: camelBack}, \
+// RUN: {key: readability-identifier-naming.ParameterPrefix, value: 'a_'}, \
+// RUN: {key: readability-identifier-naming.ConstantParameterCase, value: camelBack}, \
+// RUN: {key: readability-identifier-naming.ConstantParameterPrefix, value: 'i_'}, \
+// RUN: {key: readability-identifier-naming.ParameterPackCase, value: camelBack}, \
+// RUN: {key: readability-identifier-naming.PureFunctionCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.PureMethodCase, value: camelBack}, \
+// RUN: {key: readability-identifier-naming.StaticConstantCase, value: UPPER_CASE}, \
+// RUN: {key: readability-identifier-naming.StaticVariableCase, value: camelBack}, \
+// RUN: {key: readability-identifier-naming.StaticVariablePrefix, value: 's_'}, \
+// RUN: {key: readability-identifier-naming.StructCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.TemplateParameterCase, value: UPPER_CASE}, \
+// RUN: {key: readability-identifier-naming.TemplateTemplateParameterCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.TemplateUsingCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.TemplateUsingPrefix, value: 'u_'}, \
+// RUN: {key: readability-identifier-naming.TypeTemplateParameterCase, value: camelBack}, \
+// RUN: {key: readability-identifier-naming.TypeTemplateParameterSuffix, value: '_t'}, \
+// RUN: {key: readability-identifier-naming.TypedefCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.TypedefSuffix, value: '_t'}, \
+// RUN: {key: readability-identifier-naming.UnionCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.UnionPrefix, value: 'U'}, \
+// RUN: {key: readability-identifier-naming.UsingCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.ValueTemplateParameterCase, value: camelBack}, \
+// RUN: {key: readability-identifier-naming.VariableCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.VirtualMethodCase, value: Camel_Snake_Case}, \
+// RUN: {key: readability-identifier-naming.VirtualMethodPrefix, value: 'v_'}, \
+// RUN: {key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE}, \
+// RUN: {key: readability-identifier-naming.TypeAliasCase, value: camel_Snake_Back}, \
+// RUN: {key: readability-identifier-naming.TypeAliasSuffix, value: '_t'}, \
+// RUN: {key: readability-identifier-naming.IgnoreFailedSplit, value: 0}, \
+// RUN: {key: readability-identifier-naming.GlobalPointerCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.GlobalPointerSuffix, value: '_Ptr'}, \
+// RUN: {key: readability-identifier-naming.GlobalConstantPointerCase, value: UPPER_CASE}, \
+// RUN: {key: readability-identifier-naming.GlobalConstantPointerSuffix, value: '_Ptr'}, \
+// RUN: {key: readability-identifier-naming.PointerParameterCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.PointerParameterPrefix, value: 'p_'}, \
+// RUN: {key: readability-identifier-naming.ConstantPointerParameterCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.ConstantPointerParameterPrefix, value: 'cp_'}, \
+// RUN: {key: readability-identifier-naming.LocalPointerCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.LocalPointerPrefix, value: 'l_'}, \
+// RUN: {key: readability-identifier-naming.LocalConstantPointerCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.LocalConstantPointerPrefix, value: 'lc_'}, \
+// RUN: ]}' -- -fno-delayed-template-parsing \
+// RUN: -I%S/Inputs/readability-identifier-naming \
+// RUN: -isystem %S/Inputs/readability-identifier-naming/system
+
+// clang-format off
+
+#include <system-header.h>
+#include "user-header.h"
+// NO warnings or fixes expected from declarations within header files without
+// the -header-filter= option
+
+namespace FOO_NS {
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: invalid case style for namespace 'FOO_NS' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}namespace foo_ns {{{$}}
+inline namespace InlineNamespace {
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for inline namespace 'InlineNamespace'
+// CHECK-FIXES: {{^}}inline namespace inline_namespace {{{$}}
+
+SYSTEM_NS::structure g_s1;
+// NO warnings or fixes expected as SYSTEM_NS and structure are declared in a header file
+
+USER_NS::object g_s2;
+// NO warnings or fixes expected as USER_NS and object are declared in a header file
+
+SYSTEM_MACRO(var1);
+// NO warnings or fixes expected as var1 is from macro expansion
+
+USER_MACRO(var2);
+// NO warnings or fixes expected as var2 is declared in a macro expansion
+
+#define BLA int FOO_bar
+BLA;
+// NO warnings or fixes expected as FOO_bar is from macro expansion
+
+int global0;
+#define USE_NUMBERED_GLOBAL(number) auto use_global##number = global##number
+USE_NUMBERED_GLOBAL(0);
+// NO warnings or fixes expected as global0 is pieced together in a macro
+// expansion.
+
+int global1;
+#define USE_NUMBERED_BAL(prefix, number) \
+ auto use_##prefix##bal##number = prefix##bal##number
+USE_NUMBERED_BAL(glo, 1);
+// NO warnings or fixes expected as global1 is pieced together in a macro
+// expansion.
+
+int global2;
+#define USE_RECONSTRUCTED(glo, bal) auto use_##glo##bal = glo##bal
+USE_RECONSTRUCTED(glo, bal2);
+// NO warnings or fixes expected as global2 is pieced together in a macro
+// expansion.
+
+int global;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'global'
+// CHECK-FIXES: {{^}}int g_global;{{$}}
+#define USE_IN_MACRO(m) auto use_##m = m
+USE_IN_MACRO(global);
+
+int global3;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'global3'
+// CHECK-FIXES: {{^}}int g_global3;{{$}}
+#define ADD_TO_SELF(m) (m) + (m)
+int g_twice_global3 = ADD_TO_SELF(global3);
+// CHECK-FIXES: {{^}}int g_twice_global3 = ADD_TO_SELF(g_global3);{{$}}
+
+enum my_enumeration {
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for enum 'my_enumeration'
+// CHECK-FIXES: {{^}}enum EMyEnumeration {{{$}}
+ MyConstant = 1,
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for enum constant 'MyConstant'
+// CHECK-FIXES: {{^}} MY_CONSTANT = 1,{{$}}
+ your_CONST = 1,
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for enum constant 'your_CONST'
+// CHECK-FIXES: {{^}} YOUR_CONST = 1,{{$}}
+ THIS_ConstValue = 1,
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for enum constant 'THIS_ConstValue'
+// CHECK-FIXES: {{^}} THIS_CONST_VALUE = 1,{{$}}
+};
+
+constexpr int ConstExpr_variable = MyConstant;
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: invalid case style for constexpr variable 'ConstExpr_variable'
+// CHECK-FIXES: {{^}}constexpr int const_expr_variable = MY_CONSTANT;{{$}}
+
+class my_class {
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 'my_class'
+// CHECK-FIXES: {{^}}class CMyClass {{{$}}
+public:
+ my_class();
+// CHECK-FIXES: {{^}} CMyClass();{{$}}
+
+ my_class(void*) : my_class() {}
+// CHECK-FIXES: {{^}} CMyClass(void*) : CMyClass() {}{{$}}
+
+ ~
+ my_class();
+// (space in destructor token test, we could check trigraph but they will be deprecated)
+// CHECK-FIXES: {{^}} ~{{$}}
+// CHECK-FIXES: {{^}} CMyClass();{{$}}
+
+private:
+ const int MEMBER_one_1 = ConstExpr_variable;
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for constant member 'MEMBER_one_1'
+// CHECK-FIXES: {{^}} const int member_one_1 = const_expr_variable;{{$}}
+ int member2 = 2;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private member 'member2'
+// CHECK-FIXES: {{^}} int __member2 = 2;{{$}}
+ int _memberWithExtraUnderscores_ = 42;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private member '_memberWithExtraUnderscores_'
+// CHECK-FIXES: {{^}} int __memberWithExtraUnderscores = 42;{{$}}
+
+private:
+ int private_member = 3;
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for private member 'private_member'
+// CHECK-FIXES: {{^}} int __private_member = 3;{{$}}
+
+protected:
+ int ProtMember;
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for protected member 'ProtMember'
+// CHECK-FIXES: {{^}} int _ProtMember;{{$}}
+
+public:
+ int PubMem;
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for public member 'PubMem'
+// CHECK-FIXES: {{^}} int pub_mem;{{$}}
+
+ static const int classConstant;
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: invalid case style for class constant 'classConstant'
+// CHECK-FIXES: {{^}} static const int kClassConstant;{{$}}
+ static int ClassMember_2;
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: invalid case style for class member 'ClassMember_2'
+// CHECK-FIXES: {{^}} static int ClassMember2;{{$}}
+};
+class my_class;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 'my_class'
+// CHECK-FIXES: {{^}}class CMyClass;{{$}}
+
+class my_forward_declared_class; // No warning should be triggered.
+
+const int my_class::classConstant = 4;
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: invalid case style for class constant 'classConstant'
+// CHECK-FIXES: {{^}}const int CMyClass::kClassConstant = 4;{{$}}
+
+int my_class::ClassMember_2 = 5;
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: invalid case style for class member 'ClassMember_2'
+// CHECK-FIXES: {{^}}int CMyClass::ClassMember2 = 5;{{$}}
+
+class my_derived_class : public virtual my_class {};
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 'my_derived_class'
+// CHECK-FIXES: {{^}}class CMyDerivedClass : public virtual CMyClass {};{{$}}
+
+class CMyWellNamedClass {};
+// No warning expected as this class is well named.
+
+template <typename t_t>
+class CMyWellNamedClass2 : public my_class {
+ // CHECK-FIXES: {{^}}class CMyWellNamedClass2 : public CMyClass {{{$}}
+ t_t my_Bad_Member;
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private member 'my_Bad_Member'
+ // CHECK-FIXES: {{^}} t_t __my_Bad_Member;{{$}}
+ int my_Other_Bad_Member = 42;
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private member 'my_Other_Bad_Member'
+ // CHECK-FIXES: {{^}} int __my_Other_Bad_Member = 42;{{$}}
+public:
+ CMyWellNamedClass2() = default;
+ CMyWellNamedClass2(CMyWellNamedClass2 const&) = default;
+ CMyWellNamedClass2(CMyWellNamedClass2 &&) = default;
+ CMyWellNamedClass2(t_t a_v, void *p_p) : my_class(p_p), my_Bad_Member(a_v) {}
+ // CHECK-FIXES: {{^}} CMyWellNamedClass2(t_t a_v, void *p_p) : CMyClass(p_p), __my_Bad_Member(a_v) {}{{$}}
+
+ CMyWellNamedClass2(t_t a_v) : my_class(), my_Bad_Member(a_v), my_Other_Bad_Member(11) {}
+ // CHECK-FIXES: {{^}} CMyWellNamedClass2(t_t a_v) : CMyClass(), __my_Bad_Member(a_v), __my_Other_Bad_Member(11) {}{{$}}
+};
+void InstantiateClassMethods() {
+ // Ensure we trigger the instantiation of each constructor
+ CMyWellNamedClass2<int> x;
+ CMyWellNamedClass2<int> x2 = x;
+ CMyWellNamedClass2<int> x3 = static_cast<CMyWellNamedClass2<int>&&>(x2);
+ CMyWellNamedClass2<int> x4(42);
+ CMyWellNamedClass2<int> x5(42, nullptr);
+}
+
+class AOverridden {
+public:
+ virtual ~AOverridden() = default;
+ virtual void BadBaseMethod() = 0;
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: invalid case style for virtual method 'BadBaseMethod'
+};
+
+class COverriding : public AOverridden {
+public:
+ // Overriding a badly-named base isn't a new violation.
+ void BadBaseMethod() override {}
+};
+
+template <typename derived_t>
+class CRTPBase {
+public:
+ void BadBaseMethod(int) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for method 'BadBaseMethod'
+};
+
+class CRTPDerived : CRTPBase<CRTPDerived> {
+public:
+ // Hiding a badly-named base isn't a new violation.
+ double BadBaseMethod(double) { return 0; }
+};
+
+template<typename T>
+// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: invalid case style for type template parameter 'T'
+// CHECK-FIXES: {{^}}template<typename t_t>{{$}}
+class my_templated_class : CMyWellNamedClass {};
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 'my_templated_class'
+// CHECK-FIXES: {{^}}class CMyTemplatedClass : CMyWellNamedClass {};{{$}}
+
+template<typename T>
+// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: invalid case style for type template parameter 'T'
+// CHECK-FIXES: {{^}}template<typename t_t>{{$}}
+class my_other_templated_class : my_templated_class< my_class>, private my_derived_class {};
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 'my_other_templated_class'
+// CHECK-FIXES: {{^}}class CMyOtherTemplatedClass : CMyTemplatedClass< CMyClass>, private CMyDerivedClass {};{{$}}
+
+template<typename t_t>
+using mysuper_tpl_t = my_other_templated_class <:: FOO_NS ::my_class>;
+// CHECK-FIXES: {{^}}using mysuper_tpl_t = CMyOtherTemplatedClass <:: foo_ns ::CMyClass>;{{$}}
+
+const int global_Constant = 6;
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: invalid case style for global constant 'global_Constant'
+// CHECK-FIXES: {{^}}const int GLOBAL_CONSTANT = 6;{{$}}
+int Global_variable = 7;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'Global_variable'
+// CHECK-FIXES: {{^}}int g_global_variable = 7;{{$}}
+
+void global_function(int PARAMETER_1, int const CONST_parameter) {
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global function 'global_function'
+// CHECK-MESSAGES: :[[@LINE-2]]:26: warning: invalid case style for parameter 'PARAMETER_1'
+// CHECK-MESSAGES: :[[@LINE-3]]:49: warning: invalid case style for constant parameter 'CONST_parameter'
+// CHECK-FIXES: {{^}}void GlobalFunction(int a_parameter1, int const i_constParameter) {{{$}}
+ static const int THIS_static_ConsTant = 4;
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: invalid case style for static constant 'THIS_static_ConsTant'
+// CHECK-FIXES: {{^}} static const int THIS_STATIC_CONS_TANT = 4;{{$}}
+ static int THIS_static_variable;
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: invalid case style for static variable 'THIS_static_variable'
+// CHECK-FIXES: {{^}} static int s_thisStaticVariable;{{$}}
+ int const local_Constant = 3;
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: invalid case style for local constant 'local_Constant'
+// CHECK-FIXES: {{^}} int const kLocalConstant = 3;{{$}}
+ int LOCAL_VARIABLE;
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for local variable 'LOCAL_VARIABLE'
+// CHECK-FIXES: {{^}} int local_variable;{{$}}
+
+ int LOCAL_Array__[] = {0, 1, 2};
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for local variable 'LOCAL_Array__'
+// CHECK-FIXES: {{^}} int local_array[] = {0, 1, 2};{{$}}
+
+ for (auto _ : LOCAL_Array__) {
+ }
+}
+
+template<typename ... TYPE_parameters>
+// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: invalid case style for type template parameter 'TYPE_parameters'
+// CHECK-FIXES: {{^}}template<typename ... typeParameters_t>{{$}}
+void Global_Fun(TYPE_parameters... PARAMETER_PACK) {
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global function 'Global_Fun'
+// CHECK-MESSAGES: :[[@LINE-2]]:36: warning: invalid case style for parameter pack 'PARAMETER_PACK'
+// CHECK-FIXES: {{^}}void GlobalFun(typeParameters_t... parameterPack) {{{$}}
+ global_function(1, 2);
+// CHECK-FIXES: {{^}} GlobalFunction(1, 2);{{$}}
+ FOO_bar = Global_variable;
+// CHECK-FIXES: {{^}} FOO_bar = g_global_variable;{{$}}
+// NO fix expected for FOO_bar declared in macro expansion
+}
+
+template<template<typename> class TPL_parameter, int COUNT_params, typename ... TYPE_parameters>
+// CHECK-MESSAGES: :[[@LINE-1]]:35: warning: invalid case style for template template parameter 'TPL_parameter'
+// CHECK-MESSAGES: :[[@LINE-2]]:54: warning: invalid case style for value template parameter 'COUNT_params'
+// CHECK-MESSAGES: :[[@LINE-3]]:81: warning: invalid case style for type template parameter 'TYPE_parameters'
+// CHECK-FIXES: {{^}}template<template<typename> class TplParameter, int countParams, typename ... typeParameters_t>{{$}}
+class test_CLASS {
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 'test_CLASS'
+// CHECK-FIXES: {{^}}class CTestClass {{{$}}
+};
+
+class abstract_class {
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for abstract class 'abstract_class'
+// CHECK-FIXES: {{^}}class AAbstractClass {{{$}}
+ virtual ~abstract_class() = 0;
+// CHECK-FIXES: {{^}} virtual ~AAbstractClass() = 0;{{$}}
+ virtual void VIRTUAL_METHOD();
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for virtual method 'VIRTUAL_METHOD'
+// CHECK-FIXES: {{^}} virtual void v_Virtual_Method();{{$}}
+ void non_Virtual_METHOD() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for private method 'non_Virtual_METHOD'
+// CHECK-FIXES: {{^}} void __non_Virtual_METHOD() {}{{$}}
+
+public:
+ static void CLASS_METHOD() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: invalid case style for class method 'CLASS_METHOD'
+// CHECK-FIXES: {{^}} static void classMethod() {}{{$}}
+
+ constexpr int CST_expr_Method() { return 2; }
+// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: invalid case style for constexpr method 'CST_expr_Method'
+// CHECK-FIXES: {{^}} constexpr int cst_expr_method() { return 2; }{{$}}
+
+private:
+ void PRIVate_Method();
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for private method 'PRIVate_Method'
+// CHECK-FIXES: {{^}} void __PRIVate_Method();{{$}}
+protected:
+ void protected_Method();
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for protected method 'protected_Method'
+// CHECK-FIXES: {{^}} void _protected_Method();{{$}}
+public:
+ void public_Method();
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for method 'public_Method'
+// CHECK-FIXES: {{^}} void publicMethod();{{$}}
+};
+
+constexpr int CE_function() { return 3; }
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: invalid case style for constexpr function 'CE_function'
+// CHECK-FIXES: {{^}}constexpr int ce_function() { return 3; }{{$}}
+
+struct THIS___Structure {
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for struct 'THIS___Structure'
+// CHECK-FIXES: {{^}}struct this_structure {{{$}}
+ THIS___Structure();
+// CHECK-FIXES: {{^}} this_structure();{{$}}
+
+ union __MyUnion_is_wonderful__ {};
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for union '__MyUnion_is_wonderful__'
+// CHECK-FIXES: {{^}} union UMyUnionIsWonderful {};{{$}}
+};
+
+typedef THIS___Structure struct_type;
+// CHECK-MESSAGES: :[[@LINE-1]]:26: warning: invalid case style for typedef 'struct_type'
+// CHECK-FIXES: {{^}}typedef this_structure struct_type_t;{{$}}
+
+struct_type GlobalTypedefTestFunction(struct_type a_argument1) {
+// CHECK-FIXES: {{^}}struct_type_t GlobalTypedefTestFunction(struct_type_t a_argument1) {
+ struct_type typedef_test_1;
+// CHECK-FIXES: {{^}} struct_type_t typedef_test_1;
+}
+
+using my_struct_type = THIS___Structure;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for type alias 'my_struct_type'
+// CHECK-FIXES: {{^}}using my_Struct_Type_t = this_structure;{{$}}
+
+template<typename t_t>
+using SomeOtherTemplate = my_other_templated_class <:: FOO_NS ::my_class>;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for type alias 'SomeOtherTemplate'
+// CHECK-FIXES: {{^}}using some_Other_Template_t = CMyOtherTemplatedClass <:: foo_ns ::CMyClass>;{{$}}
+
+static void static_Function() {
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for function 'static_Function'
+// CHECK-FIXES: {{^}}static void staticFunction() {{{$}}
+
+ ::FOO_NS::InlineNamespace::abstract_class::CLASS_METHOD();
+// CHECK-FIXES: {{^}} ::foo_ns::inline_namespace::AAbstractClass::classMethod();{{$}}
+ ::FOO_NS::InlineNamespace::static_Function();
+// CHECK-FIXES: {{^}} ::foo_ns::inline_namespace::staticFunction();{{$}}
+
+ using ::FOO_NS::InlineNamespace::CE_function;
+// CHECK-FIXES: {{^}} using ::foo_ns::inline_namespace::ce_function;{{$}}
+
+ unsigned MY_LOCAL_array[] = {1,2,3};
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: invalid case style for local variable 'MY_LOCAL_array'
+// CHECK-FIXES: {{^}} unsigned my_local_array[] = {1,2,3};{{$}}
+
+ unsigned const MyConstLocal_array[] = {1,2,3};
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for local constant 'MyConstLocal_array'
+// CHECK-FIXES: {{^}} unsigned const kMyConstLocalArray[] = {1,2,3};{{$}}
+
+ static unsigned MY_STATIC_array[] = {1,2,3};
+// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: invalid case style for static variable 'MY_STATIC_array'
+// CHECK-FIXES: {{^}} static unsigned s_myStaticArray[] = {1,2,3};{{$}}
+
+ static unsigned const MyConstStatic_array[] = {1,2,3};
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: invalid case style for static constant 'MyConstStatic_array'
+// CHECK-FIXES: {{^}} static unsigned const MY_CONST_STATIC_ARRAY[] = {1,2,3};{{$}}
+
+ char MY_LOCAL_string[] = "123";
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for local variable 'MY_LOCAL_string'
+// CHECK-FIXES: {{^}} char my_local_string[] = "123";{{$}}
+
+ char const MyConstLocal_string[] = "123";
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: invalid case style for local constant 'MyConstLocal_string'
+// CHECK-FIXES: {{^}} char const kMyConstLocalString[] = "123";{{$}}
+
+ static char MY_STATIC_string[] = "123";
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: invalid case style for static variable 'MY_STATIC_string'
+// CHECK-FIXES: {{^}} static char s_myStaticString[] = "123";{{$}}
+
+ static char const MyConstStatic_string[] = "123";
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: invalid case style for static constant 'MyConstStatic_string'
+// CHECK-FIXES: {{^}} static char const MY_CONST_STATIC_STRING[] = "123";{{$}}
+}
+
+#define MY_TEST_Macro(X) X()
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for macro definition 'MY_TEST_Macro'
+// CHECK-FIXES: {{^}}#define MY_TEST_MACRO(X) X()
+
+void MY_TEST_Macro(function) {}
+// CHECK-FIXES: {{^}}void MY_TEST_MACRO(function) {}
+}
+}
+
+template <typename t_t> struct a {
+ typename t_t::template b<> c;
+
+ char const MY_ConstMember_string[4] = "123";
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: invalid case style for constant member 'MY_ConstMember_string'
+// CHECK-FIXES: {{^}} char const my_const_member_string[4] = "123";{{$}}
+
+ static char const MyConstClass_string[];
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: invalid case style for class constant 'MyConstClass_string'
+// CHECK-FIXES: {{^}} static char const kMyConstClassString[];{{$}}
+};
+
+template<typename t_t>
+char const a<t_t>::MyConstClass_string[] = "123";
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: invalid case style for class constant 'MyConstClass_string'
+// CHECK-FIXES: {{^}}char const a<t_t>::kMyConstClassString[] = "123";{{$}}
+
+template <template <typename> class A> struct b { A<int> c; };
+
+unsigned MY_GLOBAL_array[] = {1,2,3};
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for global variable 'MY_GLOBAL_array'
+// CHECK-FIXES: {{^}}unsigned g_my_global_array[] = {1,2,3};{{$}}
+
+unsigned const MyConstGlobal_array[] = {1,2,3};
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: invalid case style for global constant 'MyConstGlobal_array'
+// CHECK-FIXES: {{^}}unsigned const MY_CONST_GLOBAL_ARRAY[] = {1,2,3};{{$}}
+
+int * MyGlobal_Ptr;// -> ok
+int * const MyConstantGlobalPointer = nullptr;
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for global constant pointer 'MyConstantGlobalPointer'
+// CHECK-FIXES: {{^}}int * const MY_CONSTANT_GLOBAL_POINTER_Ptr = nullptr;{{$}}
+
+void MyPoiterFunction(int * p_normal_pointer, int * const constant_ptr){
+// CHECK-MESSAGES: :[[@LINE-1]]:59: warning: invalid case style for constant pointer parameter 'constant_ptr'
+// CHECK-FIXES: {{^}}void MyPoiterFunction(int * p_normal_pointer, int * const cp_ConstantPtr){{{$}}
+ int * l_PointerA;
+ int * const pointer_b = nullptr;
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: invalid case style for local constant pointer 'pointer_b'
+// CHECK-FIXES: {{^}} int * const lc_PointerB = nullptr;{{$}}
+}
+
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-implicit-bool-conversion-allow-in-conditions.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-implicit-bool-conversion-allow-in-conditions.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-implicit-bool-conversion-allow-in-conditions.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-implicit-bool-conversion-allow-in-conditions.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,71 @@
+// RUN: %check_clang_tidy %s readability-implicit-bool-conversion %t \
+// RUN: -config='{CheckOptions: \
+// RUN: [{key: readability-implicit-bool-conversion.AllowIntegerConditions, value: 1}, \
+// RUN: {key: readability-implicit-bool-conversion.AllowPointerConditions, value: 1}]}'
+
+template<typename T>
+void functionTaking(T);
+
+int functionReturningInt();
+int* functionReturningPointer();
+
+struct Struct {
+ int member;
+ unsigned bitfield : 1;
+};
+
+
+void regularImplicitConversionIntegerToBoolIsNotIgnored() {
+ int integer = 0;
+ functionTaking<bool>(integer);
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'int' -> bool [readability-implicit-bool-conversion]
+ // CHECK-FIXES: functionTaking<bool>(integer != 0);
+}
+
+void implicitConversionIntegerToBoolInConditionalsIsAllowed() {
+ Struct s = {};
+ if (s.member) {}
+ if (!s.member) {}
+ if (s.bitfield) {}
+ if (!s.bitfield) {}
+ if (functionReturningInt()) {}
+ if (!functionReturningInt()) {}
+ if (functionReturningInt() && functionReturningPointer()) {}
+ if (!functionReturningInt() && !functionReturningPointer()) {}
+ for (; functionReturningInt(); ) {}
+ for (; functionReturningPointer(); ) {}
+ for (; functionReturningInt() && !functionReturningPointer() || (!functionReturningInt() && functionReturningPointer()); ) {}
+ while (functionReturningInt()) {}
+ while (functionReturningPointer()) {}
+ while (functionReturningInt() && !functionReturningPointer() || (!functionReturningInt() && functionReturningPointer())) {}
+ int value1 = functionReturningInt() ? 1 : 2;
+ int value2 = !functionReturningInt() ? 1 : 2;
+ int value3 = (functionReturningInt() && functionReturningPointer() || !functionReturningInt()) ? 1 : 2;
+ int value4 = functionReturningInt() ?: value3;
+ int *p1 = functionReturningPointer() ?: &value3;
+}
+
+void regularImplicitConversionPointerToBoolIsNotIgnored() {
+ int* pointer = nullptr;
+ functionTaking<bool>(pointer);
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'int *' -> bool
+ // CHECK-FIXES: functionTaking<bool>(pointer != nullptr);
+
+ int Struct::* memberPointer = &Struct::member;
+ functionTaking<bool>(memberPointer);
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'int Struct::*' -> bool
+ // CHECK-FIXES: functionTaking<bool>(memberPointer != nullptr);
+}
+
+void implicitConversionPointerToBoolInConditionalsIsAllowed() {
+ if (functionReturningPointer()) {}
+ if (not functionReturningPointer()) {}
+ int value1 = functionReturningPointer() ? 1 : 2;
+ int value2 = (not functionReturningPointer()) ? 1 : 2;
+
+ int Struct::* memberPointer = &Struct::member;
+ if (memberPointer) {}
+ if (memberPointer) {}
+ int value3 = memberPointer ? 1 : 2;
+ int value4 = (not memberPointer) ? 1 : 2;
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-implicit-bool-conversion-cxx98.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-implicit-bool-conversion-cxx98.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-implicit-bool-conversion-cxx98.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-implicit-bool-conversion-cxx98.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,45 @@
+// RUN: %check_clang_tidy -std=c++98 %s readability-implicit-bool-conversion %t
+
+// We need NULL macro, but some buildbots don't like including <cstddef> header
+// This is a portable way of getting it to work
+#undef NULL
+#define NULL 0L
+
+template<typename T>
+void functionTaking(T);
+
+struct Struct {
+ int member;
+};
+
+void useOldNullMacroInReplacements() {
+ int* pointer = NULL;
+ functionTaking<bool>(pointer);
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'int *' -> bool [readability-implicit-bool-conversion]
+ // CHECK-FIXES: functionTaking<bool>(pointer != 0);
+
+ int Struct::* memberPointer = NULL;
+ functionTaking<bool>(!memberPointer);
+ // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: implicit conversion 'int Struct::*' -> bool
+ // CHECK-FIXES: functionTaking<bool>(memberPointer == 0);
+}
+
+void fixFalseLiteralConvertingToNullPointer() {
+ functionTaking<int*>(false);
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion bool -> 'int *'
+ // CHECK-FIXES: functionTaking<int*>(0);
+
+ int* pointer = NULL;
+ if (pointer == false) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: implicit conversion bool -> 'int *'
+ // CHECK-FIXES: if (pointer == 0) {}
+
+ functionTaking<int Struct::*>(false);
+ // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: implicit conversion bool -> 'int Struct::*'
+ // CHECK-FIXES: functionTaking<int Struct::*>(0);
+
+ int Struct::* memberPointer = NULL;
+ if (memberPointer != false) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion bool -> 'int Struct::*'
+ // CHECK-FIXES: if (memberPointer != 0) {}
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-implicit-bool-conversion.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-implicit-bool-conversion.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-implicit-bool-conversion.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-implicit-bool-conversion.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,473 @@
+// RUN: %check_clang_tidy %s readability-implicit-bool-conversion %t
+
+// We need NULL macro, but some buildbots don't like including <cstddef> header
+// This is a portable way of getting it to work
+#undef NULL
+#define NULL 0L
+
+template<typename T>
+void functionTaking(T);
+
+struct Struct {
+ int member;
+};
+
+
+////////// Implicit conversion from bool.
+
+void implicitConversionFromBoolSimpleCases() {
+ bool boolean = true;
+
+ functionTaking<bool>(boolean);
+
+ functionTaking<int>(boolean);
+ // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: implicit conversion bool -> 'int' [readability-implicit-bool-conversion]
+ // CHECK-FIXES: functionTaking<int>(static_cast<int>(boolean));
+
+ functionTaking<unsigned long>(boolean);
+ // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: implicit conversion bool -> 'unsigned long'
+ // CHECK-FIXES: functionTaking<unsigned long>(static_cast<unsigned long>(boolean));
+
+ functionTaking<char>(boolean);
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion bool -> 'char'
+ // CHECK-FIXES: functionTaking<char>(static_cast<char>(boolean));
+
+ functionTaking<float>(boolean);
+ // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: implicit conversion bool -> 'float'
+ // CHECK-FIXES: functionTaking<float>(static_cast<float>(boolean));
+
+ functionTaking<double>(boolean);
+ // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: implicit conversion bool -> 'double'
+ // CHECK-FIXES: functionTaking<double>(static_cast<double>(boolean));
+}
+
+float implicitConversionFromBoolInReturnValue() {
+ bool boolean = false;
+ return boolean;
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: implicit conversion bool -> 'float'
+ // CHECK-FIXES: return static_cast<float>(boolean);
+}
+
+void implicitConversionFromBoolInSingleBoolExpressions(bool b1, bool b2) {
+ bool boolean = true;
+ boolean = b1 ^ b2;
+ boolean = b1 && b2;
+ boolean |= !b1 || !b2;
+ boolean &= b1;
+ boolean = b1 == true;
+ boolean = b2 != false;
+
+ int integer = boolean - 3;
+ // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: implicit conversion bool -> 'int'
+ // CHECK-FIXES: int integer = static_cast<int>(boolean) - 3;
+
+ float floating = boolean / 0.3f;
+ // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: implicit conversion bool -> 'float'
+ // CHECK-FIXES: float floating = static_cast<float>(boolean) / 0.3f;
+
+ char character = boolean;
+ // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: implicit conversion bool -> 'char'
+ // CHECK-FIXES: char character = static_cast<char>(boolean);
+}
+
+void implicitConversionFromBoollInComplexBoolExpressions() {
+ bool boolean = true;
+ bool anotherBoolean = false;
+
+ int integer = boolean && anotherBoolean;
+ // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: implicit conversion bool -> 'int'
+ // CHECK-FIXES: int integer = static_cast<int>(boolean && anotherBoolean);
+
+ unsigned long unsignedLong = (! boolean) + 4ul;
+ // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: implicit conversion bool -> 'unsigned long'
+ // CHECK-FIXES: unsigned long unsignedLong = static_cast<unsigned long>(! boolean) + 4ul;
+
+ float floating = (boolean || anotherBoolean) * 0.3f;
+ // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: implicit conversion bool -> 'float'
+ // CHECK-FIXES: float floating = static_cast<float>(boolean || anotherBoolean) * 0.3f;
+
+ double doubleFloating = (boolean && (anotherBoolean || boolean)) * 0.3;
+ // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: implicit conversion bool -> 'double'
+ // CHECK-FIXES: double doubleFloating = static_cast<double>(boolean && (anotherBoolean || boolean)) * 0.3;
+}
+
+void implicitConversionFromBoolLiterals() {
+ functionTaking<int>(true);
+ // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: implicit conversion bool -> 'int'
+ // CHECK-FIXES: functionTaking<int>(1);
+
+ functionTaking<unsigned long>(false);
+ // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: implicit conversion bool -> 'unsigned long'
+ // CHECK-FIXES: functionTaking<unsigned long>(0u);
+
+ functionTaking<signed char>(true);
+ // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: implicit conversion bool -> 'signed char'
+ // CHECK-FIXES: functionTaking<signed char>(1);
+
+ functionTaking<float>(false);
+ // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: implicit conversion bool -> 'float'
+ // CHECK-FIXES: functionTaking<float>(0.0f);
+
+ functionTaking<double>(true);
+ // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: implicit conversion bool -> 'double'
+ // CHECK-FIXES: functionTaking<double>(1.0);
+}
+
+void implicitConversionFromBoolInComparisons() {
+ bool boolean = true;
+ int integer = 0;
+
+ functionTaking<bool>(boolean == integer);
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion bool -> 'int'
+ // CHECK-FIXES: functionTaking<bool>(static_cast<int>(boolean) == integer);
+
+ functionTaking<bool>(integer != boolean);
+ // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: implicit conversion bool -> 'int'
+ // CHECK-FIXES: functionTaking<bool>(integer != static_cast<int>(boolean));
+}
+
+void ignoreBoolComparisons() {
+ bool boolean = true;
+ bool anotherBoolean = false;
+
+ functionTaking<bool>(boolean == anotherBoolean);
+ functionTaking<bool>(boolean != anotherBoolean);
+}
+
+void ignoreExplicitCastsFromBool() {
+ bool boolean = true;
+
+ int integer = static_cast<int>(boolean) + 3;
+ float floating = static_cast<float>(boolean) * 0.3f;
+ char character = static_cast<char>(boolean);
+}
+
+void ignoreImplicitConversionFromBoolInMacroExpansions() {
+ bool boolean = true;
+
+ #define CAST_FROM_BOOL_IN_MACRO_BODY boolean + 3
+ int integerFromMacroBody = CAST_FROM_BOOL_IN_MACRO_BODY;
+
+ #define CAST_FROM_BOOL_IN_MACRO_ARGUMENT(x) x + 3
+ int integerFromMacroArgument = CAST_FROM_BOOL_IN_MACRO_ARGUMENT(boolean);
+}
+
+namespace ignoreImplicitConversionFromBoolInTemplateInstantiations {
+
+template<typename T>
+void templateFunction() {
+ bool boolean = true;
+ T uknownType = boolean + 3;
+}
+
+void useOfTemplateFunction() {
+ templateFunction<int>();
+}
+
+} // namespace ignoreImplicitConversionFromBoolInTemplateInstantiations
+
+////////// Implicit conversions to bool.
+
+void implicitConversionToBoolSimpleCases() {
+ int integer = 10;
+ functionTaking<bool>(integer);
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'int' -> bool
+ // CHECK-FIXES: functionTaking<bool>(integer != 0);
+
+ unsigned long unsignedLong = 10;
+ functionTaking<bool>(unsignedLong);
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'unsigned long' -> bool
+ // CHECK-FIXES: functionTaking<bool>(unsignedLong != 0u);
+
+ float floating = 0.0f;
+ functionTaking<bool>(floating);
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'float' -> bool
+ // CHECK-FIXES: functionTaking<bool>(floating != 0.0f);
+
+ double doubleFloating = 1.0f;
+ functionTaking<bool>(doubleFloating);
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'double' -> bool
+ // CHECK-FIXES: functionTaking<bool>(doubleFloating != 0.0);
+
+ signed char character = 'a';
+ functionTaking<bool>(character);
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'signed char' -> bool
+ // CHECK-FIXES: functionTaking<bool>(character != 0);
+
+ int* pointer = nullptr;
+ functionTaking<bool>(pointer);
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'int *' -> bool
+ // CHECK-FIXES: functionTaking<bool>(pointer != nullptr);
+
+ auto pointerToMember = &Struct::member;
+ functionTaking<bool>(pointerToMember);
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'int Struct::*' -> bool
+ // CHECK-FIXES: functionTaking<bool>(pointerToMember != nullptr);
+}
+
+void implicitConversionToBoolInSingleExpressions() {
+ int integer = 10;
+ bool boolComingFromInt = integer;
+ // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: implicit conversion 'int' -> bool
+ // CHECK-FIXES: bool boolComingFromInt = integer != 0;
+
+ float floating = 10.0f;
+ bool boolComingFromFloat = floating;
+ // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: implicit conversion 'float' -> bool
+ // CHECK-FIXES: bool boolComingFromFloat = floating != 0.0f;
+
+ signed char character = 'a';
+ bool boolComingFromChar = character;
+ // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: implicit conversion 'signed char' -> bool
+ // CHECK-FIXES: bool boolComingFromChar = character != 0;
+
+ int* pointer = nullptr;
+ bool boolComingFromPointer = pointer;
+ // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: implicit conversion 'int *' -> bool
+ // CHECK-FIXES: bool boolComingFromPointer = pointer != nullptr;
+}
+
+void implicitConversionToBoolInComplexExpressions() {
+ bool boolean = true;
+
+ int integer = 10;
+ int anotherInteger = 20;
+ bool boolComingFromInteger = integer + anotherInteger;
+ // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: implicit conversion 'int' -> bool
+ // CHECK-FIXES: bool boolComingFromInteger = (integer + anotherInteger) != 0;
+
+ float floating = 0.2f;
+ bool boolComingFromFloating = floating - 0.3f || boolean;
+ // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: implicit conversion 'float' -> bool
+ // CHECK-FIXES: bool boolComingFromFloating = ((floating - 0.3f) != 0.0f) || boolean;
+
+ double doubleFloating = 0.3;
+ bool boolComingFromDoubleFloating = (doubleFloating - 0.4) && boolean;
+ // CHECK-MESSAGES: :[[@LINE-1]]:39: warning: implicit conversion 'double' -> bool
+ // CHECK-FIXES: bool boolComingFromDoubleFloating = ((doubleFloating - 0.4) != 0.0) && boolean;
+}
+
+void implicitConversionInNegationExpressions() {
+ int integer = 10;
+ bool boolComingFromNegatedInt = !integer;
+ // CHECK-MESSAGES: :[[@LINE-1]]:36: warning: implicit conversion 'int' -> bool
+ // CHECK-FIXES: bool boolComingFromNegatedInt = integer == 0;
+
+ float floating = 10.0f;
+ bool boolComingFromNegatedFloat = ! floating;
+ // CHECK-MESSAGES: :[[@LINE-1]]:39: warning: implicit conversion 'float' -> bool
+ // CHECK-FIXES: bool boolComingFromNegatedFloat = floating == 0.0f;
+
+ signed char character = 'a';
+ bool boolComingFromNegatedChar = (! character);
+ // CHECK-MESSAGES: :[[@LINE-1]]:39: warning: implicit conversion 'signed char' -> bool
+ // CHECK-FIXES: bool boolComingFromNegatedChar = (character == 0);
+
+ int* pointer = nullptr;
+ bool boolComingFromNegatedPointer = not pointer;
+ // CHECK-MESSAGES: :[[@LINE-1]]:43: warning: implicit conversion 'int *' -> bool
+ // CHECK-FIXES: bool boolComingFromNegatedPointer = pointer == nullptr;
+}
+
+void implicitConversionToBoolInControlStatements() {
+ int integer = 10;
+ if (integer) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: implicit conversion 'int' -> bool
+ // CHECK-FIXES: if (integer != 0) {}
+
+ long int longInteger = 0.2f;
+ for (;longInteger;) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: implicit conversion 'long' -> bool
+ // CHECK-FIXES: for (;longInteger != 0;) {}
+
+ float floating = 0.3f;
+ while (floating) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: implicit conversion 'float' -> bool
+ // CHECK-FIXES: while (floating != 0.0f) {}
+
+ double doubleFloating = 0.4;
+ do {} while (doubleFloating);
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: implicit conversion 'double' -> bool
+ // CHECK-FIXES: do {} while (doubleFloating != 0.0);
+}
+
+bool implicitConversionToBoolInReturnValue() {
+ float floating = 1.0f;
+ return floating;
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: implicit conversion 'float' -> bool
+ // CHECK-FIXES: return floating != 0.0f;
+}
+
+void implicitConversionToBoolFromLiterals() {
+ functionTaking<bool>(0);
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'int' -> bool
+ // CHECK-FIXES: functionTaking<bool>(false);
+
+ functionTaking<bool>(1);
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'int' -> bool
+ // CHECK-FIXES: functionTaking<bool>(true);
+
+ functionTaking<bool>(2ul);
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'unsigned long' -> bool
+ // CHECK-FIXES: functionTaking<bool>(true);
+
+
+ functionTaking<bool>(0.0f);
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'float' -> bool
+ // CHECK-FIXES: functionTaking<bool>(false);
+
+ functionTaking<bool>(1.0f);
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'float' -> bool
+ // CHECK-FIXES: functionTaking<bool>(true);
+
+ functionTaking<bool>(2.0);
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'double' -> bool
+ // CHECK-FIXES: functionTaking<bool>(true);
+
+
+ functionTaking<bool>('\0');
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'char' -> bool
+ // CHECK-FIXES: functionTaking<bool>(false);
+
+ functionTaking<bool>('a');
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'char' -> bool
+ // CHECK-FIXES: functionTaking<bool>(true);
+
+
+ functionTaking<bool>("");
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'const char *' -> bool
+ // CHECK-FIXES: functionTaking<bool>(true);
+
+ functionTaking<bool>("abc");
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'const char *' -> bool
+ // CHECK-FIXES: functionTaking<bool>(true);
+
+ functionTaking<bool>(NULL);
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'long' -> bool
+ // CHECK-FIXES: functionTaking<bool>(false);
+}
+
+void implicitConversionToBoolFromUnaryMinusAndZeroLiterals() {
+ functionTaking<bool>(-0);
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'int' -> bool
+ // CHECK-FIXES: functionTaking<bool>((-0) != 0);
+
+ functionTaking<bool>(-0.0f);
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'float' -> bool
+ // CHECK-FIXES: functionTaking<bool>((-0.0f) != 0.0f);
+
+ functionTaking<bool>(-0.0);
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'double' -> bool
+ // CHECK-FIXES: functionTaking<bool>((-0.0) != 0.0);
+}
+
+void implicitConversionToBoolInWithOverloadedOperators() {
+ struct UserStruct {
+ int operator()(int x) { return x; }
+ int operator+(int y) { return y; }
+ };
+
+ UserStruct s;
+
+ functionTaking<bool>(s(0));
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'int' -> bool
+ // CHECK-FIXES: functionTaking<bool>(s(0) != 0);
+
+ functionTaking<bool>(s + 2);
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'int' -> bool
+ // CHECK-FIXES: functionTaking<bool>((s + 2) != 0);
+}
+
+int functionReturningInt();
+int* functionReturningPointer();
+
+void ignoreImplicitConversionToBoolWhenDeclaringVariableInControlStatements() {
+ if (int integer = functionReturningInt()) {}
+
+ while (int* pointer = functionReturningPointer()) {}
+}
+
+void ignoreExplicitCastsToBool() {
+ int integer = 10;
+ bool boolComingFromInt = static_cast<bool>(integer);
+
+ float floating = 10.0f;
+ bool boolComingFromFloat = static_cast<bool>(floating);
+
+ char character = 'a';
+ bool boolComingFromChar = static_cast<bool>(character);
+
+ int* pointer = nullptr;
+ bool booleanComingFromPointer = static_cast<bool>(pointer);
+}
+
+void ignoreImplicitConversionToBoolInMacroExpansions() {
+ int integer = 3;
+
+ #define CAST_TO_BOOL_IN_MACRO_BODY integer && false
+ bool boolFromMacroBody = CAST_TO_BOOL_IN_MACRO_BODY;
+
+ #define CAST_TO_BOOL_IN_MACRO_ARGUMENT(x) x || true
+ bool boolFromMacroArgument = CAST_TO_BOOL_IN_MACRO_ARGUMENT(integer);
+}
+
+namespace ignoreImplicitConversionToBoolInTemplateInstantiations {
+
+template<typename T>
+void templateFunction() {
+ T unknownType = 0;
+ bool boolean = unknownType;
+}
+
+void useOfTemplateFunction() {
+ templateFunction<int>();
+}
+
+} // namespace ignoreImplicitConversionToBoolInTemplateInstantiations
+
+namespace ignoreUserDefinedConversionOperator {
+
+struct StructWithUserConversion {
+ operator bool();
+};
+
+void useOfUserConversion() {
+ StructWithUserConversion structure;
+ functionTaking<bool>(structure);
+}
+
+} // namespace ignoreUserDefinedConversionOperator
+
+namespace ignore_1bit_bitfields {
+
+struct S {
+ int a;
+ int b : 1;
+ int c : 2;
+
+ S(bool a, bool b, bool c) : a(a), b(b), c(c) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: implicit conversion bool -> 'int'
+ // CHECK-MESSAGES: :[[@LINE-2]]:45: warning: implicit conversion bool -> 'int'
+ // CHECK-FIXES: S(bool a, bool b, bool c) : a(static_cast<int>(a)), b(b), c(static_cast<int>(c)) {}
+};
+
+bool f(S& s) {
+ functionTaking<bool>(s.a);
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'int' -> bool
+ // CHECK-FIXES: functionTaking<bool>(s.a != 0);
+ functionTaking<bool>(s.b);
+ // CHECK-FIXES: functionTaking<bool>(s.b);
+ s.a = true;
+ // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: implicit conversion bool -> 'int'
+ // CHECK-FIXES: s.a = 1;
+ s.b = true;
+ // CHECK-FIXES: s.b = true;
+ s.c = true;
+ // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: implicit conversion bool -> 'int'
+ // CHECK-FIXES: s.c = 1;
+ functionTaking<bool>(s.c);
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'int' -> bool
+ // CHECK-FIXES: functionTaking<bool>(s.c != 0);
+}
+
+} // namespace ignore_1bit_bitfields
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-inconsistent-declaration-parameter-name-macros.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-inconsistent-declaration-parameter-name-macros.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-inconsistent-declaration-parameter-name-macros.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-inconsistent-declaration-parameter-name-macros.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,46 @@
+// RUN: %check_clang_tidy %s readability-inconsistent-declaration-parameter-name %t -- \
+// RUN: -config="{CheckOptions: [{key: readability-inconsistent-declaration-parameter-name.IgnoreMacros, value: 0}]}"
+
+#define MACRO() \
+ void f(int x)
+
+struct S1 {
+ MACRO();
+ // CHECK-NOTES: :[[@LINE-1]]:3: warning: function 'S1::f' has a definition with different parameter names
+ // CHECK-NOTES: :[[@LINE-5]]:8: note: expanded from macro 'MACRO'
+ // CHECK-NOTES: :[[@LINE+4]]:10: note: the definition seen here
+ // CHECK-NOTES: :[[@LINE-4]]:3: note: differing parameters are named here: ('x'), in definition: ('y')
+ // CHECK-NOTES: :[[@LINE-8]]:8: note: expanded from macro 'MACRO'
+};
+void S1::f(int y) {}
+
+struct S2 {
+ int g() const;
+ void set_g(int g);
+ // CHECK-NOTES: :[[@LINE-1]]:8: warning: function 'S2::set_g' has a definition with different parameter names
+ // CHECK-NOTES: :[[@LINE+14]]:1: note: the definition seen here
+ // CHECK-NOTES: :[[@LINE+9]]:12: note: expanded from macro 'DEFINITION'
+ // This one is unfortunate, but the location this points to is in a scratch
+ // space, so it's not helpful to the user.
+ // CHECK-NOTES: {{^}}note: expanded from here{{$}}
+ // CHECK-NOTES: :[[@LINE-7]]:8: note: differing parameters are named here: ('g'), in definition: ('w')
+};
+
+#define DEFINITION(name, parameter) \
+ int S2::name() const { return 0; } \
+ void S2::set_##name(int parameter) { \
+ (void)parameter; \
+ }
+
+DEFINITION(g, w)
+
+//////////////////////////////////////////////////////
+
+#define DECLARE_FUNCTION_WITH_PARAM_NAME(function_name, param_name) \
+ void function_name(int param_name)
+
+// CHECK-NOTES: :[[@LINE+1]]:34: warning: function 'macroFunction' has 1 other declaration with different parameter names [readability-inconsistent-declaration-parameter-name]
+DECLARE_FUNCTION_WITH_PARAM_NAME(macroFunction, a);
+// CHECK-NOTES: :[[@LINE+2]]:34: note: the 1st inconsistent declaration seen here
+// CHECK-NOTES: :[[@LINE+1]]:34: note: differing parameters are named here: ('b'), in the other declaration: ('a')
+DECLARE_FUNCTION_WITH_PARAM_NAME(macroFunction, b);
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-inconsistent-declaration-parameter-name-strict.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-inconsistent-declaration-parameter-name-strict.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-inconsistent-declaration-parameter-name-strict.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-inconsistent-declaration-parameter-name-strict.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,10 @@
+// RUN: %check_clang_tidy %s readability-inconsistent-declaration-parameter-name %t -- \
+// RUN: -config="{CheckOptions: [{key: readability-inconsistent-declaration-parameter-name.Strict, value: 1}]}"
+
+void inconsistentFunction(int a, int b, int c);
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'inconsistentFunction' has 1 other declaration with different parameter names
+void inconsistentFunction(int prefixA, int b, int cSuffix);
+// CHECK-MESSAGES: :[[@LINE-1]]:6: note: the 1st inconsistent declaration seen here
+// CHECK-MESSAGES: :[[@LINE-2]]:6: note: differing parameters are named here: ('prefixA', 'cSuffix'), in the other declaration: ('a', 'c')
+void inconsistentFunction(int a, int b, int c);
+void inconsistentFunction(int /*c*/, int /*c*/, int /*c*/);
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-inconsistent-declaration-parameter-name.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-inconsistent-declaration-parameter-name.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-inconsistent-declaration-parameter-name.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-inconsistent-declaration-parameter-name.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,193 @@
+// RUN: %check_clang_tidy %s readability-inconsistent-declaration-parameter-name %t -- -- -fno-delayed-template-parsing
+
+void consistentFunction(int a, int b, int c);
+void consistentFunction(int a, int b, int c);
+void consistentFunction(int prefixA, int b, int cSuffix);
+void consistentFunction(int a, int b, int c);
+void consistentFunction(int a, int b, int /*c*/);
+void consistentFunction(int /*c*/, int /*c*/, int /*c*/);
+
+//////////////////////////////////////////////////////
+
+// CHECK-MESSAGES: :[[@LINE+1]]:6: warning: function 'inconsistentFunction' has 2 other declarations with different parameter names [readability-inconsistent-declaration-parameter-name]
+void inconsistentFunction(int a, int b, int c);
+// CHECK-MESSAGES: :[[@LINE+2]]:6: note: the 1st inconsistent declaration seen here
+// CHECK-MESSAGES: :[[@LINE+1]]:6: note: differing parameters are named here: ('d', 'e', 'f'), in the other declaration: ('a', 'b', 'c')
+void inconsistentFunction(int d, int e, int f);
+// CHECK-MESSAGES: :[[@LINE+2]]:6: note: the 2nd inconsistent declaration seen here
+// CHECK-MESSAGES: :[[@LINE+1]]:6: note: differing parameters are named here: ('x', 'y', 'z'), in the other declaration: ('a', 'b', 'c')
+void inconsistentFunction(int x, int y, int z);
+
+//////////////////////////////////////////////////////
+
+// CHECK-MESSAGES: :[[@LINE+4]]:6: warning: function 'inconsistentFunctionWithVisibleDefinition' has a definition with different parameter names [readability-inconsistent-declaration-parameter-name]
+// CHECK-MESSAGES: :[[@LINE+9]]:6: note: the definition seen here
+// CHECK-MESSAGES: :[[@LINE+2]]:6: note: differing parameters are named here: ('a'), in definition: ('c')
+// CHECK-FIXES: void inconsistentFunctionWithVisibleDefinition(int c);
+void inconsistentFunctionWithVisibleDefinition(int a);
+// CHECK-MESSAGES: :[[@LINE+4]]:6: warning: function 'inconsistentFunctionWithVisibleDefinition' has a definition
+// CHECK-MESSAGES: :[[@LINE+4]]:6: note: the definition seen here
+// CHECK-MESSAGES: :[[@LINE+2]]:6: note: differing parameters are named here: ('b'), in definition: ('c')
+// CHECK-FIXES: void inconsistentFunctionWithVisibleDefinition(int c);
+void inconsistentFunctionWithVisibleDefinition(int b);
+void inconsistentFunctionWithVisibleDefinition(int c) { c; }
+
+// CHECK-MESSAGES: :[[@LINE+3]]:6: warning: function 'inconsidentFunctionWithUnreferencedParameterInDefinition' has a definition
+// CHECK-MESSAGES: :[[@LINE+3]]:6: note: the definition seen here
+// CHECK-MESSAGES: :[[@LINE+1]]:6: note: differing parameters are named here: ('a'), in definition: ('b')
+void inconsidentFunctionWithUnreferencedParameterInDefinition(int a);
+void inconsidentFunctionWithUnreferencedParameterInDefinition(int b) {}
+
+//////////////////////////////////////////////////////
+
+struct Struct {
+// CHECK-MESSAGES: :[[@LINE+4]]:8: warning: function 'Struct::inconsistentFunction' has a definition
+// CHECK-MESSAGES: :[[@LINE+6]]:14: note: the definition seen here
+// CHECK-MESSAGES: :[[@LINE+2]]:8: note: differing parameters are named here: ('a'), in definition: ('b')
+// CHECK-FIXES: void inconsistentFunction(int b);
+ void inconsistentFunction(int a);
+};
+
+void Struct::inconsistentFunction(int b) { b = 0; }
+
+//////////////////////////////////////////////////////
+
+struct SpecialFunctions {
+// CHECK-MESSAGES: :[[@LINE+4]]:3: warning: function 'SpecialFunctions::SpecialFunctions' has a definition
+// CHECK-MESSAGES: :[[@LINE+12]]:19: note: the definition seen here
+// CHECK-MESSAGES: :[[@LINE+2]]:3: note: differing parameters are named here: ('a'), in definition: ('b')
+// CHECK-FIXES: SpecialFunctions(int b);
+ SpecialFunctions(int a);
+
+// CHECK-MESSAGES: :[[@LINE+4]]:21: warning: function 'SpecialFunctions::operator=' has a definition
+// CHECK-MESSAGES: :[[@LINE+8]]:37: note: the definition seen here
+// CHECK-MESSAGES: :[[@LINE+2]]:21: note: differing parameters are named here: ('a'), in definition: ('b')
+// CHECK-FIXES: SpecialFunctions& operator=(const SpecialFunctions& b);
+ SpecialFunctions& operator=(const SpecialFunctions& a);
+};
+
+SpecialFunctions::SpecialFunctions(int b) { b; }
+
+SpecialFunctions& SpecialFunctions::operator=(const SpecialFunctions& b) { b; return *this; }
+
+//////////////////////////////////////////////////////
+
+// CHECK-MESSAGES: :[[@LINE+5]]:6: warning: function 'templateFunctionWithSeparateDeclarationAndDefinition' has a definition
+// CHECK-MESSAGES: :[[@LINE+7]]:6: note: the definition seen here
+// CHECK-MESSAGES: :[[@LINE+3]]:6: note: differing parameters are named here: ('a'), in definition: ('b')
+// CHECK-FIXES: void templateFunctionWithSeparateDeclarationAndDefinition(T b);
+template<typename T>
+void templateFunctionWithSeparateDeclarationAndDefinition(T a);
+
+template<typename T>
+void templateFunctionWithSeparateDeclarationAndDefinition(T b) { b; }
+
+//////////////////////////////////////////////////////
+
+template<typename T>
+void templateFunctionWithSpecializations(T a) { a; }
+
+template<>
+// CHECK-MESSAGES: :[[@LINE+3]]:6: warning: function template specialization 'templateFunctionWithSpecializations<int>' has a primary template declaration with different parameter names [readability-inconsistent-declaration-parameter-name]
+// CHECK-MESSAGES: :[[@LINE-4]]:6: note: the primary template declaration seen here
+// CHECK-MESSAGES: :[[@LINE+1]]:6: note: differing parameters are named here: ('b'), in primary template declaration: ('a')
+void templateFunctionWithSpecializations(int b) { b; }
+
+template<>
+// CHECK-MESSAGES: :[[@LINE+3]]:6: warning: function template specialization 'templateFunctionWithSpecializations<float>' has a primary template
+// CHECK-MESSAGES: :[[@LINE-10]]:6: note: the primary template declaration seen here
+// CHECK-MESSAGES: :[[@LINE+1]]:6: note: differing parameters are named here: ('c'), in primary template declaration: ('a')
+void templateFunctionWithSpecializations(float c) { c; }
+
+//////////////////////////////////////////////////////
+
+template<typename T>
+void templateFunctionWithoutDefinitionButWithSpecialization(T a);
+
+template<>
+// CHECK-MESSAGES: :[[@LINE+3]]:6: warning: function template specialization 'templateFunctionWithoutDefinitionButWithSpecialization<int>' has a primary template
+// CHECK-MESSAGES: :[[@LINE-4]]:6: note: the primary template declaration seen here
+// CHECK-MESSAGES: :[[@LINE+1]]:6: note: differing parameters are named here: ('b'), in primary template declaration: ('a')
+void templateFunctionWithoutDefinitionButWithSpecialization(int b) { b; }
+
+//////////////////////////////////////////////////////
+
+template<typename T>
+void templateFunctionWithSeparateSpecializationDeclarationAndDefinition(T a);
+
+template<>
+// CHECK-MESSAGES: :[[@LINE+3]]:6: warning: function template specialization 'templateFunctionWithSeparateSpecializationDeclarationAndDefinition<int>' has a primary template
+// CHECK-MESSAGES: :[[@LINE-4]]:6: note: the primary template declaration seen here
+// CHECK-MESSAGES: :[[@LINE+1]]:6: note: differing parameters are named here: ('b'), in primary template declaration: ('a')
+void templateFunctionWithSeparateSpecializationDeclarationAndDefinition(int b);
+
+template<>
+// CHECK-MESSAGES: :[[@LINE+3]]:6: warning: function template specialization 'templateFunctionWithSeparateSpecializationDeclarationAndDefinition<int>' has a primary template
+// CHECK-MESSAGES: :[[@LINE-10]]:6: note: the primary template declaration seen here
+// CHECK-MESSAGES: :[[@LINE+1]]:6: note: differing parameters are named here: ('c'), in primary template declaration: ('a')
+void templateFunctionWithSeparateSpecializationDeclarationAndDefinition(int c) { c; }
+
+//////////////////////////////////////////////////////
+
+template<typename T>
+class ClassTemplate
+{
+public:
+// CHECK-MESSAGES: :[[@LINE+4]]:10: warning: function 'ClassTemplate::functionInClassTemplateWithSeparateDeclarationAndDefinition' has a definition
+// CHECK-MESSAGES: :[[@LINE+7]]:24: note: the definition seen here
+// CHECK-MESSAGES: :[[@LINE+2]]:10: note: differing parameters are named here: ('a'), in definition: ('b')
+// CHECK-FIXES: void functionInClassTemplateWithSeparateDeclarationAndDefinition(int b);
+ void functionInClassTemplateWithSeparateDeclarationAndDefinition(int a);
+};
+
+template<typename T>
+void ClassTemplate<T>::functionInClassTemplateWithSeparateDeclarationAndDefinition(int b) { b; }
+
+//////////////////////////////////////////////////////
+
+class Class
+{
+public:
+ template<typename T>
+// CHECK-MESSAGES: :[[@LINE+4]]:8: warning: function 'Class::memberFunctionTemplateWithSeparateDeclarationAndDefinition' has a definition
+// CHECK-MESSAGES: :[[@LINE+12]]:13: note: the definition seen here
+// CHECK-MESSAGES: :[[@LINE+2]]:8: note: differing parameters are named here: ('a'), in definition: ('b')
+// CHECK-FIXES: void memberFunctionTemplateWithSeparateDeclarationAndDefinition(T b);
+ void memberFunctionTemplateWithSeparateDeclarationAndDefinition(T a);
+
+ template<typename T>
+ void memberFunctionTemplateWithSpecializations(T a) { a; }
+};
+
+//////////////////////////////////////////////////////
+
+template<typename T>
+void Class::memberFunctionTemplateWithSeparateDeclarationAndDefinition(T b) { b; }
+
+//////////////////////////////////////////////////////
+
+template<>
+// CHECK-MESSAGES: :[[@LINE+3]]:13: warning: function template specialization 'Class::memberFunctionTemplateWithSpecializations<int>' has a primary template
+// CHECK-MESSAGES: :[[@LINE-12]]:8: note: the primary template declaration seen here
+// CHECK-MESSAGES: :[[@LINE+1]]:13: note: differing parameters are named here: ('b'), in primary template declaration: ('a')
+void Class::memberFunctionTemplateWithSpecializations(int b) { b; }
+
+template<>
+// CHECK-MESSAGES: :[[@LINE+3]]:13: warning: function template specialization 'Class::memberFunctionTemplateWithSpecializations<float>' has a primary template
+// CHECK-MESSAGES: :[[@LINE-18]]:8: note: the primary template declaration seen here
+// CHECK-MESSAGES: :[[@LINE+1]]:13: note: differing parameters are named here: ('c'), in primary template declaration: ('a')
+void Class::memberFunctionTemplateWithSpecializations(float c) { c; }
+
+//////////////////////////////////////////////////////
+
+// This resulted in a warning by default.
+#define MACRO() \
+ void f(int x);
+
+struct S {
+ MACRO();
+};
+
+void S::f(int y)
+{
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-isolate-declaration-cxx17.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-isolate-declaration-cxx17.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-isolate-declaration-cxx17.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-isolate-declaration-cxx17.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,103 @@
+// RUN: %check_clang_tidy -std=c++17 %s readability-isolate-declaration %t
+
+template <typename T1, typename T2>
+struct pair {
+ T1 first;
+ T2 second;
+ pair(T1 v1, T2 v2) : first(v1), second(v2) {}
+
+ template <int N>
+ decltype(auto) get() const {
+ if constexpr (N == 0)
+ return first;
+ else if constexpr (N == 1)
+ return second;
+ }
+};
+
+void forbidden_transformations() {
+ if (int i = 42, j = i; i == j)
+ ;
+ switch (int i = 12, j = 14; i)
+ ;
+
+ auto [i, j] = pair<int, int>(42, 42);
+}
+
+struct SomeClass {
+ SomeClass() = default;
+ SomeClass(int value);
+};
+
+namespace std {
+template <typename T>
+class initializer_list {};
+
+template <typename T>
+class vector {
+public:
+ vector() = default;
+ vector(initializer_list<T> init) {}
+};
+
+class string {
+public:
+ string() = default;
+ string(const char *) {}
+};
+
+namespace string_literals {
+string operator""s(const char *, decltype(sizeof(int))) {
+ return string();
+}
+} // namespace string_literals
+} // namespace std
+
+namespace Types {
+typedef int MyType;
+} // namespace Types
+
+int touch1, touch2;
+
+void modern() {
+ auto autoInt1 = 3, autoInt2 = 4;
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: auto autoInt1 = 3;
+ // CHECK-FIXES: {{^ }}auto autoInt2 = 4;
+
+ decltype(int()) declnottouch = 4;
+ decltype(int()) declint1 = 5, declint2 = 3;
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: decltype(int()) declint1 = 5;
+ // CHECK-FIXES: {{^ }}decltype(int()) declint2 = 3;
+
+ std::vector<int> vectorA = {1, 2}, vectorB = {1, 2, 3}, vectorC({1, 1, 1});
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: std::vector<int> vectorA = {1, 2};
+ // CHECK-FIXES: {{^ }}std::vector<int> vectorB = {1, 2, 3};
+ // CHECK-FIXES: {{^ }}std::vector<int> vectorC({1, 1, 1});
+
+ using uType = int;
+ uType utype1, utype2;
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: uType utype1;
+ // CHECK-FIXES: {{^ }}uType utype2;
+
+ Types::MyType mytype1, mytype2, mytype3 = 3;
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: Types::MyType mytype1;
+ // CHECK-FIXES: {{^ }}Types::MyType mytype2;
+ // CHECK-FIXES: {{^ }}Types::MyType mytype3 = 3;
+
+ {
+ using namespace std::string_literals;
+
+ std::vector<std::string> s{"foo"s, "bar"s}, t{"foo"s}, u, a({"hey", "you"}), bb = {"h", "a"};
+ // CHECK-MESSAGES: [[@LINE-1]]:5: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: std::vector<std::string> s{"foo"s, "bar"s};
+ // CHECK-FIXES: {{^ }}std::vector<std::string> t{"foo"s};
+ // CHECK-FIXES: {{^ }}std::vector<std::string> u;
+ // CHECK-FIXES: {{^ }}std::vector<std::string> a({"hey", "you"});
+ // CHECK-FIXES: {{^ }}std::vector<std::string> bb = {"h", "a"};
+ }
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-isolate-declaration-fixing.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-isolate-declaration-fixing.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-isolate-declaration-fixing.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-isolate-declaration-fixing.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,64 @@
+// RUN: %check_clang_tidy %s readability-isolate-declaration %t
+// XFAIL: *
+
+struct S {
+ int a;
+ const int b;
+ void f() {}
+};
+
+void member_pointers() {
+ // FIXME: Memberpointers are transformed incorrect. Emit only a warning
+ // for now.
+ int S::*p = &S::a, S::*const q = &S::a;
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: int S::*p = &S::a;
+ // CHECK-FIXES: {{^ }}int S::*const q = &S::a;
+
+ int /* :: */ S::*pp2 = &S::a, var1 = 0;
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: int /* :: */ S::*pp2 = &S::a;
+ // CHECK-FIXES: {{^ }}int var1 = 0;
+
+ const int S::*r = &S::b, S::*t;
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: const int S::*r = &S::b;
+ // CHECK-FIXES: {{^ }}const int S::*t;
+
+ {
+ int S::*mdpa1[2] = {&S::a, &S::a}, var1 = 0;
+ // CHECK-MESSAGES: [[@LINE-1]]:5: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: int S::*mdpa1[2] = {&S::a, &S::a};
+ // CHECK-FIXES: {{^ }}int var1 = 0;
+
+ int S ::**mdpa2[2] = {&p, &pp2}, var2 = 0;
+ // CHECK-MESSAGES: [[@LINE-1]]:5: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: int S ::**mdpa2[2] = {&p, &pp2};
+ // CHECK-FIXES: {{^ }}int var2 = 0;
+
+ void (S::*mdfp1)() = &S::f, (S::*mdfp2)() = &S::f;
+ // CHECK-MESSAGES: [[@LINE-1]]:5: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: void (S::*mdfp1)() = &S::f;
+ // CHECK-FIXES: {{^ }}void (S::*mdfp2)() = &S::f;
+
+ void (S::*mdfpa1[2])() = {&S::f, &S::f}, (S::*mdfpa2)() = &S::f;
+ // CHECK-MESSAGES: [[@LINE-1]]:5: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: void (S::*mdfpa1[2])() = {&S::f, &S::f};
+ // CHECK-FIXES: {{^ }}void (S::*mdfpa2)() = &S::f;
+
+ void (S::* * mdfpa3[2])() = {&mdfpa1[0], &mdfpa1[1]}, (S::*mdfpa4)() = &S::f;
+ // CHECK-MESSAGES: [[@LINE-1]]:5: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: void (S::* * mdfpa3[2])() = {&mdfpa1[0], &mdfpa1[1]};
+ // CHECK-FIXES: {{^ }}void (S::*mdfpa4)() = &S::f;
+ }
+
+ class CS {
+ public:
+ int a;
+ const int b;
+ };
+ int const CS ::*pp = &CS::a, CS::*const qq = &CS::a;
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: int const CS ::*pp = &CS::a;
+ // CHECK-FIXES: {{^ }}int const CS::*const qq = &CS::a;
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-isolate-declaration-no-infinite-loop.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-isolate-declaration-no-infinite-loop.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-isolate-declaration-no-infinite-loop.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-isolate-declaration-no-infinite-loop.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,7 @@
+// RUN: %check_clang_tidy -expect-clang-tidy-error %s readability-isolate-declaration %t
+
+int main(){
+ int a, b
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-MESSAGES: [[@LINE-2]]:11: error: expected ';' at end of declaration [clang-diagnostic-error]
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-isolate-declaration.c
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-isolate-declaration.c?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-isolate-declaration.c (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-isolate-declaration.c Fri Oct 11 05:05:42 2019
@@ -0,0 +1,13 @@
+// RUN: %check_clang_tidy %s readability-isolate-declaration %t
+
+void c_specific() {
+ void (*signal(int sig, void (*func)(int)))(int);
+ int i = sizeof(struct S { int i; });
+ int j = sizeof(struct T { int i; }), k;
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: int j = sizeof(struct T { int i; });
+ // CHECK-FIXES: {{^ }}int k;
+
+ void g(struct U { int i; } s); // One decl
+ void h(struct V { int i; } s), m(int i, ...); // Two decls
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-isolate-declaration.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-isolate-declaration.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-isolate-declaration.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-isolate-declaration.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,412 @@
+// RUN: %check_clang_tidy %s readability-isolate-declaration %t -- -- -fexceptions
+
+void f() {
+ int i;
+}
+
+void f2() {
+ int i, j, *k, lala = 42;
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: int i;
+ // CHECK-FIXES: {{^ }}int j;
+ // CHECK-FIXES: {{^ }}int *k;
+ // CHECK-FIXES: {{^ }}int lala = 42;
+
+ int normal, weird = /* comment */ 42;
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: int normal;
+ // CHECK-FIXES: {{^ }}int weird = /* comment */ 42;
+
+ int /* here is a comment */ v1,
+ // another comment
+ v2 = 42 // Ok, more comments
+ ;
+ // CHECK-MESSAGES: [[@LINE-4]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: int /* here is a comment */ v1;
+ // CHECK-FIXES: {{^ }}int /* here is a comment */ // another comment
+ // CHECK-FIXES: {{^ }}v2 = 42 // Ok, more comments
+ // CHECK-FIXES: {{^ }};
+
+ auto int1 = 42, int2 = 0, int3 = 43;
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: auto int1 = 42;
+ // CHECK-FIXES: {{^ }}auto int2 = 0;
+ // CHECK-FIXES: {{^ }}auto int3 = 43;
+
+ decltype(auto) ptr1 = &int1, ptr2 = &int1;
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: decltype(auto) ptr1 = &int1;
+ // CHECK-FIXES: {{^ }}decltype(auto) ptr2 = &int1;
+
+ decltype(k) ptr3 = &int1, ptr4 = &int1;
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: decltype(k) ptr3 = &int1;
+ // CHECK-FIXES: {{^ }}decltype(k) ptr4 = &int1;
+}
+
+void f3() {
+ int i, *pointer1;
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: int i;
+ // CHECK-FIXES: {{^ }}int *pointer1;
+ //
+ int *pointer2 = nullptr, *pointer3 = &i;
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: int *pointer2 = nullptr;
+ // CHECK-FIXES: {{^ }}int *pointer3 = &i;
+
+ int *(i_ptr) = nullptr, *((i_ptr2));
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: int *(i_ptr) = nullptr;
+ // CHECK-FIXES: {{^ }}int *((i_ptr2));
+
+ float(*f_ptr)[42], (((f_value))) = 42;
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: float (*f_ptr)[42];
+ // CHECK-FIXES: {{^ }}float (((f_value))) = 42;
+
+ float(((*f_ptr2)))[42], ((*f_ptr3)), f_value2 = 42.f;
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: float (((*f_ptr2)))[42];
+ // CHECK-FIXES: {{^ }}float ((*f_ptr3));
+ // CHECK-FIXES: {{^ }}float f_value2 = 42.f;
+
+ float(((*f_ptr4)))[42], *f_ptr5, ((f_value3));
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: float (((*f_ptr4)))[42];
+ // CHECK-FIXES: {{^ }}float *f_ptr5;
+ // CHECK-FIXES: {{^ }}float ((f_value3));
+
+ void(((*f2))(int)), (*g2)(int, float);
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: void (((*f2))(int));
+ // CHECK-FIXES: {{^ }}void (*g2)(int, float);
+
+ float(*(*(*f_ptr6)))[42], (*f_ptr7);
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: float (*(*(*f_ptr6)))[42];
+ // CHECK-FIXES: {{^ }}float (*f_ptr7);
+}
+
+void f4() {
+ double d = 42. /* foo */, z = 43., /* hi */ y, c /* */ /* */, l = 2.;
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: double d = 42. /* foo */;
+ // CHECK-FIXES: {{^ }}double z = 43.;
+ // CHECK-FIXES: {{^ }}double /* hi */ y;
+ // CHECK-FIXES: {{^ }}double c /* */ /* */;
+ // CHECK-FIXES: {{^ }}double l = 2.;
+}
+
+struct SomeClass {
+ SomeClass() = default;
+ SomeClass(int value);
+};
+
+class Point {
+ double x;
+ double y;
+
+public:
+ Point(double x, double y) : x(x), y(y) {}
+};
+
+class Rectangle {
+ Point TopLeft;
+ Point BottomRight;
+
+public:
+ Rectangle(Point TopLeft, Point BottomRight) : TopLeft(TopLeft), BottomRight(BottomRight) {}
+};
+
+void f5() {
+ SomeClass v1, v2(42), v3{42}, v4(42.5);
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: SomeClass v1;
+ // CHECK-FIXES: {{^ }}SomeClass v2(42);
+ // CHECK-FIXES: {{^ }}SomeClass v3{42};
+ // CHECK-FIXES: {{^ }}SomeClass v4(42.5);
+
+ SomeClass v5 = 42, *p1 = nullptr;
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: SomeClass v5 = 42;
+ // CHECK-FIXES: {{^ }}SomeClass *p1 = nullptr;
+
+ Point P1(0., 2.), P2{2., 0.};
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: Point P1(0., 2.);
+ // CHECK-FIXES: {{^ }}Point P2{2., 0.};
+
+ Rectangle R1({0., 0.}, {1., -2.}), R2{{0., 1.}, {1., 0.}}, R3(P1, P2), R4{P1, P2};
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: Rectangle R1({0., 0.}, {1., -2.});
+ // CHECK-FIXES: {{^ }}Rectangle R2{{[{][{]}}0., 1.}, {1., 0.{{[}][}]}};
+ // CHECK-FIXES: {{^ }}Rectangle R3(P1, P2);
+ // CHECK-FIXES: {{^ }}Rectangle R4{P1, P2};
+}
+
+void f6() {
+ int array1[] = {1, 2, 3, 4}, array2[] = {1, 2, 3}, value1, value2 = 42;
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: int array1[] = {1, 2, 3, 4};
+ // CHECK-FIXES: {{^ }}int array2[] = {1, 2, 3};
+ // CHECK-FIXES: {{^ }}int value1;
+ // CHECK-FIXES: {{^ }}int value2 = 42;
+}
+
+template <typename T>
+struct TemplatedType {
+ TemplatedType() = default;
+ TemplatedType(T value);
+};
+
+void f7() {
+ TemplatedType<int> TT1(42), TT2{42}, TT3;
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: TemplatedType<int> TT1(42);
+ // CHECK-FIXES: {{^ }}TemplatedType<int> TT2{42};
+ // CHECK-FIXES: {{^ }}TemplatedType<int> TT3;
+ //
+ TemplatedType<int *> *TT4(nullptr), TT5, **TT6 = nullptr, *const *const TT7{nullptr};
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: TemplatedType<int *> *TT4(nullptr);
+ // CHECK-FIXES: {{^ }}TemplatedType<int *> TT5;
+ // CHECK-FIXES: {{^ }}TemplatedType<int *> **TT6 = nullptr;
+ // CHECK-FIXES: {{^ }}TemplatedType<int *> *const *const TT7{nullptr};
+
+ TemplatedType<int &> **TT8(nullptr), *TT9;
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: TemplatedType<int &> **TT8(nullptr);
+ // CHECK-FIXES: {{^ }}TemplatedType<int &> *TT9;
+
+ TemplatedType<int *> TT10{nullptr}, *TT11(nullptr);
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: TemplatedType<int *> TT10{nullptr};
+ // CHECK-FIXES: {{^ }}TemplatedType<int *> *TT11(nullptr);
+}
+
+void forbidden_transformations() {
+ for (int i = 0, j = 42; i < j; ++i)
+ ;
+}
+
+#define NULL 0
+#define MY_NICE_TYPE int **
+#define VAR_NAME(name) name##__LINE__
+#define A_BUNCH_OF_VARIABLES int m1 = 42, m2 = 43, m3 = 44;
+
+void macros() {
+ int *p1 = NULL, *p2 = NULL;
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: int *p1 = NULL;
+ // CHECK-FIXES: {{^ }}int *p2 = NULL;
+
+ // Macros are involved, so there will be no transformation
+ MY_NICE_TYPE p3, v1, v2;
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+
+ int VAR_NAME(v3),
+ VAR_NAME(v4),
+ VAR_NAME(v5);
+ // CHECK-MESSAGES: [[@LINE-3]]:3: warning: multiple declarations in a single statement reduces readability
+
+ A_BUNCH_OF_VARIABLES
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+
+ int Unconditional,
+ // Explanatory comment.
+#if CONFIGURATION
+ IfConfigured = 42,
+#else
+ IfConfigured = 0;
+#endif
+ // CHECK-MESSAGES: [[@LINE-7]]:3: warning: multiple declarations in a single statement reduces readability
+}
+
+void dontTouchParameter(int param1, int param2) {}
+
+struct StructOne {
+ StructOne() {}
+ StructOne(int b) {}
+
+ int member1, member2;
+ // TODO: Handle FieldDecl's as well
+};
+
+using PointerType = int;
+
+struct {
+ int i;
+} AS1, AS2;
+struct TemT {
+ template <typename T>
+ T *getAs() {
+ return nullptr;
+ }
+} TT1, TT2;
+
+void complex_typedefs() {
+ typedef int *IntPtr;
+ typedef int ArrayType[2];
+ typedef int FunType(void);
+
+ IntPtr intptr1, intptr2 = nullptr, intptr3;
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: IntPtr intptr1;
+ // CHECK-FIXES: {{^ }}IntPtr intptr2 = nullptr;
+ // CHECK-FIXES: {{^ }}IntPtr intptr3;
+
+ IntPtr *DoublePtr1 = nullptr, **TriplePtr, SinglePtr = nullptr;
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: IntPtr *DoublePtr1 = nullptr;
+ // CHECK-FIXES: {{^ }}IntPtr **TriplePtr;
+ // CHECK-FIXES: {{^ }}IntPtr SinglePtr = nullptr;
+
+ IntPtr intptr_array1[2], intptr_array2[4] = {nullptr, nullptr, nullptr, nullptr};
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: IntPtr intptr_array1[2];
+ // CHECK-FIXES: {{^ }}IntPtr intptr_array2[4] = {nullptr, nullptr, nullptr, nullptr};
+
+ ArrayType arraytype1, arraytype2 = {1}, arraytype3;
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: ArrayType arraytype1;
+ // CHECK-FIXES: {{^ }}ArrayType arraytype2 = {1};
+ // CHECK-FIXES: {{^ }}ArrayType arraytype3;
+
+ // Don't touch function declarations.
+ FunType funtype1, funtype2, functype3;
+
+ for (int index1 = 0, index2 = 0;;) {
+ int localFor1 = 1, localFor2 = 2;
+ // CHECK-MESSAGES: [[@LINE-1]]:5: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: int localFor1 = 1;
+ // CHECK-FIXES: {{^ }}int localFor2 = 2;
+ }
+
+ StructOne s1, s2(23), s3, s4(3), *sptr = new StructOne(2);
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: StructOne s1;
+ // CHECK-FIXES: {{^ }}StructOne s2(23);
+ // CHECK-FIXES: {{^ }}StructOne s3;
+ // CHECK-FIXES: {{^ }}StructOne s4(3);
+ // CHECK-FIXES: {{^ }}StructOne *sptr = new StructOne(2);
+
+ struct StructOne cs1, cs2(42);
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: struct StructOne cs1;
+ // CHECK-FIXES: {{^ }}struct StructOne cs2(42);
+
+ int *ptrArray[3], dummy, **ptrArray2[5], twoDim[2][3], *twoDimPtr[2][3];
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: int *ptrArray[3];
+ // CHECK-FIXES: {{^ }}int dummy;
+ // CHECK-FIXES: {{^ }}int **ptrArray2[5];
+ // CHECK-FIXES: {{^ }}int twoDim[2][3];
+ // CHECK-FIXES: {{^ }}int *twoDimPtr[2][3];
+
+ {
+ void f1(int), g1(int, float);
+ }
+
+ {
+ void gg(int, float);
+
+ void (*f2)(int), (*g2)(int, float) = gg;
+ // CHECK-MESSAGES: [[@LINE-1]]:5: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: void (*f2)(int);
+ // CHECK-FIXES: {{^ }}void (*g2)(int, float) = gg;
+
+ void /*(*/ (/*(*/ *f3)(int), (*g3)(int, float);
+ // CHECK-MESSAGES: [[@LINE-1]]:5: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: void /*(*/ (/*(*/ *f3)(int);
+ // CHECK-FIXES: {{^ }}void /*(*/ (*g3)(int, float);
+ }
+
+ // clang-format off
+ auto returner = []() { return int(32); };
+ int intfunction = returner(), intarray[] =
+ {
+ 1,
+ 2,
+ 3,
+ 4
+ }, bb = 4;
+ // CHECK-MESSAGES: [[@LINE-7]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: int intfunction = returner();
+ // CHECK-FIXES: {{^ }}int intarray[] =
+ // CHECK-FIXES: {{^ }}{
+ // CHECK-FIXES: {{^ }}1,
+ // CHECK-FIXES: {{^ }}2,
+ // CHECK-FIXES: {{^ }}3,
+ // CHECK-FIXES: {{^ }}4
+ // CHECK-FIXES: {{^ }}};
+ // CHECK-FIXES: {{^ }}int bb = 4;
+ // clang-format on
+
+ TemT *T1 = &TT1, *T2 = &TT2;
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: TemT *T1 = &TT1;
+ // CHECK-FIXES: {{^ }}TemT *T2 = &TT2;
+
+ const PointerType *PT1 = T1->getAs<PointerType>(),
+ *PT2 = T2->getAs<PointerType>();
+ // CHECK-MESSAGES: [[@LINE-2]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: const PointerType *PT1 = T1->getAs<PointerType>();
+ // CHECK-FIXES: {{^ }}const PointerType *PT2 = T2->getAs<PointerType>();
+
+ const int *p1 = nullptr;
+ const int *p2 = nullptr;
+
+ const int *&pref1 = p1, *&pref2 = p2;
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: const int *&pref1 = p1;
+ // CHECK-FIXES: {{^ }}const int *&pref2 = p2;
+
+ // clang-format off
+ const char *literal1 = "clang" "test"\
+ "one",
+ *literal2 = "empty", literal3[] = "three";
+ // CHECK-MESSAGES: [[@LINE-3]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: const char *literal1 = "clang" "test"\
+ // CHECK-FIXES: {{^ }}"one";
+ // CHECK-FIXES: {{^ }}const char *literal2 = "empty";
+ // CHECK-FIXES: {{^ }}const char literal3[] = "three";
+ // clang-format on
+}
+
+void g() try {
+ int i, j;
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: int i;
+ // CHECK-FIXES: {{^ }}int j;
+} catch (...) {
+}
+
+struct S {
+ int a;
+ const int b;
+ void f() {}
+};
+
+void memberPointers() {
+ typedef const int S::*MemPtr;
+ MemPtr aaa = &S::a, bbb = &S::b;
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-FIXES: MemPtr aaa = &S::a;
+ // CHECK-FIXES: {{^ }}MemPtr bbb = &S::b;
+}
+
+typedef int *tptr, tbt;
+typedef int (&tfp)(int, long), tarr[10];
+typedef int tarr2[10], tct;
+
+template <typename A, typename B>
+void should_not_be_touched(A, B);
+
+int variable, function(void);
+
+int call_func_with_sideeffect();
+void bad_if_decl() {
+ if (true)
+ int i, j, k = call_func_with_sideeffect();
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-magic-numbers.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-magic-numbers.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-magic-numbers.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-magic-numbers.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,199 @@
+// RUN: %check_clang_tidy %s readability-magic-numbers %t \
+// RUN: -config='{CheckOptions: \
+// RUN: [{key: readability-magic-numbers.IgnoredIntegerValues, value: "0;1;2;10;100;"}, \
+// RUN: {key: readability-magic-numbers.IgnoredFloatingPointValues, value: "3.14;2.71828;9.81;10000.0;101.0;0x1.2p3"}, \
+// RUN: {key: readability-magic-numbers.IgnorePowersOf2IntegerValues, value: 1}]}' \
+// RUN: --
+
+template <typename T, int V>
+struct ValueBucket {
+ T value[V];
+};
+
+int BadGlobalInt = 5;
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: 5 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+
+int IntSquarer(int param) {
+ return param * param;
+}
+
+void BuggyFunction() {
+ int BadLocalInt = 6;
+ // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: 6 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+
+ (void)IntSquarer(7);
+ // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: 7 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+
+ int LocalArray[15];
+ // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 15 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+
+ for (int ii = 0; ii < 22; ++ii)
+ // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: 22 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+ {
+ LocalArray[ii] = 3 * ii;
+ // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: 3 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+ }
+
+ ValueBucket<int, 66> Bucket;
+ // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: 66 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+}
+
+class TwoIntContainer {
+public:
+ TwoIntContainer(int val) : anotherMember(val * val), yetAnotherMember(6), anotherConstant(val + val) {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:73: warning: 6 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+
+ int getValue() const;
+
+private:
+ int oneMember = 9;
+ // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: 9 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+
+ int anotherMember;
+
+ int yetAnotherMember;
+
+ const int oneConstant = 2;
+
+ const int anotherConstant;
+};
+
+int ValueArray[] = {3, 5};
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: 3 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+// CHECK-MESSAGES: :[[@LINE-2]]:24: warning: 5 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+
+float FloatPiVariable = 3.1415926535f;
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: 3.1415926535f is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+double DoublePiVariable = 6.283185307;
+// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: 6.283185307 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+
+float SomeFloats[] = {0.5, 0x1.2p4};
+// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: 0.5 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+// CHECK-MESSAGES: :[[@LINE-2]]:28: warning: 0x1.2p4 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+
+int getAnswer() {
+ if (ValueArray[0] < ValueArray[1])
+ return ValueArray[1];
+
+ return -3; // FILENOTFOUND
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: 3 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+}
+
+/*
+ * Clean code
+ */
+
+#define INT_MACRO 5
+
+const int GoodGlobalIntConstant = 42;
+
+constexpr int AlsoGoodGlobalIntConstant = 42;
+
+int InitializedByMacro = INT_MACRO;
+
+void SolidFunction() {
+ const int GoodLocalIntConstant = 43;
+
+ (void)IntSquarer(GoodLocalIntConstant);
+
+ int LocalArray[INT_MACRO];
+
+ ValueBucket<int, INT_MACRO> Bucket;
+}
+
+const int ConstValueArray[] = {7, 9};
+
+const int ConstValueArray2D[2][2] = {{7, 9}, {13, 15}};
+
+/*
+ * no warnings for ignored values (specified in the configuration above)
+ */
+int GrandfatheredIntegerValues[] = {0, 1, 2, 10, 100, -1, -10, -100, 65536};
+
+float GrandfatheredFloatValues[] = {3.14f, 3.14, 2.71828, 2.71828f, -1.01E2, 1E4, 0x1.2p3};
+
+/*
+ * no warnings for enums
+ */
+enum Smorgasbord {
+ STARTER,
+ ALPHA = 3,
+ BETA = 1 << 5,
+};
+
+const float FloatPiConstant = 3.1415926535f;
+const double DoublePiConstant = 6.283185307;
+
+const float Angles[] = {45.0f, 90.0f, 135.0f};
+
+double DoubleZeroIsAccepted = 0.0;
+float FloatZeroIsAccepted = 0.0f;
+
+namespace geometry {
+
+template <typename T>
+struct Point {
+ T x;
+ T y;
+
+ explicit Point(T xval, T yval) noexcept : x{xval}, y{yval} {
+ }
+};
+
+template <typename T>
+struct Dimension {
+ T x;
+ T y;
+
+ explicit Dimension(T xval, T yval) noexcept : x{xval}, y{yval} {
+ }
+};
+
+template <typename T>
+struct Rectangle {
+ Point<T> origin;
+ Dimension<T> size;
+ T rotation; // angle of rotation around origin
+
+ Rectangle(Point<T> origin_, Dimension<T> size_, T rotation_ = 0) noexcept : origin{origin_}, size{size_}, rotation{rotation_} {
+ }
+
+ bool contains(Point<T> point) const;
+};
+
+} // namespace geometry
+
+const geometry::Rectangle<double> mandelbrotCanvas{geometry::Point<double>{-2.5, -1}, geometry::Dimension<double>{3.5, 2}};
+
+// Simulate the macro magic in Google Test internal headers
+class AssertionHelper {
+public:
+ AssertionHelper(const char *Message, int LineNumber) : Message(Message), LineNumber(LineNumber) {}
+
+private:
+ const char *Message;
+ int LineNumber;
+};
+
+#define ASSERTION_HELPER_AT(M, L) AssertionHelper(M, L)
+
+#define ASSERTION_HELPER(M) ASSERTION_HELPER_AT(M, __LINE__)
+
+void FunctionWithCompilerDefinedSymbol(void) {
+ ASSERTION_HELPER("here and now");
+}
+
+// prove that integer literals introduced by the compiler are accepted silently
+extern int ConsumeString(const char *Input);
+
+const char *SomeStrings[] = {"alpha", "beta", "gamma"};
+
+int TestCheckerOverreach() {
+ int Total = 0;
+
+ for (const auto *Str : SomeStrings) {
+ Total += ConsumeString(Str);
+ }
+
+ return Total;
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-misleading-indentation.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-misleading-indentation.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-misleading-indentation.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-misleading-indentation.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,120 @@
+// RUN: %check_clang_tidy %s readability-misleading-indentation %t
+
+void foo1();
+void foo2();
+
+#define BLOCK \
+ if (cond1) \
+ foo1(); \
+ foo2();
+
+void f()
+{
+ bool cond1 = true;
+ bool cond2 = true;
+
+ if (cond1)
+ if (cond2)
+ foo1();
+ else
+ foo2();
+ // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: different indentation for 'if' and corresponding 'else' [readability-misleading-indentation]
+
+ if (cond1) {
+ if (cond2)
+ foo1();
+ }
+ else
+ foo2();
+
+ if (cond1)
+ if (cond2)
+ foo1();
+ else
+ foo2();
+
+ if (cond2)
+ foo1();
+ foo2();
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: misleading indentation: statement is indented too deeply [readability-misleading-indentation]
+ // CHECK-MESSAGES: :[[@LINE-4]]:3: note: did you mean this line to be inside this 'if'
+ foo2(); // No redundant warning.
+
+ if (cond1)
+ {
+ foo1();
+ }
+ foo2();
+
+ if (cond1)
+ foo1();
+ foo2();
+
+ if (cond2)
+ if (cond1) foo1(); else foo2();
+
+ if (cond1) {
+ } else {
+ }
+
+ if (cond1) {
+ }
+ else {
+ }
+
+ if (cond1)
+ {
+ }
+ else
+ {
+ }
+
+ if (cond1)
+ {
+ }
+ else
+ {
+ }
+
+ if(cond1) {
+ }
+ else if (cond2) {
+ }
+ else {
+ }
+
+ if(cond1) {
+ }
+ else if (cond2) {
+ }
+ else {
+ }
+ // CHECK-MESSAGES: :[[@LINE-2]]:8: warning: different indentation for 'if' and corresponding 'else' [readability-misleading-indentation]
+
+ if (cond1) {
+ if (cond1) {
+ }
+ else if (cond2) {
+ }
+ else {
+ }
+ if (cond1) {
+ } else if (cond2) {
+ } else if (!cond2) {
+ } else {
+ }
+ }
+ else if (cond2) {
+ }
+
+ BLOCK
+}
+
+void g(bool x) {
+ if (x)
+ #pragma unroll
+ for (int k = 0; k < 1; ++k) {}
+
+ #pragma unroll
+ for (int k = 0; k < 1; ++k) {}
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-misplaced-array-index.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-misplaced-array-index.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-misplaced-array-index.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-misplaced-array-index.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,34 @@
+// RUN: %check_clang_tidy %s readability-misplaced-array-index %t
+
+#define ABC "abc"
+
+struct XY { int *X; int *Y; };
+
+void dostuff(int);
+
+void unusualSyntax(int *P1, struct XY *P2) {
+ 10[P1] = 0;
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: confusing array subscript expression, usually the index is inside the []
+ // CHECK-FIXES: P1[10] = 0;
+
+ 10[P2->X] = 0;
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: confusing array subscript expression
+ // CHECK-FIXES: P2->X[10] = 0;
+
+ dostuff(1["abc"]);
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: confusing array subscript expression
+ // CHECK-FIXES: dostuff("abc"[1]);
+
+ dostuff(1[ABC]);
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: confusing array subscript expression
+ // CHECK-FIXES: dostuff(ABC[1]);
+
+ dostuff(0[0 + ABC]);
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: confusing array subscript expression
+ // CHECK-FIXES: dostuff(0[0 + ABC]);
+ // No fixit. Probably the code should be ABC[0]
+}
+
+void normalSyntax(int *X) {
+ X[10] = 0;
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-named-parameter.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-named-parameter.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-named-parameter.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-named-parameter.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,133 @@
+// RUN: %check_clang_tidy %s readability-named-parameter %t
+
+void Method(char *) { /* */ }
+// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: all parameters should be named in a function
+// CHECK-FIXES: void Method(char * /*unused*/) { /* */ }
+void Method2(char *) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: all parameters should be named in a function
+// CHECK-FIXES: void Method2(char * /*unused*/) {}
+void Method3(char *, void *) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: all parameters should be named in a function
+// CHECK-FIXES: void Method3(char * /*unused*/, void * /*unused*/) {}
+void Method4(char *, int /*unused*/) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: all parameters should be named in a function
+// CHECK-FIXES: void Method4(char * /*unused*/, int /*unused*/) {}
+void operator delete[](void *) throw() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: all parameters should be named in a function
+// CHECK-FIXES: void operator delete[](void * /*unused*/) throw() {}
+int Method5(int) { return 0; }
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: all parameters should be named in a function
+// CHECK-FIXES: int Method5(int /*unused*/) { return 0; }
+void Method6(void (*)(void *)) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: all parameters should be named in a function
+// CHECK-FIXES: void Method6(void (* /*unused*/)(void *)) {}
+template <typename T> void Method7(T) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:37: warning: all parameters should be named in a function
+// CHECK-FIXES: template <typename T> void Method7(T /*unused*/) {}
+
+// Don't warn in macros.
+#define M void MethodM(int) {}
+M
+
+void operator delete(void *x) throw() {}
+void Method7(char * /*x*/) {}
+void Method8(char *x) {}
+typedef void (*TypeM)(int x);
+void operator delete[](void *x) throw();
+void operator delete[](void * /*x*/) throw();
+
+struct X {
+ X operator++(int) {}
+ X operator--(int) {}
+
+ X(X&) = delete;
+ X &operator=(X&) = default;
+
+ const int &i;
+};
+
+void (*Func1)(void *);
+void Func2(void (*func)(void *)) {}
+template <void Func(void *)> void Func3() {}
+
+template <typename T>
+struct Y {
+ void foo(T) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: all parameters should be named in a function
+// CHECK-FIXES: void foo(T /*unused*/) {}
+};
+
+Y<int> y;
+Y<float> z;
+
+struct Base {
+ virtual void foo(bool notThisOne);
+ virtual void foo(int argname);
+};
+
+struct Derived : public Base {
+ void foo(int);
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: all parameters should be named in a function
+// CHECK-FIXES: void foo(int /*argname*/);
+};
+
+void FDef(int);
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: all parameters should be named in a function
+// CHECK-FIXES: void FDef(int /*n*/);
+void FDef(int n) {}
+
+void FDef2(int, int);
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: all parameters should be named in a function
+// CHECK-FIXES: void FDef2(int /*n*/, int /*unused*/);
+void FDef2(int n, int) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: all parameters should be named in a function
+// CHECK-FIXES: void FDef2(int n, int /*unused*/) {}
+
+void FNoDef(int);
+
+class Z {};
+
+Z &operator++(Z&) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: all parameters should be named in a function
+// CHECK-FIXES: Z &operator++(Z& /*unused*/) {}
+
+Z &operator++(Z&, int) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: all parameters should be named in a function
+// CHECK-FIXES: Z &operator++(Z& /*unused*/, int) {}
+
+Z &operator--(Z&) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: all parameters should be named in a function
+// CHECK-FIXES: Z &operator--(Z& /*unused*/) {}
+
+Z &operator--(Z&, int) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: all parameters should be named in a function
+// CHECK-FIXES: Z &operator--(Z& /*unused*/, int) {}
+
+namespace testing {
+namespace internal {
+class IgnoredValue {
+ public:
+ template <typename T>
+ IgnoredValue(const T& /* ignored */) {}
+};
+}
+typedef internal::IgnoredValue Unused;
+}
+
+using ::testing::Unused;
+
+void MockFunction(Unused, int q, Unused) {
+ ++q;
+ ++q;
+ ++q;
+}
+
+namespace std {
+typedef decltype(nullptr) nullptr_t;
+}
+
+void f(std::nullptr_t) {}
+
+typedef void (F)(int);
+F f;
+void f(int x) {}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-non-const-parameter.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-non-const-parameter.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-non-const-parameter.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-non-const-parameter.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,289 @@
+// RUN: %check_clang_tidy %s readability-non-const-parameter %t
+
+// Currently the checker only warns about pointer arguments.
+//
+// It can be defined both that the data is const and that the pointer is const,
+// the checker only checks if the data can be const-specified.
+//
+// It does not warn about pointers to records or function pointers.
+
+// Some external function where first argument is nonconst and second is const.
+char *strcpy1(char *dest, const char *src);
+unsigned my_strcpy(char *buf, const char *s);
+unsigned my_strlen(const char *buf);
+
+// CHECK-MESSAGES: :[[@LINE+1]]:29: warning: pointer parameter 'last' can be pointer to const [readability-non-const-parameter]
+void warn1(int *first, int *last) {
+ // CHECK-FIXES: {{^}}void warn1(int *first, const int *last) {{{$}}
+ *first = 0;
+ if (first < last) {
+ } // <- last can be const
+}
+
+// TODO: warning should be written here
+void warn2(char *p) {
+ char buf[10];
+ strcpy1(buf, p);
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:19: warning: pointer parameter 'p' can be
+void assign1(int *p) {
+ // CHECK-FIXES: {{^}}void assign1(const int *p) {{{$}}
+ const int *q;
+ q = p;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:19: warning: pointer parameter 'p' can be
+void assign2(int *p) {
+ // CHECK-FIXES: {{^}}void assign2(const int *p) {{{$}}
+ const int *q;
+ q = p + 1;
+}
+
+void assign3(int *p) {
+ *p = 0;
+}
+
+void assign4(int *p) {
+ *p += 2;
+}
+
+void assign5(char *p) {
+ p[0] = 0;
+}
+
+void assign6(int *p) {
+ int *q;
+ q = p++;
+}
+
+void assign7(char *p) {
+ char *a, *b;
+ a = b = p;
+}
+
+void assign8(char *a, char *b) {
+ char *x;
+ x = (a ? a : b);
+}
+
+void assign9(unsigned char *str, const unsigned int i) {
+ unsigned char *p;
+ for (p = str + i; *p;) {
+ }
+}
+
+void assign10(int *buf) {
+ int i, *p;
+ for (i = 0, p = buf; i < 10; i++, p++) {
+ *p = 1;
+ }
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:17: warning: pointer parameter 'p' can be
+void init1(int *p) {
+ // CHECK-FIXES: {{^}}void init1(const int *p) {{{$}}
+ const int *q = p;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:17: warning: pointer parameter 'p' can be
+void init2(int *p) {
+ // CHECK-FIXES: {{^}}void init2(const int *p) {{{$}}
+ const int *q = p + 1;
+}
+
+void init3(int *p) {
+ int *q = p;
+}
+
+void init4(float *p) {
+ int *q = (int *)p;
+}
+
+void init5(int *p) {
+ int *i = p ? p : 0;
+}
+
+void init6(int *p) {
+ int *a[] = {p, p, 0};
+}
+
+void init7(int *p, int x) {
+ for (int *q = p + x - 1; 0; q++)
+ ;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:18: warning: pointer parameter 'p' can be
+int return1(int *p) {
+ // CHECK-FIXES: {{^}}int return1(const int *p) {{{$}}
+ return *p;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:25: warning: pointer parameter 'p' can be
+const int *return2(int *p) {
+ // CHECK-FIXES: {{^}}const int *return2(const int *p) {{{$}}
+ return p;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:25: warning: pointer parameter 'p' can be
+const int *return3(int *p) {
+ // CHECK-FIXES: {{^}}const int *return3(const int *p) {{{$}}
+ return p + 1;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:27: warning: pointer parameter 'p' can be
+const char *return4(char *p) {
+ // CHECK-FIXES: {{^}}const char *return4(const char *p) {{{$}}
+ return p ? p : "";
+}
+
+char *return5(char *s) {
+ return s;
+}
+
+char *return6(char *s) {
+ return s + 1;
+}
+
+char *return7(char *a, char *b) {
+ return a ? a : b;
+}
+
+char return8(int *p) {
+ return ++(*p);
+}
+
+void dontwarn1(int *p) {
+ ++(*p);
+}
+
+void dontwarn2(int *p) {
+ (*p)++;
+}
+
+int dontwarn3(_Atomic(int) * p) {
+ return *p;
+}
+
+void callFunction1(char *p) {
+ strcpy1(p, "abc");
+}
+
+void callFunction2(char *p) {
+ strcpy1(&p[0], "abc");
+}
+
+void callFunction3(char *p) {
+ strcpy1(p + 2, "abc");
+}
+
+char *callFunction4(char *p) {
+ return strcpy1(p, "abc");
+}
+
+unsigned callFunction5(char *buf) {
+ unsigned len = my_strlen(buf);
+ return len + my_strcpy(buf, "abc");
+}
+
+void f6(int **p);
+void callFunction6(int *p) { f6(&p); }
+
+typedef union { void *v; } t;
+void f7(t obj);
+void callFunction7(int *p) {
+ f7((t){p});
+}
+
+void f8(int &x);
+void callFunction8(int *p) {
+ f8(*p);
+}
+
+// Don't warn about nonconst function pointers that can be const.
+void functionpointer(double f(double), int x) {
+ f(x);
+}
+
+// TODO: This is a false positive.
+// CHECK-MESSAGES: :[[@LINE+1]]:27: warning: pointer parameter 'p' can be
+int functionpointer2(int *p) {
+ return *p;
+}
+void use_functionpointer2() {
+ int (*fp)(int *) = functionpointer2; // <- the parameter 'p' can't be const
+}
+
+// Don't warn about nonconst record pointers that can be const.
+struct XY {
+ int *x;
+ int *y;
+};
+void recordpointer(struct XY *xy) {
+ *(xy->x) = 0;
+}
+
+class C {
+public:
+ C(int *p) : p(p) {}
+
+private:
+ int *p;
+};
+
+class C2 {
+public:
+ // CHECK-MESSAGES: :[[@LINE+1]]:11: warning: pointer parameter 'p' can be
+ C2(int *p) : p(p) {}
+ // CHECK-FIXES: {{^}} C2(const int *p) : p(p) {}{{$}}
+
+private:
+ const int *p;
+};
+
+void tempObject(int *p) {
+ C c(p);
+}
+
+// avoid fp for const pointer array
+void constPointerArray(const char *remapped[][2]) {
+ const char *name = remapped[0][0];
+}
+
+class Warn {
+public:
+ // CHECK-MESSAGES: :[[@LINE+1]]:21: warning: pointer parameter 'p' can be
+ void doStuff(int *p) {
+ // CHECK-FIXES: {{^}} void doStuff(const int *p) {{{$}}
+ x = *p;
+ }
+
+private:
+ int x;
+};
+
+class Base {
+public:
+ // Ensure there is no false positive for this method. It is virtual.
+ virtual void doStuff(int *p) {
+ int x = *p;
+ }
+};
+
+class Derived : public Base {
+public:
+ // Ensure there is no false positive for this method. It overrides a method.
+ void doStuff(int *p) override {
+ int x = *p;
+ }
+};
+
+extern char foo(char *s); // 1
+// CHECK-FIXES: {{^}}extern char foo(const char *s); // 1{{$}}
+// CHECK-MESSAGES: :[[@LINE+1]]:16: warning: pointer parameter 's' can be
+char foo(char *s) {
+ // CHECK-FIXES: {{^}}char foo(const char *s) {{{$}}
+ return *s;
+}
+char foo(char *s); // 2
+// CHECK-FIXES: {{^}}char foo(const char *s); // 2{{$}}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-control-flow.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-control-flow.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-control-flow.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-control-flow.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,224 @@
+// RUN: %check_clang_tidy %s readability-redundant-control-flow %t
+
+void g(int i);
+void j();
+
+void f() {
+ return;
+}
+// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: redundant return statement at the end of a function with a void return type [readability-redundant-control-flow]
+// CHECK-FIXES: {{^}}void f() {{{$}}
+// CHECK-FIXES-NEXT: {{^ *}$}}
+
+void g() {
+ f();
+ return;
+}
+// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: redundant return statement
+// CHECK-FIXES: {{^ }}f();{{$}}
+// CHECK-FIXES-NEXT: {{^ *}$}}
+
+void g(int i) {
+ if (i < 0) {
+ return;
+ }
+ if (i < 10) {
+ f();
+ }
+}
+
+int h() {
+ return 1;
+}
+
+void j() {
+}
+
+void k() {
+ for (int i = 0; i < 10; ++i) {
+ continue;
+ }
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: redundant continue statement at the end of loop statement
+// CHECK-FIXES: {{^}} for (int i = 0; i < 10; ++i) {{{$}}
+// CHECK-FIXES-NEXT: {{^ *}$}}
+
+void k2() {
+ int v[10] = { 0 };
+ for (auto i : v) {
+ continue;
+ }
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: redundant continue statement
+// CHECK-FIXES: {{^}} for (auto i : v) {{{$}}
+// CHECK-FIXES-NEXT: {{^ *}$}}
+
+void m() {
+ int i = 0;
+ do {
+ ++i;
+ continue;
+ } while (i < 10);
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: redundant continue statement
+// CHECK-FIXES: {{^ do {$}}
+// CHECK-FIXES-NEXT: {{^}} ++i;{{$}}
+// CHECK-FIXES-NEXT: {{^ *}}} while (i < 10);{{$}}
+
+void p() {
+ int i = 0;
+ while (i < 10) {
+ ++i;
+ continue;
+ }
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: redundant continue statement
+// CHECK-FIXES: {{^}} while (i < 10) {{{$}}
+// CHECK-FIXES-NEXT: {{^}} ++i;{{$}}
+// CHECK-FIXES-NEXT: {{^ *}$}}
+
+void im_not_dead(int i) {
+ if (i > 0) {
+ return;
+ }
+ g();
+}
+
+void im_still_not_dead(int i) {
+ for (int j = 0; j < 10; ++j) {
+ if (i < 10) {
+ continue;
+ }
+ g();
+ }
+}
+
+void im_dead(int i) {
+ if (i > 0) {
+ return;
+ g();
+ }
+ g();
+}
+
+void im_still_dead(int i) {
+ for (int j = 0; j < 10; ++j) {
+ if (i < 10) {
+ continue;
+ g();
+ }
+ g();
+ }
+}
+
+void void_return() {
+ return g();
+}
+
+void nested_return_unmolested() {
+ g();
+ {
+ g();
+ return;
+ }
+}
+
+void nested_continue_unmolested() {
+ for (int i = 0; i < 10; ++i) {
+ if (i < 5) {
+ continue;
+ }
+ }
+}
+
+#define MACRO_RETURN_UNMOLESTED(fn_) \
+ (fn_)(); \
+ return
+
+#define MACRO_CONTINUE_UNMOLESTED(x_) \
+ do { \
+ for (int i = 0; i < (x_); ++i) { \
+ continue; \
+ } \
+ } while (false)
+
+void macro_return() {
+ MACRO_RETURN_UNMOLESTED(g);
+}
+
+void macro_continue() {
+ MACRO_CONTINUE_UNMOLESTED(10);
+}
+
+#define MACRO_RETURN_ARG(stmt_) \
+ stmt_
+
+#define MACRO_CONTINUE_ARG(stmt_) \
+ do { \
+ for (int i = 0; i < 10; ++i) { \
+ stmt_; \
+ } \
+ } while (false)
+
+void macro_arg_return() {
+ MACRO_RETURN_ARG(return);
+}
+
+void macro_arg_continue() {
+ MACRO_CONTINUE_ARG(continue);
+}
+
+template <typename T>
+void template_return(T check) {
+ if (check < T(0)) {
+ return;
+ }
+ return;
+}
+// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: redundant return statement
+// CHECK-FIXES: {{^}} if (check < T(0)) {{{$}}
+// CHECK-FIXES-NEXT: {{^ return;$}}
+// CHECK-FIXES-NEXT: {{^ *}$}}
+// CHECK-FIXES-NEXT: {{^ *}$}}
+
+template <>
+void template_return(int check) {
+ if (check < 0) {
+ return;
+ }
+ return;
+}
+// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: redundant return statement
+// CHECK-FIXES: {{^}} if (check < 0) {{{$}}
+// CHECK-FIXES-NEXT: {{^ return;$}}
+// CHECK-FIXES-NEXT: {{^ *}$}}
+// CHECK-FIXES-NEXT: {{^ *}$}}
+
+template <typename T>
+void template_loop(T end) {
+ for (T i = 0; i < end; ++i) {
+ continue;
+ }
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: redundant continue statement
+// CHECK-FIXES: {{^}} for (T i = 0; i < end; ++i) {{{$}}
+// CHECK-FIXES-NEXT: {{^ *}$}}
+
+template <>
+void template_loop(int end) {
+ for (int i = 0; i < end; ++i) {
+ continue;
+ }
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: redundant continue statement
+// CHECK-FIXES: {{^}} for (int i = 0; i < end; ++i) {{{$}}
+// CHECK-FIXES-NEXT: {{^ *}$}}
+
+void call_templates() {
+ template_return(10);
+ template_return(10.0f);
+ template_return(10.0);
+ template_loop(10);
+ template_loop(10L);
+ template_loop(10U);
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-declaration-ignore-macros.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-declaration-ignore-macros.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-declaration-ignore-macros.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-declaration-ignore-macros.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,21 @@
+// RUN: %check_clang_tidy %s readability-redundant-declaration %t -- \
+// RUN: -config="{CheckOptions: \
+// RUN: [{key: readability-redundant-declaration.IgnoreMacros, \
+// RUN: value: 1}]}"
+
+extern int Xyz;
+extern int Xyz; // Xyz
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: redundant 'Xyz' declaration [readability-redundant-declaration]
+// CHECK-FIXES: {{^}}// Xyz{{$}}
+
+namespace macros {
+#define DECLARE(x) extern int x
+#define DEFINE(x) extern int x; int x = 42
+DECLARE(test);
+DEFINE(test);
+// CHECK-FIXES: {{^}}#define DECLARE(x) extern int x{{$}}
+// CHECK-FIXES: {{^}}#define DEFINE(x) extern int x; int x = 42{{$}}
+// CHECK-FIXES: {{^}}DECLARE(test);{{$}}
+// CHECK-FIXES: {{^}}DEFINE(test);{{$}}
+
+} // namespace macros
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-declaration.c
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-declaration.c?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-declaration.c (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-declaration.c Fri Oct 11 05:05:42 2019
@@ -0,0 +1,31 @@
+// RUN: %check_clang_tidy %s readability-redundant-declaration %t
+
+extern int Xyz;
+extern int Xyz; // Xyz
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: redundant 'Xyz' declaration [readability-redundant-declaration]
+// CHECK-FIXES: {{^}}// Xyz{{$}}
+int Xyz = 123;
+
+extern int A;
+extern int A, B;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: redundant 'A' declaration
+// CHECK-FIXES: {{^}}extern int A, B;{{$}}
+
+extern int Buf[10];
+extern int Buf[10]; // Buf[10]
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: redundant 'Buf' declaration
+// CHECK-FIXES: {{^}}// Buf[10]{{$}}
+
+static int f();
+static int f(); // f
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: redundant 'f' declaration
+// CHECK-FIXES: {{^}}// f{{$}}
+static int f() {}
+
+inline void g() {}
+
+inline void g();
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: redundant 'g' declaration
+
+// OK: Needed to emit an external definition.
+extern inline void g();
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-declaration.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-declaration.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-declaration.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-declaration.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,96 @@
+// RUN: %check_clang_tidy %s readability-redundant-declaration %t -- \
+// RUN: -config="{CheckOptions: \
+// RUN: [{key: readability-redundant-declaration.IgnoreMacros, \
+// RUN: value: 0}]}"
+//
+// With -fms-compatibility and -DEXTERNINLINE, the extern inline shouldn't
+// produce additional diagnostics, so same check suffix as before:
+// RUN: %check_clang_tidy %s readability-redundant-declaration %t -- \
+// RUN: -config="{CheckOptions: \
+// RUN: [{key: readability-redundant-declaration.IgnoreMacros, \
+// RUN: value: 0}]}" -- -fms-compatibility -DEXTERNINLINE
+//
+// With -fno-ms-compatiblity, DEXTERNINLINE causes additional output.
+// (The leading ',' means "default checks in addition to NOMSCOMPAT checks.)
+// RUN: %check_clang_tidy -check-suffix=,NOMSCOMPAT \
+// RUN: %s readability-redundant-declaration %t -- \
+// RUN: -config="{CheckOptions: \
+// RUN: [{key: readability-redundant-declaration.IgnoreMacros, \
+// RUN: value: 0}]}" -- -fno-ms-compatibility -DEXTERNINLINE
+
+extern int Xyz;
+extern int Xyz; // Xyz
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: redundant 'Xyz' declaration [readability-redundant-declaration]
+// CHECK-FIXES: {{^}}// Xyz{{$}}
+int Xyz = 123;
+
+extern int A;
+extern int A, B;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: redundant 'A' declaration
+// CHECK-FIXES: {{^}}extern int A, B;{{$}}
+
+extern int Buf[10];
+extern int Buf[10]; // Buf[10]
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: redundant 'Buf' declaration
+// CHECK-FIXES: {{^}}// Buf[10]{{$}}
+
+static int f();
+static int f(); // f
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: redundant 'f' declaration
+// CHECK-FIXES: {{^}}// f{{$}}
+static int f() {}
+
+// Original check crashed for the code below.
+namespace std {
+typedef decltype(sizeof(0)) size_t;
+}
+void *operator new(std::size_t) __attribute__((__externally_visible__));
+void *operator new[](std::size_t) __attribute__((__externally_visible__));
+
+// Don't warn about static member definition.
+struct C {
+ static int I;
+};
+int C::I;
+
+template <class T>
+struct C2 {
+ C2();
+};
+
+template <class T>
+C2<T>::C2() = default;
+
+void best_friend();
+
+struct Friendly {
+ friend void best_friend();
+ friend void enemy();
+};
+
+void enemy();
+
+namespace macros {
+#define DECLARE(x) extern int x
+#define DEFINE(x) extern int x; int x = 42
+DECLARE(test);
+DEFINE(test);
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant 'test' declaration
+// CHECK-FIXES: {{^}}#define DECLARE(x) extern int x{{$}}
+// CHECK-FIXES: {{^}}#define DEFINE(x) extern int x; int x = 42{{$}}
+// CHECK-FIXES: {{^}}DECLARE(test);{{$}}
+// CHECK-FIXES: {{^}}DEFINE(test);{{$}}
+
+} // namespace macros
+
+inline void g() {}
+
+inline void g(); // g
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: redundant 'g' declaration
+// CHECK-FIXES: {{^}}// g{{$}}
+
+#if defined(EXTERNINLINE)
+extern inline void g(); // extern g
+// CHECK-MESSAGES-NOMSCOMPAT: :[[@LINE-1]]:20: warning: redundant 'g' declaration
+// CHECK-FIXES-NOMSCOMPAT: {{^}}// extern g{{$}}
+#endif
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-function-ptr-dereference.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-function-ptr-dereference.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-function-ptr-dereference.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-function-ptr-dereference.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,45 @@
+// RUN: %check_clang_tidy %s readability-redundant-function-ptr-dereference %t
+
+void f(int i);
+
+void positive() {
+ void (*p)(int) = f;
+
+ (**p)(1);
+ // CHECK-MESSAGES: :[[@LINE-1]]:4: warning: redundant repeated dereference of function pointer [readability-redundant-function-ptr-dereference]
+ // CHECK-FIXES: (*p)(1);
+ (*****p)(2);
+ // CHECK-MESSAGES: :[[@LINE-1]]:4: warning: redundant repeated
+ // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: redundant repeated
+ // CHECK-MESSAGES: :[[@LINE-3]]:6: warning: redundant repeated
+ // CHECK-MESSAGES: :[[@LINE-4]]:7: warning: redundant repeated
+ // CHECK-FIXES: (*p)(2);
+}
+
+template<typename T>
+void invoke(const T& fn) {
+ fn(0); // 1
+ (*fn)(0); // 2
+ // CHECK-MESSAGES: :[[@LINE-1]]:4: warning: redundant repeated
+ // CHECK-FIXES: fn(0); // 1
+ // CHECK-FIXES: (fn)(0); // 2
+ // FIXME: Remove unnecessary parentheses.
+}
+
+void f1(int);
+void f2(double);
+void f3(char);
+
+void instantiate() {
+ invoke(f1);
+ invoke(f2);
+ invoke(f3);
+ invoke([](unsigned) {});
+}
+
+void negative() {
+ void (*q)(int) = &f;
+
+ q(1);
+ (*q)(2);
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-member-init.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-member-init.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-member-init.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-member-init.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,219 @@
+// RUN: %check_clang_tidy %s readability-redundant-member-init %t
+
+struct S {
+ S() = default;
+ S(int i) : i(i) {}
+ int i = 1;
+};
+
+struct T {
+ T(int i = 1) : i(i) {}
+ int i;
+};
+
+struct U {
+ int i;
+};
+
+union V {
+ int i;
+ double f;
+};
+
+// Initializer calls default constructor
+struct F1 {
+ F1() : f() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for member 'f' is redundant
+ // CHECK-FIXES: F1() {}
+ S f;
+};
+
+// Initializer calls default constructor with default argument
+struct F2 {
+ F2() : f() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for member 'f' is redundant
+ // CHECK-FIXES: F2() {}
+ T f;
+};
+
+// Multiple redundant initializers for same constructor
+struct F3 {
+ F3() : f(), g(1), h() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for member 'f' is redundant
+ // CHECK-MESSAGES: :[[@LINE-2]]:21: warning: initializer for member 'h' is redundant
+ // CHECK-FIXES: F3() : g(1) {}
+ S f, g, h;
+};
+
+// Templated class independent type
+template <class V>
+struct F4 {
+ F4() : f() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for member 'f' is redundant
+ // CHECK-FIXES: F4() {}
+ S f;
+};
+F4<int> f4i;
+F4<S> f4s;
+
+// Base class
+struct F5 : S {
+ F5() : S() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for base class 'S' is redundant
+ // CHECK-FIXES: F5() {}
+};
+
+// Constructor call requires cleanup
+struct Cleanup {
+ ~Cleanup() {}
+};
+
+struct UsesCleanup {
+ UsesCleanup(const Cleanup &c = Cleanup()) {}
+};
+
+struct F6 {
+ F6() : uc() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for member 'uc' is redundant
+ // CHECK-FIXES: F6() {}
+ UsesCleanup uc;
+};
+
+// Multiple inheritance
+struct F7 : S, T {
+ F7() : S(), T() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for base class 'S' is redundant
+ // CHECK-MESSAGES: :[[@LINE-2]]:15: warning: initializer for base class 'T' is redundant
+ // CHECK-FIXES: F7() {}
+};
+
+namespace Foo {
+inline namespace Bar {
+template <int N>
+struct Template {
+ Template() = default;
+ int i = N;
+};
+}
+}
+
+enum { N_THINGS = 5 };
+
+struct F8 : Foo::Template<N_THINGS> {
+ F8() : Template() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for base class 'Foo::Template<N_THINGS>' is redundant
+ // CHECK-FIXES: F8() {}
+};
+
+// Anonymous struct
+struct F9 {
+ F9() : s1() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: initializer for member 's1' is redundant
+ // CHECK-FIXES: F9() {}
+ struct {
+ S s1;
+ S s2;
+ };
+};
+
+// Initializer not written
+struct NF1 {
+ NF1() {}
+ S f;
+};
+
+// Initializer doesn't call default constructor
+struct NF2 {
+ NF2() : f(1) {}
+ S f;
+};
+
+// Initializer calls default constructor without using default argument
+struct NF3 {
+ NF3() : f(1) {}
+ T f;
+};
+
+// Initializer calls default constructor without using default argument
+struct NF4 {
+ NF4() : f(2) {}
+ T f;
+};
+
+// Initializer is zero-initialization
+struct NF5 {
+ NF5() : i() {}
+ int i;
+};
+
+// Initializer is direct-initialization
+struct NF6 {
+ NF6() : i(1) {}
+ int i;
+};
+
+// Initializer is aggregate initialization of struct
+struct NF7 {
+ NF7() : f{} {}
+ U f;
+};
+
+// Initializer is zero-initialization of struct
+struct NF7b {
+ NF7b() : f() {}
+ U f;
+};
+
+// Initializer is aggregate initialization of array
+struct NF8 {
+ NF8() : f{} {}
+ int f[2];
+};
+
+struct NF9 {
+ NF9() : f{} {}
+ S f[2];
+};
+
+// Initializing member of union
+union NF10 {
+ NF10() : s() {}
+ int i;
+ S s;
+};
+
+// Templated class dependent type
+template <class V>
+struct NF11 {
+ NF11() : f() {}
+ V f;
+};
+NF11<int> nf11i;
+NF11<S> nf11s;
+
+// Delegating constructor
+class NF12 {
+ NF12() = default;
+ NF12(int) : NF12() {}
+};
+
+// Const member
+struct NF13 {
+ NF13() : f() {}
+ const S f;
+};
+
+// Union member
+struct NF14 {
+ NF14() : f() {}
+ V f;
+};
+
+// Anonymous union member
+struct NF15 {
+ NF15() : s1() {}
+ union {
+ S s1;
+ S s2;
+ };
+};
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-preprocessor-ifdef.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-preprocessor-ifdef.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-preprocessor-ifdef.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-preprocessor-ifdef.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,36 @@
+// RUN: %check_clang_tidy %s readability-redundant-preprocessor %t -- -- -DFOO
+
+// Positive testing.
+#ifdef FOO
+// CHECK-NOTES: [[@LINE+1]]:2: warning: nested redundant #ifdef; consider removing it [readability-redundant-preprocessor]
+#ifdef FOO
+// CHECK-NOTES: [[@LINE-3]]:2: note: previous #ifdef was here
+void f();
+#endif
+#endif
+
+// Positive testing of inverted condition.
+#ifdef FOO
+// CHECK-NOTES: [[@LINE+1]]:2: warning: nested redundant #ifndef; consider removing it [readability-redundant-preprocessor]
+#ifndef FOO
+// CHECK-NOTES: [[@LINE-3]]:2: note: previous #ifdef was here
+void f2();
+#endif
+#endif
+
+// Negative testing.
+#ifdef BAR
+void g();
+#endif
+
+#ifdef FOO
+#ifdef BAR
+void h();
+#endif
+#endif
+
+#ifdef FOO
+#ifndef BAR
+void i();
+#endif
+#endif
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-preprocessor.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-preprocessor.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-preprocessor.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,84 @@
+// RUN: %check_clang_tidy %s readability-redundant-preprocessor %t -- -- -I %S
+
+// Positive testing.
+#ifndef FOO
+// CHECK-NOTES: [[@LINE+1]]:2: warning: nested redundant #ifndef; consider removing it [readability-redundant-preprocessor]
+#ifndef FOO
+// CHECK-NOTES: [[@LINE-3]]:2: note: previous #ifndef was here
+void f();
+#endif
+#endif
+
+// Positive testing of inverted condition.
+#ifndef FOO
+// CHECK-NOTES: [[@LINE+1]]:2: warning: nested redundant #ifdef; consider removing it [readability-redundant-preprocessor]
+#ifdef FOO
+// CHECK-NOTES: [[@LINE-3]]:2: note: previous #ifndef was here
+void f2();
+#endif
+#endif
+
+// Negative testing.
+#include "readability-redundant-preprocessor.h"
+
+#ifndef BAR
+void g();
+#endif
+
+#ifndef FOO
+#ifndef BAR
+void h();
+#endif
+#endif
+
+#ifndef FOO
+#ifdef BAR
+void i();
+#endif
+#endif
+
+// Positive #if testing.
+#define FOO 4
+
+#if FOO == 4
+// CHECK-NOTES: [[@LINE+1]]:2: warning: nested redundant #if; consider removing it [readability-redundant-preprocessor]
+#if FOO == 4
+// CHECK-NOTES: [[@LINE-3]]:2: note: previous #if was here
+void j();
+#endif
+#endif
+
+#if FOO == 3 + 1
+// CHECK-NOTES: [[@LINE+1]]:2: warning: nested redundant #if; consider removing it [readability-redundant-preprocessor]
+#if FOO == 3 + 1
+// CHECK-NOTES: [[@LINE-3]]:2: note: previous #if was here
+void j();
+#endif
+#endif
+
+#if FOO == \
+ 4
+// CHECK-NOTES: [[@LINE+1]]:2: warning: nested redundant #if; consider removing it [readability-redundant-preprocessor]
+#if FOO == \
+ 4
+// CHECK-NOTES: [[@LINE-5]]:2: note: previous #if was here
+void j();
+#endif
+#endif
+
+// Negative #if testing.
+#define BAR 4
+
+#if FOO == 4
+#if BAR == 4
+void k();
+#endif
+#endif
+
+#if FOO == \
+ 4
+#if BAR == \
+ 5
+void k();
+#endif
+#endif
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-preprocessor.h?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-preprocessor.h (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-preprocessor.h Fri Oct 11 05:05:42 2019
@@ -0,0 +1,5 @@
+#ifndef FOO
+#ifndef FOO // this would warn, but not in a header
+void f();
+#endif
+#endif
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-smartptr-get-macros.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-smartptr-get-macros.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-smartptr-get-macros.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-smartptr-get-macros.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,23 @@
+// RUN: %check_clang_tidy %s readability-redundant-smartptr-get %t -- \
+// RUN: -config="{CheckOptions: [{key: readability-redundant-smartptr-get.IgnoreMacros, value: 0}]}"
+
+namespace std {
+
+template <typename T>
+struct shared_ptr {
+ T &operator*() const;
+ T *operator->() const;
+ T *get() const;
+ explicit operator bool() const noexcept;
+};
+
+} // namespace std
+
+#define MACRO(p) p.get()
+
+void Positive() {
+ std::shared_ptr<int> x;
+ if (MACRO(x) == nullptr)
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:13: warning: redundant get() call on smart pointer
+};
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-smartptr-get-msvc.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-smartptr-get-msvc.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-smartptr-get-msvc.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-smartptr-get-msvc.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,94 @@
+// RUN: %check_clang_tidy %s readability-redundant-smartptr-get %t
+
+#define NULL __null
+
+namespace std {
+
+// MSVC headers define operator templates instead of plain operators.
+
+template <typename T>
+struct unique_ptr {
+ template <typename T2 = T>
+ T2& operator*() const;
+ template <typename T2 = T>
+ T2* operator->() const;
+ T* get() const;
+ explicit operator bool() const noexcept;
+};
+
+template <typename T>
+struct shared_ptr {
+ template <typename T2 = T>
+ T2& operator*() const;
+ template <typename T2 = T>
+ T2* operator->() const;
+ T* get() const;
+ explicit operator bool() const noexcept;
+};
+
+} // namespace std
+
+struct Bar {
+ void Do();
+ void ConstDo() const;
+};
+
+void Positive() {
+ std::unique_ptr<Bar>* up;
+ (*up->get()).Do();
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: redundant get() call
+ // CHECK-MESSAGES: (*up->get()).Do();
+ // CHECK-FIXES: (**up).Do();
+
+ std::unique_ptr<int> uu;
+ std::shared_ptr<double> *ss;
+ bool bb = uu.get() == nullptr;
+ // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: redundant get() call
+ // CHECK-MESSAGES: uu.get() == nullptr;
+ // CHECK-FIXES: bool bb = uu == nullptr;
+
+ if (up->get());
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant get() call
+ // CHECK-MESSAGES: if (up->get());
+ // CHECK-FIXES: if (*up);
+ if ((uu.get()));
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant get() call
+ // CHECK-MESSAGES: if ((uu.get()));
+ // CHECK-FIXES: if ((uu));
+ bb = !ss->get();
+ // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: redundant get() call
+ // CHECK-MESSAGES: bb = !ss->get();
+ // CHECK-FIXES: bb = !*ss;
+
+ bb = nullptr != ss->get();
+ // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: redundant get() call
+ // CHECK-MESSAGES: nullptr != ss->get();
+ // CHECK-FIXES: bb = nullptr != *ss;
+
+ bb = std::unique_ptr<int>().get() == NULL;
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant get() call
+ // CHECK-MESSAGES: bb = std::unique_ptr<int>().get() == NULL;
+ // CHECK-FIXES: bb = std::unique_ptr<int>() == NULL;
+ bb = ss->get() == NULL;
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant get() call
+ // CHECK-MESSAGES: bb = ss->get() == NULL;
+ // CHECK-FIXES: bb = *ss == NULL;
+
+ std::unique_ptr<int> x, y;
+ if (x.get() == nullptr);
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant get() call
+ // CHECK-MESSAGES: if (x.get() == nullptr);
+ // CHECK-FIXES: if (x == nullptr);
+ if (nullptr == y.get());
+ // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: redundant get() call
+ // CHECK-MESSAGES: if (nullptr == y.get());
+ // CHECK-FIXES: if (nullptr == y);
+ if (x.get() == NULL);
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant get() call
+ // CHECK-MESSAGES: if (x.get() == NULL);
+ // CHECK-FIXES: if (x == NULL);
+ if (NULL == x.get());
+ // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: redundant get() call
+ // CHECK-MESSAGES: if (NULL == x.get());
+ // CHECK-FIXES: if (NULL == x);
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-smartptr-get.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-smartptr-get.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-smartptr-get.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-smartptr-get.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,201 @@
+// RUN: %check_clang_tidy %s readability-redundant-smartptr-get %t
+
+#define NULL __null
+
+namespace std {
+
+template <typename T>
+struct unique_ptr {
+ T& operator*() const;
+ T* operator->() const;
+ T* get() const;
+ explicit operator bool() const noexcept;
+};
+
+template <typename T>
+struct shared_ptr {
+ T& operator*() const;
+ T* operator->() const;
+ T* get() const;
+ explicit operator bool() const noexcept;
+};
+
+} // namespace std
+
+struct Bar {
+ void Do();
+ void ConstDo() const;
+};
+struct BarPtr {
+ Bar* operator->();
+ Bar& operator*();
+ Bar* get();
+ explicit operator bool() const;
+};
+struct int_ptr {
+ int* get();
+ int* operator->();
+ int& operator*();
+};
+
+struct Fail1 {
+ Bar* get();
+};
+struct Fail2 {
+ Bar* get();
+ int* operator->();
+ int& operator*();
+};
+
+struct PointerWithOverloadedGet {
+ int* get();
+ template <typename T>
+ T* get();
+ int* operator->();
+ int& operator*();
+};
+
+void Positive() {
+ BarPtr u;
+ // CHECK-FIXES: BarPtr u;
+ BarPtr().get()->Do();
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: redundant get() call on smart pointer [readability-redundant-smartptr-get]
+ // CHECK-MESSAGES: BarPtr().get()->Do();
+ // CHECK-FIXES: BarPtr()->Do();
+
+ u.get()->ConstDo();
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: redundant get() call
+ // CHECK-MESSAGES: u.get()->ConstDo();
+ // CHECK-FIXES: u->ConstDo();
+
+ Bar& b = *BarPtr().get();
+ // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: redundant get() call
+ // CHECK-MESSAGES: Bar& b = *BarPtr().get();
+ // CHECK-FIXES: Bar& b = *BarPtr();
+
+ Bar& b2 = *std::unique_ptr<Bar>().get();
+ // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: redundant get() call
+ // CHECK-MESSAGES: Bar& b2 = *std::unique_ptr<Bar>().get();
+ // CHECK-FIXES: Bar& b2 = *std::unique_ptr<Bar>();
+
+ (*BarPtr().get()).ConstDo();
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: redundant get() call
+ // CHECK-MESSAGES: (*BarPtr().get()).ConstDo();
+ // CHECK-FIXES: (*BarPtr()).ConstDo();
+
+ (*std::unique_ptr<Bar>().get()).ConstDo();
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: redundant get() call
+ // CHECK-MESSAGES: (*std::unique_ptr<Bar>().get()).ConstDo();
+ // CHECK-FIXES: (*std::unique_ptr<Bar>()).ConstDo();
+
+ std::unique_ptr<Bar>* up;
+ (*up->get()).Do();
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: redundant get() call
+ // CHECK-MESSAGES: (*up->get()).Do();
+ // CHECK-FIXES: (**up).Do();
+
+ int_ptr ip;
+ int i = *ip.get();
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: redundant get() call
+ // CHECK-MESSAGES: int i = *ip.get();
+ // CHECK-FIXES: int i = *ip;
+
+ auto ip2 = ip;
+ i = *ip2.get();
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant get() call
+ // CHECK-MESSAGES: i = *ip2.get();
+ // CHECK-FIXES: i = *ip2;
+
+ std::unique_ptr<int> uu;
+ std::shared_ptr<double> *ss;
+ bool bb = uu.get() == nullptr;
+ // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: redundant get() call
+ // CHECK-MESSAGES: uu.get() == nullptr;
+ // CHECK-FIXES: bool bb = uu == nullptr;
+
+ if (up->get());
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant get() call
+ // CHECK-MESSAGES: if (up->get());
+ // CHECK-FIXES: if (*up);
+ if ((uu.get()));
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant get() call
+ // CHECK-MESSAGES: if ((uu.get()));
+ // CHECK-FIXES: if ((uu));
+ bb = !ss->get();
+ // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: redundant get() call
+ // CHECK-MESSAGES: bb = !ss->get();
+ // CHECK-FIXES: bb = !*ss;
+ bb = u.get() ? true : false;
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant get() call
+ // CHECK-MESSAGES: bb = u.get() ? true : false;
+ // CHECK-FIXES: bb = u ? true : false;
+
+ bb = nullptr != ss->get();
+ // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: redundant get() call
+ // CHECK-MESSAGES: nullptr != ss->get();
+ // CHECK-FIXES: bb = nullptr != *ss;
+
+ i = *PointerWithOverloadedGet().get();
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant get() call
+ // CHECK-MESSAGES: i = *PointerWithOverloadedGet().get();
+ // CHECK-FIXES: i = *PointerWithOverloadedGet();
+
+ bb = std::unique_ptr<int>().get() == NULL;
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant get() call
+ // CHECK-MESSAGES: bb = std::unique_ptr<int>().get() == NULL;
+ // CHECK-FIXES: bb = std::unique_ptr<int>() == NULL;
+ bb = ss->get() == NULL;
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant get() call
+ // CHECK-MESSAGES: bb = ss->get() == NULL;
+ // CHECK-FIXES: bb = *ss == NULL;
+
+ std::unique_ptr<int> x, y;
+ if (x.get() == nullptr);
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant get() call
+ // CHECK-MESSAGES: if (x.get() == nullptr);
+ // CHECK-FIXES: if (x == nullptr);
+ if (nullptr == y.get());
+ // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: redundant get() call
+ // CHECK-MESSAGES: if (nullptr == y.get());
+ // CHECK-FIXES: if (nullptr == y);
+ if (x.get() == NULL);
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant get() call
+ // CHECK-MESSAGES: if (x.get() == NULL);
+ // CHECK-FIXES: if (x == NULL);
+ if (NULL == x.get());
+ // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: redundant get() call
+ // CHECK-MESSAGES: if (NULL == x.get());
+ // CHECK-FIXES: if (NULL == x);
+}
+
+#define MACRO(p) p.get()
+
+void Negative() {
+ struct NegPtr {
+ int* get();
+ int* operator->() {
+ return &*this->get();
+ }
+ int& operator*() {
+ return *get();
+ }
+ };
+
+ long l = *PointerWithOverloadedGet().get<long>();
+
+ std::unique_ptr<Bar>* u;
+ u->get()->Do();
+
+ Fail1().get()->Do();
+ Fail2().get()->Do();
+ const Bar& b = *Fail1().get();
+ (*Fail2().get()).Do();
+
+ int_ptr ip;
+ bool bb = ip.get() == nullptr;
+ bb = !ip.get();
+ bb = ip.get() ? true : false;
+ std::unique_ptr<int> x;
+ if (MACRO(x) == nullptr)
+ ;
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-string-cstr-msvc.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-string-cstr-msvc.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-string-cstr-msvc.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-string-cstr-msvc.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,47 @@
+// RUN: %check_clang_tidy %s readability-redundant-string-cstr %t
+
+namespace std {
+template <typename T>
+class allocator {};
+template <typename T>
+class char_traits {};
+template <typename C, typename T, typename A>
+struct basic_string {
+ basic_string();
+ // MSVC headers define two constructors instead of using optional arguments.
+ basic_string(const C *p);
+ basic_string(const C *p, const A &a);
+ const C *c_str() const;
+ const C *data() const;
+};
+typedef basic_string<char, std::char_traits<char>, std::allocator<char>> string;
+}
+namespace llvm {
+struct StringRef {
+ StringRef(const char *p);
+ StringRef(const std::string &);
+};
+}
+
+void f1(const std::string &s) {
+ f1(s.c_str());
+ // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+ // CHECK-FIXES: {{^ }}f1(s);{{$}}
+ f1(s.data());
+ // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'data' [readability-redundant-string-cstr]
+ // CHECK-FIXES: {{^ }}f1(s);{{$}}
+}
+void f2(const llvm::StringRef r) {
+ std::string s;
+ f2(s.c_str());
+ // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call {{.*}}
+ // CHECK-FIXES: {{^ }}std::string s;{{$}}
+ // CHECK-FIXES-NEXT: {{^ }}f2(s);{{$}}
+}
+void f3(const llvm::StringRef &r) {
+ std::string s;
+ f3(s.c_str());
+ // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call {{.*}}
+ // CHECK-FIXES: {{^ }}std::string s;{{$}}
+ // CHECK-FIXES-NEXT: {{^ }}f3(s);{{$}}
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-string-cstr.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-string-cstr.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-string-cstr.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-string-cstr.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,207 @@
+// RUN: %check_clang_tidy %s readability-redundant-string-cstr %t
+
+typedef unsigned __INT16_TYPE__ char16;
+typedef unsigned __INT32_TYPE__ char32;
+typedef __SIZE_TYPE__ size;
+
+namespace std {
+template <typename T>
+class allocator {};
+template <typename T>
+class char_traits {};
+template <typename C, typename T, typename A>
+struct basic_string {
+ typedef basic_string<C, T, A> _Type;
+ basic_string();
+ basic_string(const C *p, const A &a = A());
+
+ const C *c_str() const;
+ const C *data() const;
+
+ _Type& append(const C *s);
+ _Type& append(const C *s, size n);
+ _Type& assign(const C *s);
+ _Type& assign(const C *s, size n);
+
+ int compare(const _Type&) const;
+ int compare(const C* s) const;
+ int compare(size pos, size len, const _Type&) const;
+ int compare(size pos, size len, const C* s) const;
+
+ size find(const _Type& str, size pos = 0) const;
+ size find(const C* s, size pos = 0) const;
+ size find(const C* s, size pos, size n) const;
+
+ _Type& insert(size pos, const _Type& str);
+ _Type& insert(size pos, const C* s);
+ _Type& insert(size pos, const C* s, size n);
+
+ _Type& operator+=(const _Type& str);
+ _Type& operator+=(const C* s);
+ _Type& operator=(const _Type& str);
+ _Type& operator=(const C* s);
+};
+
+typedef basic_string<char, std::char_traits<char>, std::allocator<char>> string;
+typedef basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t>> wstring;
+typedef basic_string<char16, std::char_traits<char16>, std::allocator<char16>> u16string;
+typedef basic_string<char32, std::char_traits<char32>, std::allocator<char32>> u32string;
+}
+
+std::string operator+(const std::string&, const std::string&);
+std::string operator+(const std::string&, const char*);
+std::string operator+(const char*, const std::string&);
+
+bool operator==(const std::string&, const std::string&);
+bool operator==(const std::string&, const char*);
+bool operator==(const char*, const std::string&);
+
+namespace llvm {
+struct StringRef {
+ StringRef(const char *p);
+ StringRef(const std::string &);
+};
+}
+
+// Tests for std::string.
+
+void f1(const std::string &s) {
+ f1(s.c_str());
+ // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+ // CHECK-FIXES: {{^ }}f1(s);{{$}}
+ f1(s.data());
+ // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'data' [readability-redundant-string-cstr]
+ // CHECK-FIXES: {{^ }}f1(s);{{$}}
+}
+void f2(const llvm::StringRef r) {
+ std::string s;
+ f2(s.c_str());
+ // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call {{.*}}
+ // CHECK-FIXES: {{^ }}std::string s;{{$}}
+ // CHECK-FIXES-NEXT: {{^ }}f2(s);{{$}}
+}
+void f3(const llvm::StringRef &r) {
+ std::string s;
+ f3(s.c_str());
+ // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call {{.*}}
+ // CHECK-FIXES: {{^ }}std::string s;{{$}}
+ // CHECK-FIXES-NEXT: {{^ }}f3(s);{{$}}
+}
+void f4(const std::string &s) {
+ const std::string* ptr = &s;
+ f1(ptr->c_str());
+ // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+ // CHECK-FIXES: {{^ }}f1(*ptr);{{$}}
+}
+void f5(const std::string &s) {
+ std::string tmp;
+ tmp.append(s.c_str());
+ // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: redundant call {{.*}}
+ // CHECK-FIXES: {{^ }}tmp.append(s);{{$}}
+ tmp.assign(s.c_str());
+ // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: redundant call {{.*}}
+ // CHECK-FIXES: {{^ }}tmp.assign(s);{{$}}
+
+ if (tmp.compare(s.c_str()) == 0) return;
+ // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: redundant call {{.*}}
+ // CHECK-FIXES: {{^ }}if (tmp.compare(s) == 0) return;{{$}}
+
+ if (tmp.compare(1, 2, s.c_str()) == 0) return;
+ // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: redundant call {{.*}}
+ // CHECK-FIXES: {{^ }}if (tmp.compare(1, 2, s) == 0) return;{{$}}
+
+ if (tmp.find(s.c_str()) == 0) return;
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: redundant call {{.*}}
+ // CHECK-FIXES: {{^ }}if (tmp.find(s) == 0) return;{{$}}
+
+ if (tmp.find(s.c_str(), 2) == 0) return;
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: redundant call {{.*}}
+ // CHECK-FIXES: {{^ }}if (tmp.find(s, 2) == 0) return;{{$}}
+
+ if (tmp.find(s.c_str(), 2) == 0) return;
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: redundant call {{.*}}
+ // CHECK-FIXES: {{^ }}if (tmp.find(s, 2) == 0) return;{{$}}
+
+ tmp.insert(1, s.c_str());
+ // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: redundant call {{.*}}
+ // CHECK-FIXES: {{^ }}tmp.insert(1, s);{{$}}
+
+ tmp = s.c_str();
+ // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: redundant call {{.*}}
+ // CHECK-FIXES: {{^ }}tmp = s;{{$}}
+
+ tmp += s.c_str();
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: redundant call {{.*}}
+ // CHECK-FIXES: {{^ }}tmp += s;{{$}}
+
+ if (tmp == s.c_str()) return;
+ // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: redundant call {{.*}}
+ // CHECK-FIXES: {{^ }}if (tmp == s) return;{{$}}
+
+ tmp = s + s.c_str();
+ // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: redundant call {{.*}}
+ // CHECK-FIXES: {{^ }}tmp = s + s;{{$}}
+
+ tmp = s.c_str() + s;
+ // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: redundant call {{.*}}
+ // CHECK-FIXES: {{^ }}tmp = s + s;{{$}}
+}
+void f6(const std::string &s) {
+ std::string tmp;
+ tmp.append(s.c_str(), 2);
+ tmp.assign(s.c_str(), 2);
+
+ if (tmp.compare(s) == 0) return;
+ if (tmp.compare(1, 2, s) == 0) return;
+
+ tmp = s;
+ tmp += s;
+
+ if (tmp == s)
+ return;
+
+ tmp = s + s;
+
+ if (tmp.find(s.c_str(), 2, 4) == 0) return;
+
+ tmp.insert(1, s);
+ tmp.insert(1, s.c_str(), 2);
+}
+
+// Tests for std::wstring.
+
+void g1(const std::wstring &s) {
+ g1(s.c_str());
+ // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+ // CHECK-FIXES: {{^ }}g1(s);{{$}}
+}
+
+// Tests for std::u16string.
+
+void h1(const std::u16string &s) {
+ h1(s.c_str());
+ // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+ // CHECK-FIXES: {{^ }}h1(s);{{$}}
+}
+
+// Tests for std::u32string.
+
+void k1(const std::u32string &s) {
+ k1(s.c_str());
+ // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+ // CHECK-FIXES: {{^ }}k1(s);{{$}}
+}
+
+// Tests on similar classes that aren't good candidates for this checker.
+
+struct NotAString {
+ NotAString();
+ NotAString(const NotAString&);
+ const char *c_str() const;
+};
+
+void dummy(const char*) {}
+
+void invalid(const NotAString &s) {
+ dummy(s.c_str());
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-string-init-msvc.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-string-init-msvc.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-string-init-msvc.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-string-init-msvc.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,62 @@
+// RUN: %check_clang_tidy -std=c++11,c++14 %s readability-redundant-string-init %t
+// FIXME: Fix the checker to work in C++17 mode.
+
+namespace std {
+template <typename T>
+class allocator {};
+template <typename T>
+class char_traits {};
+template <typename C, typename T = std::char_traits<C>, typename A = std::allocator<C>>
+struct basic_string {
+ basic_string();
+ basic_string(const basic_string&);
+ // MSVC headers define two constructors instead of using optional arguments.
+ basic_string(const C *);
+ basic_string(const C *, const A &);
+ ~basic_string();
+};
+typedef basic_string<char> string;
+typedef basic_string<wchar_t> wstring;
+}
+
+void f() {
+ std::string a = "";
+ // CHECK-MESSAGES: [[@LINE-1]]:15: warning: redundant string initialization [readability-redundant-string-init]
+ // CHECK-FIXES: std::string a;
+ std::string b("");
+ // CHECK-MESSAGES: [[@LINE-1]]:15: warning: redundant string initialization
+ // CHECK-FIXES: std::string b;
+ std::string c = R"()";
+ // CHECK-MESSAGES: [[@LINE-1]]:15: warning: redundant string initialization
+ // CHECK-FIXES: std::string c;
+ std::string d(R"()");
+ // CHECK-MESSAGES: [[@LINE-1]]:15: warning: redundant string initialization
+ // CHECK-FIXES: std::string d;
+
+ std::string u = "u";
+ std::string w("w");
+ std::string x = R"(x)";
+ std::string y(R"(y)");
+ std::string z;
+}
+
+void g() {
+ std::wstring a = L"";
+ // CHECK-MESSAGES: [[@LINE-1]]:16: warning: redundant string initialization
+ // CHECK-FIXES: std::wstring a;
+ std::wstring b(L"");
+ // CHECK-MESSAGES: [[@LINE-1]]:16: warning: redundant string initialization
+ // CHECK-FIXES: std::wstring b;
+ std::wstring c = LR"()";
+ // CHECK-MESSAGES: [[@LINE-1]]:16: warning: redundant string initialization
+ // CHECK-FIXES: std::wstring c;
+ std::wstring d(LR"()");
+ // CHECK-MESSAGES: [[@LINE-1]]:16: warning: redundant string initialization
+ // CHECK-FIXES: std::wstring d;
+
+ std::wstring u = L"u";
+ std::wstring w(L"w");
+ std::wstring x = LR"(x)";
+ std::wstring y(LR"(y)");
+ std::wstring z;
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-string-init.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-string-init.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-string-init.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-redundant-string-init.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,141 @@
+// RUN: %check_clang_tidy -std=c++11,c++14 %s readability-redundant-string-init %t
+// FIXME: Fix the checker to work in C++17 mode.
+
+namespace std {
+template <typename T>
+class allocator {};
+template <typename T>
+class char_traits {};
+template <typename C, typename T = std::char_traits<C>, typename A = std::allocator<C>>
+struct basic_string {
+ basic_string();
+ basic_string(const basic_string&);
+ basic_string(const C *, const A &a = A());
+ ~basic_string();
+};
+typedef basic_string<char> string;
+typedef basic_string<wchar_t> wstring;
+}
+
+void f() {
+ std::string a = "";
+ // CHECK-MESSAGES: [[@LINE-1]]:15: warning: redundant string initialization [readability-redundant-string-init]
+ // CHECK-FIXES: std::string a;
+ std::string b("");
+ // CHECK-MESSAGES: [[@LINE-1]]:15: warning: redundant string initialization
+ // CHECK-FIXES: std::string b;
+ std::string c = R"()";
+ // CHECK-MESSAGES: [[@LINE-1]]:15: warning: redundant string initialization
+ // CHECK-FIXES: std::string c;
+ std::string d(R"()");
+ // CHECK-MESSAGES: [[@LINE-1]]:15: warning: redundant string initialization
+ // CHECK-FIXES: std::string d;
+
+ std::string u = "u";
+ std::string w("w");
+ std::string x = R"(x)";
+ std::string y(R"(y)");
+ std::string z;
+}
+
+void g() {
+ std::wstring a = L"";
+ // CHECK-MESSAGES: [[@LINE-1]]:16: warning: redundant string initialization
+ // CHECK-FIXES: std::wstring a;
+ std::wstring b(L"");
+ // CHECK-MESSAGES: [[@LINE-1]]:16: warning: redundant string initialization
+ // CHECK-FIXES: std::wstring b;
+ std::wstring c = LR"()";
+ // CHECK-MESSAGES: [[@LINE-1]]:16: warning: redundant string initialization
+ // CHECK-FIXES: std::wstring c;
+ std::wstring d(LR"()");
+ // CHECK-MESSAGES: [[@LINE-1]]:16: warning: redundant string initialization
+ // CHECK-FIXES: std::wstring d;
+
+ std::wstring u = L"u";
+ std::wstring w(L"w");
+ std::wstring x = LR"(x)";
+ std::wstring y(LR"(y)");
+ std::wstring z;
+}
+
+template <typename T>
+void templ() {
+ std::string s = "";
+ // CHECK-MESSAGES: [[@LINE-1]]:15: warning: redundant string initialization
+ // CHECK-FIXES: std::string s;
+}
+
+#define M(x) x
+#define N { std::string s = ""; }
+// CHECK-FIXES: #define N { std::string s = ""; }
+
+void h() {
+ templ<int>();
+ templ<double>();
+
+ M({ std::string s = ""; })
+ // CHECK-MESSAGES: [[@LINE-1]]:19: warning: redundant string initialization
+ // CHECK-FIXES: M({ std::string s; })
+
+ N
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: redundant string initialization
+ // CHECK-FIXES: N
+ N
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: redundant string initialization
+ // CHECK-FIXES: N
+}
+
+typedef std::string MyString;
+#define STRING MyString
+#define DECL_STRING(name, val) STRING name = val
+
+void i() {
+ MyString a = "";
+ // CHECK-MESSAGES: [[@LINE-1]]:12: warning: redundant string initialization
+ // CHECK-FIXES: MyString a;
+ STRING b = "";
+ // CHECK-MESSAGES: [[@LINE-1]]:10: warning: redundant string initialization
+ // CHECK-FIXES: STRING b;
+ MyString c = "" "" "";
+ // CHECK-MESSAGES: [[@LINE-1]]:12: warning: redundant string initialization
+ // CHECK-FIXES: MyString c;
+ STRING d = "" "" "";
+ // CHECK-MESSAGES: [[@LINE-1]]:10: warning: redundant string initialization
+ // CHECK-FIXES: STRING d;
+ DECL_STRING(e, "");
+ // CHECK-MESSAGES: [[@LINE-1]]:15: warning: redundant string initialization
+
+ MyString f = "u";
+ STRING g = "u";
+ DECL_STRING(h, "u");
+}
+
+#define EMPTY_STR ""
+void j() {
+ std::string a(EMPTY_STR);
+ // CHECK-MESSAGES: [[@LINE-1]]:15: warning: redundant string initialization
+ // CHECK-FIXES: std::string a;
+ std::string b = (EMPTY_STR);
+ // CHECK-MESSAGES: [[@LINE-1]]:15: warning: redundant string initialization
+ // CHECK-FIXES: std::string b;
+
+ std::string c(EMPTY_STR "u" EMPTY_STR);
+}
+
+void k() {
+ std::string a = "", b = "", c = "";
+ // CHECK-MESSAGES: [[@LINE-1]]:15: warning: redundant string initialization
+ // CHECK-MESSAGES: [[@LINE-2]]:23: warning: redundant string initialization
+ // CHECK-MESSAGES: [[@LINE-3]]:31: warning: redundant string initialization
+ // CHECK-FIXES: std::string a, b, c;
+
+ std::string d = "u", e = "u", f = "u";
+}
+
+// These cases should not generate warnings.
+extern void Param1(std::string param = "");
+extern void Param2(const std::string& param = "");
+void Param3(std::string param = "") {}
+void Param4(STRING param = "") {}
+
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,34 @@
+// RUN: %check_clang_tidy %s readability-simplify-boolean-expr %t -- -config="{CheckOptions: [{key: "readability-simplify-boolean-expr.ChainedConditionalAssignment", value: 1}]}" --
+
+void chained_conditional_compound_assignment(int i) {
+ bool b;
+ if (i < 0) {
+ b = true;
+ } else if (i < 10) {
+ b = false;
+ } else if (i > 20) {
+ b = true;
+ } else {
+ b = false;
+ }
+ // CHECK-MESSAGES: :[[@LINE-4]]:9: warning: redundant boolean literal in conditional assignment [readability-simplify-boolean-expr]
+ // CHECK-FIXES: {{^}} } else if (i < 10) {{{$}}
+ // CHECK-FIXES-NEXT: {{^}} b = false;{{$}}
+ // CHECK-FIXES-NEXT: {{^}} } else b = i > 20;{{$}}
+}
+
+void chained_conditional_assignment(int i) {
+ bool b;
+ if (i < 0)
+ b = true;
+ else if (i < 10)
+ b = false;
+ else if (i > 20)
+ b = true;
+ else
+ b = false;
+ // CHECK-MESSAGES: :[[@LINE-3]]:9: warning: {{.*}} in conditional assignment
+ // CHECK-FIXES: {{^}} else if (i < 10)
+ // CHECK-FIXES-NEXT: {{^}} b = false;
+ // CHECK-FIXES-NEXT: {{^}} else b = i > 20;
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,94 @@
+// RUN: %check_clang_tidy %s readability-simplify-boolean-expr %t -- -config="{CheckOptions: [{key: "readability-simplify-boolean-expr.ChainedConditionalReturn", value: 1}]}" --
+
+bool chained_conditional_compound_return(int i) {
+ if (i < 0) {
+ return true;
+ } else if (i < 10) {
+ return false;
+ } else if (i > 20) {
+ return true;
+ } else {
+ return false;
+ }
+ // CHECK-MESSAGES: :[[@LINE-4]]:12: warning: redundant boolean literal in conditional return statement [readability-simplify-boolean-expr]
+ // CHECK-FIXES: {{^}} } else if (i < 10) {{{$}}
+ // CHECK-FIXES-NEXT: {{^}} return false;{{$}}
+ // CHECK-FIXES-NEXT: {{^}} } else return i > 20;{{$}}
+}
+
+bool chained_conditional_return(int i) {
+ if (i < 0)
+ return true;
+ else if (i < 10)
+ return false;
+ else if (i > 20)
+ return true;
+ else
+ return false;
+ // CHECK-MESSAGES: :[[@LINE-3]]:12: warning: {{.*}} in conditional return statement
+ // CHECK-FIXES: {{^}} else if (i < 10)
+ // CHECK-FIXES-NEXT: {{^}} return false;
+ // CHECK-FIXES-NEXT: {{^}} else return i > 20;
+}
+
+bool chained_simple_if_return(int i) {
+ if (i < 5)
+ return true;
+ if (i > 10)
+ return true;
+ return false;
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: {{^}}bool chained_simple_if_return(int i) {{{$}}
+// CHECK-FIXES: {{^}} if (i < 5){{$}}
+// CHECK-FIXES: {{^ return true;$}}
+// CHECK-FIXES: {{^ return i > 10;$}}
+// CHECK-FIXES: {{^}$}}
+
+bool chained_simple_if_return_negated(int i) {
+ if (i < 5)
+ return false;
+ if (i > 10)
+ return false;
+ return true;
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: {{^}}bool chained_simple_if_return_negated(int i) {{{$}}
+// CHECK-FIXES: {{^}} if (i < 5){{$}}
+// CHECK-FIXES: {{^ return false;$}}
+// CHECK-FIXES: {{^ return i <= 10;$}}
+// CHECK-FIXES: {{^}$}}
+
+bool complex_chained_if_return_return(int i) {
+ if (i < 5) {
+ return true;
+ }
+ if (i > 10) {
+ return true;
+ }
+ return false;
+}
+// CHECK-MESSAGES: :[[@LINE-4]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: {{^}}bool complex_chained_if_return_return(int i) {{{$}}
+// CHECK-FIXES: {{^}} if (i < 5) {{{$}}
+// CHECK-FIXES: {{^}} return true;{{$}}
+// CHECK-FIXES: {{^}} }{{$}}
+// CHECK-FIXES: {{^ return i > 10;$}}
+// CHECK-FIXES: {{^}$}}
+
+bool complex_chained_if_return_return_negated(int i) {
+ if (i < 5) {
+ return false;
+ }
+ if (i > 10) {
+ return false;
+ }
+ return true;
+}
+// CHECK-MESSAGES: :[[@LINE-4]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: {{^}}bool complex_chained_if_return_return_negated(int i) {{{$}}
+// CHECK-FIXES: {{^}} if (i < 5) {{{$}}
+// CHECK-FIXES: {{^}} return false;{{$}}
+// CHECK-FIXES: {{^}} }{{$}}
+// CHECK-FIXES: {{^ return i <= 10;$}}
+// CHECK-FIXES: {{^}$}}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,356 @@
+// RUN: %check_clang_tidy %s readability-simplify-boolean-expr %t
+
+class A {
+public:
+ int m;
+};
+
+struct S {
+ S() : m_ar(s_a) {}
+
+ void operator_equals();
+ void operator_or();
+ void operator_and();
+ void ternary_operator();
+ void operator_not_equal();
+ void simple_conditional_assignment_statements();
+ void complex_conditional_assignment_statements();
+ void chained_conditional_assignment();
+ bool non_null_pointer_condition();
+ bool null_pointer_condition();
+ bool negated_non_null_pointer_condition();
+ bool negated_null_pointer_condition();
+ bool integer_not_zero();
+ bool member_pointer_nullptr();
+ bool integer_member_implicit_cast();
+ bool expr_with_cleanups();
+
+ bool m_b1 = false;
+ bool m_b2 = false;
+ bool m_b3 = false;
+ bool m_b4 = false;
+ int *m_p = nullptr;
+ int A::*m_m = nullptr;
+ int m_i = 0;
+ A *m_a = nullptr;
+ static A s_a;
+ A &m_ar;
+};
+
+void S::operator_equals() {
+ int i = 0;
+ m_b1 = (i > 2);
+ if (m_b1 == true) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: {{.*}} to boolean operator
+ // CHECK-FIXES: {{^ if \(m_b1\) {$}}
+ i = 5;
+ } else {
+ i = 6;
+ }
+ m_b2 = (i > 4);
+ if (m_b2 == false) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: {{.*}} to boolean operator
+ // CHECK-FIXES: {{^ if \(!m_b2\) {$}}
+ i = 7;
+ } else {
+ i = 9;
+ }
+ m_b3 = (i > 6);
+ if (true == m_b3) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: {{.*}} to boolean operator
+ // CHECK-FIXES: {{^ if \(m_b3\) {$}}
+ i = 10;
+ } else {
+ i = 11;
+ }
+ m_b4 = (i > 8);
+ if (false == m_b4) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: {{.*}} to boolean operator
+ // CHECK-FIXES: {{^ if \(!m_b4\) {$}}
+ i = 12;
+ } else {
+ i = 13;
+ }
+}
+
+void S::operator_or() {
+ int i = 0;
+ m_b1 = (i > 10);
+ if (m_b1 || false) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: {{.*}} to boolean operator
+ // CHECK-FIXES: {{^ if \(m_b1\) {$}}
+ i = 14;
+ } else {
+ i = 15;
+ }
+ m_b2 = (i > 10);
+ if (m_b2 || true) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: {{.*}} to boolean operator
+ // CHECK-FIXES: {{^ if \(true\) {$}}
+ i = 16;
+ } else {
+ i = 17;
+ }
+ m_b3 = (i > 10);
+ if (false || m_b3) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: {{.*}} to boolean operator
+ // CHECK-FIXES: {{^ if \(m_b3\) {$}}
+ i = 18;
+ } else {
+ i = 19;
+ }
+ m_b4 = (i > 10);
+ if (true || m_b4) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: {{.*}} to boolean operator
+ // CHECK-FIXES: {{^ if \(true\) {$}}
+ i = 20;
+ } else {
+ i = 21;
+ }
+}
+
+void S::operator_and() {
+ int i = 0;
+ m_b1 = (i > 20);
+ if (m_b1 && false) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: {{.*}} to boolean operator
+ // CHECK-FIXES: {{^ if \(false\) {$}}
+ i = 22;
+ } else {
+ i = 23;
+ }
+ m_b2 = (i > 20);
+ if (m_b2 && true) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: {{.*}} to boolean operator
+ // CHECK-FIXES: {{^ if \(m_b2\) {$}}
+ i = 24;
+ } else {
+ i = 25;
+ }
+ m_b3 = (i > 20);
+ if (false && m_b3) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: {{.*}} to boolean operator
+ // CHECK-FIXES: {{^ if \(false\) {$}}
+ i = 26;
+ } else {
+ i = 27;
+ }
+ m_b4 = (i > 20);
+ if (true && m_b4) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: {{.*}} to boolean operator
+ // CHECK-FIXES: {{^ if \(m_b4\) {$}}
+ i = 28;
+ } else {
+ i = 29;
+ }
+}
+
+void S::ternary_operator() {
+ int i = 0;
+ m_b1 = (i > 20) ? true : false;
+ // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: {{.*}} in ternary expression result
+ // CHECK-FIXES: {{^ m_b1 = i > 20;$}}
+
+ m_b2 = (i > 20) ? false : true;
+ // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: {{.*}} in ternary expression result
+ // CHECK-FIXES: {{^ m_b2 = i <= 20;$}}
+
+ m_b3 = ((i > 20)) ? false : true;
+ // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: {{.*}} in ternary expression result
+ // CHECK-FIXES: {{^ m_b3 = i <= 20;$}}
+}
+
+void S::operator_not_equal() {
+ int i = 0;
+ m_b1 = (i > 20);
+ if (false != m_b1) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: {{.*}} to boolean operator
+ // CHECK-FIXES: {{^ if \(m_b1\) {$}}
+ i = 30;
+ } else {
+ i = 31;
+ }
+ m_b2 = (i > 20);
+ if (true != m_b2) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: {{.*}} to boolean operator
+ // CHECK-FIXES: {{^ if \(!m_b2\) {$}}
+ i = 32;
+ } else {
+ i = 33;
+ }
+ m_b3 = (i > 20);
+ if (m_b3 != false) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: {{.*}} to boolean operator
+ // CHECK-FIXES: {{^ if \(m_b3\) {$}}
+ i = 34;
+ } else {
+ i = 35;
+ }
+ m_b4 = (i > 20);
+ if (m_b4 != true) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: {{.*}} to boolean operator
+ // CHECK-FIXES: {{^ if \(!m_b4\) {$}}
+ i = 36;
+ } else {
+ i = 37;
+ }
+}
+
+void S::simple_conditional_assignment_statements() {
+ if (m_i > 10)
+ m_b1 = true;
+ else
+ m_b1 = false;
+ bool bb = false;
+ // CHECK-MESSAGES: :[[@LINE-4]]:12: warning: {{.*}} in conditional assignment
+ // CHECK-FIXES: {{^ }}m_b1 = m_i > 10;{{$}}
+ // CHECK-FIXES: bool bb = false;
+
+ if (m_i > 20)
+ m_b2 = false;
+ else
+ m_b2 = true;
+ bool c2 = false;
+ // CHECK-MESSAGES: :[[@LINE-4]]:12: warning: {{.*}} in conditional assignment
+ // CHECK-FIXES: {{^ }}m_b2 = m_i <= 20;{{$}}
+ // CHECK-FIXES: bool c2 = false;
+
+ // Unchanged: different variables.
+ if (m_i > 12)
+ m_b1 = true;
+ else
+ m_b2 = false;
+
+ // Unchanged: no else statement.
+ if (m_i > 15)
+ m_b3 = true;
+
+ // Unchanged: not boolean assignment.
+ int j;
+ if (m_i > 17)
+ j = 10;
+ else
+ j = 20;
+
+ // Unchanged: different variables assigned.
+ int k = 0;
+ m_b4 = false;
+ if (m_i > 10)
+ m_b4 = true;
+ else
+ k = 10;
+}
+
+void S::complex_conditional_assignment_statements() {
+ if (m_i > 30) {
+ m_b1 = true;
+ } else {
+ m_b1 = false;
+ }
+ m_b1 = false;
+ // CHECK-MESSAGES: :[[@LINE-5]]:12: warning: {{.*}} in conditional assignment
+ // CHECK-FIXES: {{^ }}m_b1 = m_i > 30;{{$}}
+ // CHECK-FIXES: m_b1 = false;
+
+ if (m_i > 40) {
+ m_b2 = false;
+ } else {
+ m_b2 = true;
+ }
+ m_b2 = false;
+ // CHECK-MESSAGES: :[[@LINE-5]]:12: warning: {{.*}} in conditional assignment
+ // CHECK-FIXES: {{^ }}m_b2 = m_i <= 40;{{$}}
+ // CHECK-FIXES: m_b2 = false;
+}
+
+// Unchanged: chained return statements, but ChainedConditionalReturn not set.
+void S::chained_conditional_assignment() {
+ if (m_i < 0)
+ m_b1 = true;
+ else if (m_i < 10)
+ m_b1 = false;
+ else if (m_i > 20)
+ m_b1 = true;
+ else
+ m_b1 = false;
+}
+
+bool S::non_null_pointer_condition() {
+ if (m_p) {
+ return true;
+ } else {
+ return false;
+ }
+}
+// CHECK-MESSAGES: :[[@LINE-5]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: return m_p != nullptr;{{$}}
+
+bool S::null_pointer_condition() {
+ if (!m_p) {
+ return true;
+ } else {
+ return false;
+ }
+}
+// CHECK-MESSAGES: :[[@LINE-5]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: return m_p == nullptr;{{$}}
+
+bool S::negated_non_null_pointer_condition() {
+ if (m_p) {
+ return false;
+ } else {
+ return true;
+ }
+}
+// CHECK-MESSAGES: :[[@LINE-5]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: return m_p == nullptr;{{$}}
+
+bool S::negated_null_pointer_condition() {
+ if (!m_p) {
+ return false;
+ } else {
+ return true;
+ }
+}
+// CHECK-MESSAGES: :[[@LINE-5]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: return m_p != nullptr;{{$}}
+
+bool S::integer_not_zero() {
+ if (m_i) {
+ return false;
+ } else {
+ return true;
+ }
+}
+// CHECK-MESSAGES: :[[@LINE-5]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: {{^}} return m_i == 0;{{$}}
+
+bool S::member_pointer_nullptr() {
+ if (m_m) {
+ return true;
+ } else {
+ return false;
+ }
+}
+// CHECK-MESSAGES: :[[@LINE-5]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: return m_m != nullptr;{{$}}
+
+bool S::integer_member_implicit_cast() {
+ if (m_a->m) {
+ return true;
+ } else {
+ return false;
+ }
+}
+// CHECK-MESSAGES: :[[@LINE-5]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: return m_a->m != 0;{{$}}
+
+bool operator!=(const A &, const A &) { return false; }
+bool S::expr_with_cleanups() {
+ if (m_ar != (A)m_ar)
+ return false;
+
+ return true;
+}
+// CHECK-MESSAGES: :[[@LINE-4]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: m_ar == (A)m_ar;{{$}}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,950 @@
+// RUN: %check_clang_tidy %s readability-simplify-boolean-expr %t
+
+bool a1 = false;
+
+//=-=-=-=-=-=-= operator ==
+bool aa = false == a1;
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: redundant boolean literal supplied to boolean operator [readability-simplify-boolean-expr]
+// CHECK-FIXES: {{^bool aa = !a1;$}}
+bool ab = true == a1;
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: {{.*}} to boolean operator
+// CHECK-FIXES: {{^bool ab = a1;$}}
+bool a2 = a1 == false;
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: {{.*}} to boolean operator
+// CHECK-FIXES: {{^bool a2 = !a1;$}}
+bool a3 = a1 == true;
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: {{.*}} to boolean operator
+// CHECK-FIXES: {{^bool a3 = a1;$}}
+
+//=-=-=-=-=-=-= operator !=
+bool n1 = a1 != false;
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: {{.*}} to boolean operator
+// CHECK-FIXES: {{^bool n1 = a1;$}}
+bool n2 = a1 != true;
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: {{.*}} to boolean operator
+// CHECK-FIXES: {{^bool n2 = !a1;$}}
+bool n3 = false != a1;
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: {{.*}} to boolean operator
+// CHECK-FIXES: {{^bool n3 = a1;$}}
+bool n4 = true != a1;
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: {{.*}} to boolean operator
+// CHECK-FIXES: {{^bool n4 = !a1;$}}
+
+//=-=-=-=-=-=-= operator ||
+bool a4 = a1 || false;
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: {{.*}} to boolean operator
+// CHECK-FIXES: {{^bool a4 = a1;$}}
+bool a5 = a1 || true;
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: {{.*}} to boolean operator
+// CHECK-FIXES: {{^bool a5 = true;$}}
+bool a6 = false || a1;
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: {{.*}} to boolean operator
+// CHECK-FIXES: {{^bool a6 = a1;$}}
+bool a7 = true || a1;
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: {{.*}} to boolean operator
+// CHECK-FIXES: {{^bool a7 = true;$}}
+
+//=-=-=-=-=-=-= operator &&
+bool a8 = a1 && false;
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: {{.*}} to boolean operator
+// CHECK-FIXES: {{^bool a8 = false;$}}
+bool a9 = a1 && true;
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: {{.*}} to boolean operator
+// CHECK-FIXES: {{^bool a9 = a1;$}}
+bool ac = false && a1;
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: {{.*}} to boolean operator
+// CHECK-FIXES: {{^bool ac = false;$}}
+bool ad = true && a1;
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: {{.*}} to boolean operator
+// CHECK-FIXES: {{^bool ad = a1;$}}
+
+void if_with_bool_literal_condition() {
+ int i = 0;
+ if (false) {
+ i = 1;
+ } else {
+ i = 2;
+ }
+ i = 3;
+ // CHECK-MESSAGES: :[[@LINE-6]]:7: warning: {{.*}} in if statement condition
+ // CHECK-FIXES: {{^ int i = 0;$}}
+ // CHECK-FIXES-NEXT: {{^ {$}}
+ // CHECK-FIXES-NEXT: {{^ i = 2;$}}
+ // CHECK-FIXES-NEXT: {{^ }$}}
+ // CHECK-FIXES-NEXT: {{^ i = 3;$}}
+
+ i = 4;
+ if (true) {
+ i = 5;
+ } else {
+ i = 6;
+ }
+ i = 7;
+ // CHECK-MESSAGES: :[[@LINE-6]]:7: warning: {{.*}} in if statement condition
+ // CHECK-FIXES: {{^ i = 4;$}}
+ // CHECK-FIXES-NEXT: {{^ {$}}
+ // CHECK-FIXES-NEXT: {{^ i = 5;$}}
+ // CHECK-FIXES-NEXT: {{^ }$}}
+ // CHECK-FIXES-NEXT: {{^ i = 7;$}}
+
+ i = 8;
+ if (false) {
+ i = 9;
+ }
+ i = 11;
+ // CHECK-MESSAGES: :[[@LINE-4]]:7: warning: {{.*}} in if statement condition
+ // CHECK-FIXES: {{^ i = 8;$}}
+ // CHECK-FIXES-NEXT: {{^ $}}
+ // CHECK-FIXES-NEXT: {{^ i = 11;$}}
+}
+
+void operator_equals() {
+ int i = 0;
+ bool b1 = (i > 2);
+ if (b1 == true) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: {{.*}} to boolean operator
+ // CHECK-FIXES: {{^ if \(b1\) {$}}
+ i = 5;
+ } else {
+ i = 6;
+ }
+ bool b2 = (i > 4);
+ if (b2 == false) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: {{.*}} to boolean operator
+ // CHECK-FIXES: {{^ if \(!b2\) {$}}
+ i = 7;
+ } else {
+ i = 9;
+ }
+ bool b3 = (i > 6);
+ if (true == b3) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: {{.*}} to boolean operator
+ // CHECK-FIXES: {{^ if \(b3\) {$}}
+ i = 10;
+ } else {
+ i = 11;
+ }
+ bool b4 = (i > 8);
+ if (false == b4) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: {{.*}} to boolean operator
+ // CHECK-FIXES: {{^ if \(!b4\) {$}}
+ i = 12;
+ } else {
+ i = 13;
+ }
+}
+
+void operator_or() {
+ int i = 0;
+ bool b5 = (i > 10);
+ if (b5 || false) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: {{.*}} to boolean operator
+ // CHECK-FIXES: {{^ if \(b5\) {$}}
+ i = 14;
+ } else {
+ i = 15;
+ }
+ bool b6 = (i > 10);
+ if (b6 || true) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: {{.*}} to boolean operator
+ // CHECK-FIXES: {{^ if \(true\) {$}}
+ i = 16;
+ } else {
+ i = 17;
+ }
+ bool b7 = (i > 10);
+ if (false || b7) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: {{.*}} to boolean operator
+ // CHECK-FIXES: {{^ if \(b7\) {$}}
+ i = 18;
+ } else {
+ i = 19;
+ }
+ bool b8 = (i > 10);
+ if (true || b8) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: {{.*}} to boolean operator
+ // CHECK-FIXES: {{^ if \(true\) {$}}
+ i = 20;
+ } else {
+ i = 21;
+ }
+}
+
+void operator_and() {
+ int i = 0;
+ bool b9 = (i > 20);
+ if (b9 && false) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: {{.*}} to boolean operator
+ // CHECK-FIXES: {{^ if \(false\) {$}}
+ i = 22;
+ } else {
+ i = 23;
+ }
+ bool ba = (i > 20);
+ if (ba && true) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: {{.*}} to boolean operator
+ // CHECK-FIXES: {{^ if \(ba\) {$}}
+ i = 24;
+ } else {
+ i = 25;
+ }
+ bool bb = (i > 20);
+ if (false && bb) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: {{.*}} to boolean operator
+ // CHECK-FIXES: {{^ if \(false\) {$}}
+ i = 26;
+ } else {
+ i = 27;
+ }
+ bool bc = (i > 20);
+ if (true && bc) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: {{.*}} to boolean operator
+ // CHECK-FIXES: {{^ if \(bc\) {$}}
+ i = 28;
+ } else {
+ i = 29;
+ }
+}
+
+void ternary_operator() {
+ int i = 0;
+ bool bd = (i > 20) ? true : false;
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: {{.*}} in ternary expression result
+ // CHECK-FIXES: {{^ bool bd = i > 20;$}}
+
+ bool be = (i > 20) ? false : true;
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: {{.*}} in ternary expression result
+ // CHECK-FIXES: {{^ bool be = i <= 20;$}}
+
+ bool bf = ((i > 20)) ? false : true;
+ // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: {{.*}} in ternary expression result
+ // CHECK-FIXES: {{^ bool bf = i <= 20;$}}
+}
+
+void operator_not_equal() {
+ int i = 0;
+ bool bf = (i > 20);
+ if (false != bf) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: {{.*}} to boolean operator
+ // CHECK-FIXES: {{^ if \(bf\) {$}}
+ i = 30;
+ } else {
+ i = 31;
+ }
+ bool bg = (i > 20);
+ if (true != bg) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: {{.*}} to boolean operator
+ // CHECK-FIXES: {{^ if \(!bg\) {$}}
+ i = 32;
+ } else {
+ i = 33;
+ }
+ bool bh = (i > 20);
+ if (bh != false) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: {{.*}} to boolean operator
+ // CHECK-FIXES: {{^ if \(bh\) {$}}
+ i = 34;
+ } else {
+ i = 35;
+ }
+ bool bi = (i > 20);
+ if (bi != true) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: {{.*}} to boolean operator
+ // CHECK-FIXES: {{^ if \(!bi\) {$}}
+ i = 36;
+ } else {
+ i = 37;
+ }
+}
+
+void nested_booleans() {
+ if (false || (true || false)) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: {{.*}} to boolean operator
+ // CHECK-FIXES: {{^ if \(false \|\| \(true\)\) {$}}
+ }
+ if (true && (true || false)) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: {{.*}} to boolean operator
+ // CHECK-FIXES: {{^ if \(true && \(true\)\) {$}}
+ }
+ if (false || (true && false)) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: {{.*}} to boolean operator
+ // CHECK-FIXES: {{^ if \(false \|\| \(false\)\) {$}}
+ }
+ if (true && (true && false)) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: {{.*}} to boolean operator
+ // CHECK-FIXES: {{^ if \(true && \(false\)\) {$}}
+ }
+}
+
+static constexpr bool truthy() {
+ return true;
+}
+
+#define HAS_XYZ_FEATURE true
+#define M1(what) M2(true, what)
+#define M2(condition, what) if (condition) what
+
+void macros_and_constexprs(int i = 0) {
+ bool b = (i == 1);
+ if (b && truthy()) {
+ // leave this alone; if you want it simplified, then you should
+ // inline the constexpr function first.
+ i = 1;
+ }
+ i = 2;
+ if (b && HAS_XYZ_FEATURE) {
+ // leave this alone; if you want it simplified, then you should
+ // inline the macro first.
+ i = 3;
+ }
+ if (HAS_XYZ_FEATURE) {
+ i = 5;
+ }
+ i = 4;
+ M1(i = 7);
+}
+
+#undef HAS_XYZ_FEATURE
+
+bool conditional_return_statements(int i) {
+ if (i == 0) return true; else return false;
+}
+// CHECK-MESSAGES: :[[@LINE-2]]:22: warning: {{.*}} in conditional return statement
+// CHECK-FIXES: {{^}} return i == 0;{{$}}
+// CHECK-FIXES-NEXT: {{^}$}}
+
+bool conditional_return_statements_then_expr(int i, int j) {
+ if (i == j) return (i == 0); else return false;
+}
+
+bool conditional_return_statements_else_expr(int i, int j) {
+ if (i == j) return true; else return (i == 0);
+}
+
+bool negated_conditional_return_statements(int i) {
+ if (i == 0) return false; else return true;
+}
+// CHECK-MESSAGES: :[[@LINE-2]]:22: warning: {{.*}} in conditional return statement
+// CHECK-FIXES: {{^}} return i != 0;{{$}}
+// CHECK-FIXES-NEXT: {{^}$}}
+
+bool negative_condition_conditional_return_statement(int i) {
+ if (!(i == 0)) return false; else return true;
+}
+// CHECK-MESSAGES: :[[@LINE-2]]:25: warning: {{.*}} in conditional return statement
+// CHECK-FIXES: {{^}} return i == 0;{{$}}
+// CHECK-FIXES-NEXT: {{^}$}}
+
+bool conditional_compound_return_statements(int i) {
+ if (i == 1) {
+ return true;
+ } else {
+ return false;
+ }
+}
+// CHECK-MESSAGES: :[[@LINE-5]]:12: warning: {{.*}} in conditional return statement
+// CHECK-FIXES: {{^}}bool conditional_compound_return_statements(int i) {{{$}}
+// CHECK-FIXES-NEXT: {{^}} return i == 1;{{$}}
+// CHECK-FIXES-NEXT: {{^}$}}
+
+bool negated_conditional_compound_return_statements(int i) {
+ if (i == 1) {
+ return false;
+ } else {
+ return true;
+ }
+}
+// CHECK-MESSAGES: :[[@LINE-5]]:12: warning: {{.*}} in conditional return statement
+// CHECK-FIXES: {{^}}bool negated_conditional_compound_return_statements(int i) {{{$}}
+// CHECK-FIXES-NEXT: {{^}} return i != 1;{{$}}
+// CHECK-FIXES-NEXT: {{^}$}}
+
+bool conditional_return_statements_side_effects_then(int i) {
+ if (i == 2) {
+ macros_and_constexprs();
+ return true;
+ } else
+ return false;
+}
+
+bool negated_conditional_return_statements_side_effects_then(int i) {
+ if (i == 2) {
+ macros_and_constexprs();
+ return false;
+ } else
+ return true;
+}
+
+bool conditional_return_statements_side_effects_else(int i) {
+ if (i == 2)
+ return true;
+ else {
+ macros_and_constexprs();
+ return false;
+ }
+}
+
+bool negated_conditional_return_statements_side_effects_else(int i) {
+ if (i == 2)
+ return false;
+ else {
+ macros_and_constexprs();
+ return true;
+ }
+}
+
+void lambda_conditional_return_statements() {
+ auto lambda = [](int n) -> bool { if (n > 0) return true; else return false; };
+ // CHECK-MESSAGES: :[[@LINE-1]]:55: warning: {{.*}} in conditional return statement
+ // CHECK-FIXES: {{^}} auto lambda = [](int n) -> bool { return n > 0; };{{$}}
+
+ auto lambda2 = [](int n) -> bool {
+ if (n > 0) {
+ return true;
+ } else {
+ return false;
+ }
+ };
+ // CHECK-MESSAGES: :[[@LINE-5]]:16: warning: {{.*}} in conditional return statement
+ // CHECK-FIXES: {{^}} auto lambda2 = [](int n) -> bool {{{$}}
+ // CHECK-FIXES-NEXT: {{^}} return n > 0;{{$}}
+ // CHECK-FIXES-NEXT: {{^}} };{{$}}
+
+ auto lambda3 = [](int n) -> bool { if (n > 0) {macros_and_constexprs(); return true; } else return false; };
+
+ auto lambda4 = [](int n) -> bool {
+ if (n > 0)
+ return true;
+ else {
+ macros_and_constexprs();
+ return false;
+ }
+ };
+
+ auto lambda5 = [](int n) -> bool { if (n > 0) return false; else return true; };
+ // CHECK-MESSAGES: :[[@LINE-1]]:56: warning: {{.*}} in conditional return statement
+ // CHECK-FIXES: {{^}} auto lambda5 = [](int n) -> bool { return n <= 0; };{{$}}
+
+ auto lambda6 = [](int n) -> bool {
+ if (n > 0) {
+ return false;
+ } else {
+ return true;
+ }
+ };
+ // CHECK-MESSAGES: :[[@LINE-5]]:16: warning: {{.*}} in conditional return statement
+ // CHECK-FIXES: {{^}} auto lambda6 = [](int n) -> bool {{{$}}
+ // CHECK-FIXES-NEXT: {{^}} return n <= 0;{{$}}
+ // CHECK-FIXES-NEXT: {{^}} };{{$}}
+}
+
+void simple_conditional_assignment_statements(int i) {
+ bool b;
+ if (i > 10)
+ b = true;
+ else
+ b = false;
+ bool bb = false;
+ // CHECK-MESSAGES: :[[@LINE-4]]:9: warning: {{.*}} in conditional assignment
+ // CHECK-FIXES: bool b;
+ // CHECK-FIXES: {{^ }}b = i > 10;{{$}}
+ // CHECK-FIXES: bool bb = false;
+
+ bool c;
+ if (i > 20)
+ c = false;
+ else
+ c = true;
+ bool c2 = false;
+ // CHECK-MESSAGES: :[[@LINE-4]]:9: warning: {{.*}} in conditional assignment
+ // CHECK-FIXES: bool c;
+ // CHECK-FIXES: {{^ }}c = i <= 20;{{$}}
+ // CHECK-FIXES: bool c2 = false;
+
+ // Unchanged: different variables.
+ bool b2;
+ if (i > 12)
+ b = true;
+ else
+ b2 = false;
+
+ // Unchanged: no else statement.
+ bool b3;
+ if (i > 15)
+ b3 = true;
+
+ // Unchanged: not boolean assignment.
+ int j;
+ if (i > 17)
+ j = 10;
+ else
+ j = 20;
+
+ // Unchanged: different variables assigned.
+ int k = 0;
+ bool b4 = false;
+ if (i > 10)
+ b4 = true;
+ else
+ k = 10;
+}
+
+void complex_conditional_assignment_statements(int i) {
+ bool d;
+ if (i > 30) {
+ d = true;
+ } else {
+ d = false;
+ }
+ d = false;
+ // CHECK-MESSAGES: :[[@LINE-5]]:9: warning: {{.*}} in conditional assignment
+ // CHECK-FIXES: bool d;
+ // CHECK-FIXES: {{^ }}d = i > 30;{{$}}
+ // CHECK-FIXES: d = false;
+
+ bool e;
+ if (i > 40) {
+ e = false;
+ } else {
+ e = true;
+ }
+ e = false;
+ // CHECK-MESSAGES: :[[@LINE-5]]:9: warning: {{.*}} in conditional assignment
+ // CHECK-FIXES: bool e;
+ // CHECK-FIXES: {{^ }}e = i <= 40;{{$}}
+ // CHECK-FIXES: e = false;
+
+ // Unchanged: no else statement.
+ bool b3;
+ if (i > 15) {
+ b3 = true;
+ }
+
+ // Unchanged: not a boolean assignment.
+ int j;
+ if (i > 17) {
+ j = 10;
+ } else {
+ j = 20;
+ }
+
+ // Unchanged: multiple statements.
+ bool f;
+ if (j > 10) {
+ j = 10;
+ f = true;
+ } else {
+ j = 20;
+ f = false;
+ }
+
+ // Unchanged: multiple statements.
+ bool g;
+ if (j > 10)
+ f = true;
+ else {
+ j = 20;
+ f = false;
+ }
+
+ // Unchanged: multiple statements.
+ bool h;
+ if (j > 10) {
+ j = 10;
+ f = true;
+ } else
+ f = false;
+}
+
+// Unchanged: chained return statements, but ChainedConditionalReturn not set.
+bool chained_conditional_compound_return(int i) {
+ if (i < 0) {
+ return true;
+ } else if (i < 10) {
+ return false;
+ } else if (i > 20) {
+ return true;
+ } else {
+ return false;
+ }
+}
+
+// Unchanged: chained return statements, but ChainedConditionalReturn not set.
+bool chained_conditional_return(int i) {
+ if (i < 0)
+ return true;
+ else if (i < 10)
+ return false;
+ else if (i > 20)
+ return true;
+ else
+ return false;
+}
+
+// Unchanged: chained assignments, but ChainedConditionalAssignment not set.
+void chained_conditional_compound_assignment(int i) {
+ bool b;
+ if (i < 0) {
+ b = true;
+ } else if (i < 10) {
+ b = false;
+ } else if (i > 20) {
+ b = true;
+ } else {
+ b = false;
+ }
+}
+
+// Unchanged: chained return statements, but ChainedConditionalReturn not set.
+void chained_conditional_assignment(int i) {
+ bool b;
+ if (i < 0)
+ b = true;
+ else if (i < 10)
+ b = false;
+ else if (i > 20)
+ b = true;
+ else
+ b = false;
+}
+
+// Unchanged: chained return statements, but ChainedConditionalReturn not set.
+bool chained_simple_if_return_negated(int i) {
+ if (i < 5)
+ return false;
+ if (i > 10)
+ return false;
+ return true;
+}
+
+// Unchanged: chained return statements, but ChainedConditionalReturn not set.
+bool complex_chained_if_return_return(int i) {
+ if (i < 5) {
+ return true;
+ }
+ if (i > 10) {
+ return true;
+ }
+ return false;
+}
+
+// Unchanged: chained return statements, but ChainedConditionalReturn not set.
+bool complex_chained_if_return_return_negated(int i) {
+ if (i < 5) {
+ return false;
+ }
+ if (i > 10) {
+ return false;
+ }
+ return true;
+}
+
+// Unchanged: chained return statements, but ChainedConditionalReturn not set.
+bool chained_simple_if_return(int i) {
+ if (i < 5)
+ return true;
+ if (i > 10)
+ return true;
+ return false;
+}
+
+bool simple_if_return_return(int i) {
+ if (i > 10)
+ return true;
+ return false;
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: {{^}}bool simple_if_return_return(int i) {{{$}}
+// CHECK-FIXES: {{^ return i > 10;$}}
+// CHECK-FIXES: {{^}$}}
+
+bool simple_if_return_return_negated(int i) {
+ if (i > 10)
+ return false;
+ return true;
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: {{^}}bool simple_if_return_return_negated(int i) {{{$}}
+// CHECK-FIXES: {{^ return i <= 10;$}}
+// CHECK-FIXES: {{^}$}}
+
+bool complex_if_return_return(int i) {
+ if (i > 10) {
+ return true;
+ }
+ return false;
+}
+// CHECK-MESSAGES: :[[@LINE-4]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: {{^}}bool complex_if_return_return(int i) {{{$}}
+// CHECK-FIXES: {{^ return i > 10;$}}
+// CHECK-FIXES: {{^}$}}
+
+bool complex_if_return_return_negated(int i) {
+ if (i > 10) {
+ return false;
+ }
+ return true;
+}
+// CHECK-MESSAGES: :[[@LINE-4]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: {{^}}bool complex_if_return_return_negated(int i) {{{$}}
+// CHECK-FIXES: {{^ return i <= 10;$}}
+// CHECK-FIXES: {{^}$}}
+
+bool if_implicit_bool_expr(int i) {
+ if (i & 1) {
+ return true;
+ } else {
+ return false;
+ }
+}
+// CHECK-MESSAGES: :[[@LINE-5]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: {{^}} return (i & 1) != 0;{{$}}
+
+bool negated_if_implicit_bool_expr(int i) {
+ if (i - 1) {
+ return false;
+ } else {
+ return true;
+ }
+}
+// CHECK-MESSAGES: :[[@LINE-5]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: {{^}} return (i - 1) == 0;{{$}}
+
+bool implicit_int(int i) {
+ if (i) {
+ return true;
+ } else {
+ return false;
+ }
+}
+// CHECK-MESSAGES: :[[@LINE-5]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: {{^}} return i != 0;{{$}}
+
+bool explicit_bool(bool b) {
+ if (b) {
+ return true;
+ } else {
+ return false;
+ }
+}
+// CHECK-MESSAGES: :[[@LINE-5]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: {{^}} return b;{{$}}
+
+class Implicit {
+public:
+ operator bool() {
+ return true;
+ }
+};
+
+bool object_bool_implicit_conversion(Implicit O) {
+ if (O) {
+ return true;
+ } else {
+ return false;
+ }
+}
+// CHECK-MESSAGES: :[[@LINE-5]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: {{^}} return O;{{$}}
+
+bool negated_explicit_bool(bool b) {
+ if (!b) {
+ return true;
+ } else {
+ return false;
+ }
+}
+// CHECK-MESSAGES: :[[@LINE-5]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: {{^}} return !b;{{$}}
+
+bool bitwise_complement_conversion(int i) {
+ if (~i) {
+ return true;
+ } else {
+ return false;
+ }
+}
+// CHECK-MESSAGES: :[[@LINE-5]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: {{^}} return ~i != 0;{{$}}
+
+bool logical_or(bool a, bool b) {
+ if (a || b) {
+ return true;
+ } else {
+ return false;
+ }
+}
+// CHECK-MESSAGES: :[[@LINE-5]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: {{^}} return a || b;{{$}}
+
+bool logical_and(bool a, bool b) {
+ if (a && b) {
+ return true;
+ } else {
+ return false;
+ }
+}
+// CHECK-MESSAGES: :[[@LINE-5]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: {{^}} return a && b;{{$}}
+
+class Comparable
+{
+public:
+ bool operator==(Comparable const &rhs) { return true; }
+ bool operator!=(Comparable const &rhs) { return false; }
+};
+
+bool comparable_objects() {
+ Comparable c;
+ Comparable d;
+ if (c == d) {
+ return true;
+ } else {
+ return false;
+ }
+}
+// CHECK-MESSAGES: :[[@LINE-5]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: {{^}} return c == d;{{$}}
+
+bool negated_comparable_objects() {
+ Comparable c;
+ Comparable d;
+ if (c == d) {
+ return false;
+ } else {
+ return true;
+ }
+}
+// CHECK-MESSAGES: :[[@LINE-5]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: {{^}} return c != d;{{$}}
+
+struct X {
+ explicit operator bool();
+};
+
+void explicit_conversion_assignment(X x) {
+ bool y;
+ if (x) {
+ y = true;
+ } else {
+ y = false;
+ }
+}
+// CHECK-MESSAGES: :[[@LINE-5]]:9: warning: {{.*}} in conditional assignment
+// CHECK-FIXES: {{^ bool y;$}}
+// CHECK-FIXES: {{^}} y = static_cast<bool>(x);{{$}}
+
+void ternary_integer_condition(int i) {
+ bool b = i ? true : false;
+}
+// CHECK-MESSAGES: :[[@LINE-2]]:16: warning: {{.*}} in ternary expression result
+// CHECK-FIXES: bool b = i != 0;{{$}}
+
+bool non_null_pointer_condition(int *p1) {
+ if (p1) {
+ return true;
+ } else {
+ return false;
+ }
+}
+// CHECK-MESSAGES: :[[@LINE-5]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: return p1 != nullptr;{{$}}
+
+bool null_pointer_condition(int *p2) {
+ if (!p2) {
+ return true;
+ } else {
+ return false;
+ }
+}
+// CHECK-MESSAGES: :[[@LINE-5]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: return p2 == nullptr;{{$}}
+
+bool negated_non_null_pointer_condition(int *p3) {
+ if (p3) {
+ return false;
+ } else {
+ return true;
+ }
+}
+// CHECK-MESSAGES: :[[@LINE-5]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: return p3 == nullptr;{{$}}
+
+bool negated_null_pointer_condition(int *p4) {
+ if (!p4) {
+ return false;
+ } else {
+ return true;
+ }
+}
+// CHECK-MESSAGES: :[[@LINE-5]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: return p4 != nullptr;{{$}}
+
+bool comments_in_the_middle(bool b) {
+ if (b) {
+ return true;
+ } else {
+ // something wicked this way comes
+ return false;
+ }
+}
+// CHECK-MESSAGES: :[[@LINE-6]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: {{^}} if (b) {
+// CHECK-FIXES: // something wicked this way comes{{$}}
+
+bool preprocessor_in_the_middle(bool b) {
+ if (b) {
+ return true;
+ } else {
+#define SOMETHING_WICKED false
+ return false;
+ }
+}
+// CHECK-MESSAGES: :[[@LINE-6]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: {{^}} if (b) {
+// CHECK-FIXES: {{^}}#define SOMETHING_WICKED false
+
+bool integer_not_zero(int i) {
+ if (i) {
+ return false;
+ } else {
+ return true;
+ }
+}
+// CHECK-MESSAGES: :[[@LINE-5]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: {{^}} return i == 0;{{$}}
+
+class A {
+public:
+ int m;
+};
+
+bool member_pointer_nullptr(int A::*p) {
+ if (p) {
+ return true;
+ } else {
+ return false;
+ }
+}
+// CHECK-MESSAGES: :[[@LINE-5]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: return p != nullptr;{{$}}
+
+bool integer_member_implicit_cast(A *p) {
+ if (p->m) {
+ return true;
+ } else {
+ return false;
+ }
+}
+// CHECK-MESSAGES: :[[@LINE-5]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: return p->m != 0;{{$}}
+
+bool operator!=(const A&, const A&) { return false; }
+bool expr_with_cleanups(A &S) {
+ if (S != (A)S)
+ return false;
+
+ return true;
+}
+// CHECK-MESSAGES: :[[@LINE-4]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: S == (A)S;{{$}}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-simplify-subscript-expr.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-simplify-subscript-expr.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-simplify-subscript-expr.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-simplify-subscript-expr.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,108 @@
+// RUN: %check_clang_tidy %s readability-simplify-subscript-expr %t \
+// RUN: -config="{CheckOptions: \
+// RUN: [{key: readability-simplify-subscript-expr.Types, \
+// RUN: value: '::std::basic_string;::std::basic_string_view;MyVector'}]}" --
+
+namespace std {
+
+template <class T>
+class basic_string {
+ public:
+ using size_type = unsigned;
+ using value_type = T;
+ using reference = value_type&;
+ using const_reference = const value_type&;
+
+ reference operator[](size_type);
+ const_reference operator[](size_type) const;
+ T* data();
+ const T* data() const;
+};
+
+using string = basic_string<char>;
+
+template <class T>
+class basic_string_view {
+ public:
+ using size_type = unsigned;
+ using const_reference = const T&;
+ using const_pointer = const T*;
+
+ constexpr const_reference operator[](size_type) const;
+ constexpr const_pointer data() const noexcept;
+};
+
+using string_view = basic_string_view<char>;
+
+}
+
+template <class T>
+class MyVector {
+ public:
+ using size_type = unsigned;
+ using const_reference = const T&;
+ using const_pointer = const T*;
+
+ const_reference operator[](size_type) const;
+ const T* data() const noexcept;
+};
+
+#define DO(x) do { x; } while (false)
+#define ACCESS(x) (x)
+#define GET(x, i) (x).data()[i]
+
+template <class T>
+class Foo {
+ public:
+ char bar(int i) {
+ return x.data()[i];
+ }
+ private:
+ T x;
+};
+
+void f(int i) {
+ MyVector<int> v;
+ int x = v.data()[i];
+ // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: accessing an element of the container does not require a call to 'data()'; did you mean to use 'operator[]'? [readability-simplify-subscript-expr]
+ // CHECK-FIXES: int x = v[i];
+
+ std::string s;
+ char c1 = s.data()[i];
+ // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: accessing an element
+ // CHECK-FIXES: char c1 = s[i];
+
+ std::string_view sv;
+ char c2 = sv.data()[i];
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: accessing an element
+ // CHECK-FIXES: char c2 = sv[i];
+
+ std::string* ps = &s;
+ char c3 = ps->data()[i];
+ // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: accessing an element
+ // CHECK-FIXES: char c3 = (*ps)[i];
+
+ char c4 = (*ps).data()[i];
+ // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: accessing an element
+ // CHECK-FIXES: char c4 = (*ps)[i];
+
+ DO(char c5 = s.data()[i]);
+ // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: accessing an element
+ // CHECK-FIXES: DO(char c5 = s[i]);
+
+ char c6 = ACCESS(s).data()[i];
+ // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: accessing an element
+ // CHECK-FIXES: char c6 = ACCESS(s)[i];
+
+ char c7 = ACCESS(s.data())[i];
+ // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: accessing an element
+ // CHECK-FIXES: char c7 = ACCESS(s)[i];
+
+ char c8 = ACCESS(s.data()[i]);
+ // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: accessing an element
+ // CHECK-FIXES: char c8 = ACCESS(s[i]);
+
+ char c9 = GET(s, i);
+
+ char c10 = Foo<std::string>{}.bar(i);
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-static-accessed-through-instance-nesting-threshold.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-static-accessed-through-instance-nesting-threshold.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-static-accessed-through-instance-nesting-threshold.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-static-accessed-through-instance-nesting-threshold.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,33 @@
+// RUN: %check_clang_tidy %s readability-static-accessed-through-instance %t -- -config="{CheckOptions: [{key: readability-static-accessed-through-instance.NameSpecifierNestingThreshold, value: 4}]}" --
+
+// Nested specifiers
+namespace M {
+namespace N {
+struct V {
+ static int v;
+ struct T {
+ static int t;
+ struct U {
+ static int u;
+ };
+ };
+};
+}
+}
+
+void f(M::N::V::T::U u) {
+ M::N::V v;
+ v.v = 12;
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+ // CHECK-FIXES: {{^}} M::N::V::v = 12;{{$}}
+
+ M::N::V::T w;
+ w.t = 12;
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+ // CHECK-FIXES: {{^}} M::N::V::T::t = 12;{{$}}
+
+ // u.u is not changed, because the nesting level is over 4
+ u.u = 12;
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+ // CHECK-FIXES: {{^}} u.u = 12;{{$}}
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,250 @@
+// RUN: %check_clang_tidy %s readability-static-accessed-through-instance %t
+
+struct C {
+ static void foo();
+ static int x;
+ int nsx;
+ void mf() {
+ (void)&x; // OK, x is accessed inside the struct.
+ (void)&C::x; // OK, x is accessed using a qualified-id.
+ foo(); // OK, foo() is accessed inside the struct.
+ }
+ void ns() const;
+};
+
+int C::x = 0;
+
+struct CC {
+ void foo();
+ int x;
+};
+
+template <typename T> struct CT {
+ static T foo();
+ static T x;
+ int nsx;
+ void mf() {
+ (void)&x; // OK, x is accessed inside the struct.
+ (void)&C::x; // OK, x is accessed using a qualified-id.
+ foo(); // OK, foo() is accessed inside the struct.
+ }
+};
+
+// Expressions with side effects
+C &f(int, int, int, int);
+void g() {
+ f(1, 2, 3, 4).x;
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member accessed through instance [readability-static-accessed-through-instance]
+ // CHECK-FIXES: {{^}} f(1, 2, 3, 4).x;{{$}}
+}
+
+int i(int &);
+void j(int);
+C h();
+bool a();
+int k(bool);
+
+void f(C c) {
+ j(i(h().x));
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: static member
+ // CHECK-FIXES: {{^}} j(i(h().x));{{$}}
+
+ // The execution of h() depends on the return value of a().
+ j(k(a() && h().x));
+ // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: static member
+ // CHECK-FIXES: {{^}} j(k(a() && h().x));{{$}}
+
+ if ([c]() {
+ c.ns();
+ return c;
+ }().x == 15)
+ ;
+ // CHECK-MESSAGES: :[[@LINE-5]]:7: warning: static member
+ // CHECK-FIXES: {{^}} if ([c]() {{{$}}
+}
+
+// Nested specifiers
+namespace N {
+struct V {
+ static int v;
+ struct T {
+ static int t;
+ struct U {
+ static int u;
+ };
+ };
+};
+}
+
+void f(N::V::T::U u) {
+ N::V v;
+ v.v = 12;
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+ // CHECK-FIXES: {{^}} N::V::v = 12;{{$}}
+
+ N::V::T w;
+ w.t = 12;
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+ // CHECK-FIXES: {{^}} N::V::T::t = 12;{{$}}
+
+ // u.u is not changed to N::V::T::U::u; because the nesting level is over 3.
+ u.u = 12;
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+ // CHECK-FIXES: {{^}} u.u = 12;{{$}}
+
+ using B = N::V::T::U;
+ B b;
+ b.u;
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+ // CHECK-FIXES: {{^}} B::u;{{$}}
+}
+
+// Templates
+template <typename T> T CT<T>::x;
+
+template <typename T> struct CCT {
+ T foo();
+ T x;
+};
+
+typedef C D;
+
+using E = D;
+
+#define FOO(c) c.foo()
+#define X(c) c.x
+
+template <typename T> void f(T t, C c) {
+ t.x; // OK, t is a template parameter.
+ c.x;
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+ // CHECK-FIXES: {{^}} C::x;{{$}}
+}
+
+template <int N> struct S { static int x; };
+
+template <> struct S<0> { int x; };
+
+template <int N> void h() {
+ S<N> sN;
+ sN.x; // OK, value of N affects whether x is static or not.
+
+ S<2> s2;
+ s2.x;
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+ // CHECK-FIXES: {{^}} S<2>::x;{{$}}
+}
+
+void static_through_instance() {
+ C *c1 = new C();
+ c1->foo(); // 1
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+ // CHECK-FIXES: {{^}} C::foo(); // 1{{$}}
+ c1->x; // 2
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+ // CHECK-FIXES: {{^}} C::x; // 2{{$}}
+ c1->nsx; // OK, nsx is a non-static member.
+
+ const C *c2 = new C();
+ c2->foo(); // 2
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+ // CHECK-FIXES: {{^}} C::foo(); // 2{{$}}
+
+ C::foo(); // OK, foo() is accessed using a qualified-id.
+ C::x; // OK, x is accessed using a qualified-id.
+
+ D d;
+ d.foo();
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+ // CHECK-FIXES: {{^}} D::foo();{{$}}
+ d.x;
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+ // CHECK-FIXES: {{^}} D::x;{{$}}
+
+ E e;
+ e.foo();
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+ // CHECK-FIXES: {{^}} E::foo();{{$}}
+ e.x;
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+ // CHECK-FIXES: {{^}} E::x;{{$}}
+
+ CC *cc = new CC;
+
+ f(*c1, *c1);
+ f(*cc, *c1);
+
+ // Macros: OK, macros are not checked.
+ FOO((*c1));
+ X((*c1));
+ FOO((*cc));
+ X((*cc));
+
+ // Templates
+ CT<int> ct;
+ ct.foo();
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+ // CHECK-FIXES: {{^}} CT<int>::foo();{{$}}
+ ct.x;
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+ // CHECK-FIXES: {{^}} CT<int>::x;{{$}}
+ ct.nsx; // OK, nsx is a non-static member
+
+ CCT<int> cct;
+ cct.foo(); // OK, CCT has no static members.
+ cct.x; // OK, CCT has no static members.
+
+ h<4>();
+}
+
+// Overloaded member access operator
+struct Q {
+ static int K;
+ int y = 0;
+};
+
+int Q::K = 0;
+
+struct Qptr {
+ Q *q;
+
+ explicit Qptr(Q *qq) : q(qq) {}
+
+ Q *operator->() {
+ ++q->y;
+ return q;
+ }
+};
+
+int func(Qptr qp) {
+ qp->y = 10; // OK, the overloaded operator might have side-effects.
+ qp->K = 10; //
+}
+
+namespace {
+ struct Anonymous {
+ static int I;
+ };
+}
+
+void use_anonymous() {
+ Anonymous Anon;
+ Anon.I;
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+ // CHECK-FIXES: {{^}} Anonymous::I;{{$}}
+}
+
+namespace Outer {
+ inline namespace Inline {
+ struct S {
+ static int I;
+ };
+ }
+}
+
+void use_inline() {
+ Outer::S V;
+ V.I;
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+ // CHECK-FIXES: {{^}} Outer::S::I;{{$}}
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-static-definition-in-anonymous-namespace.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-static-definition-in-anonymous-namespace.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-static-definition-in-anonymous-namespace.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-static-definition-in-anonymous-namespace.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,49 @@
+// RUN: %check_clang_tidy %s readability-static-definition-in-anonymous-namespace %t
+
+namespace {
+
+int a = 1;
+const int b = 1;
+static int c = 1;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: 'c' is a static definition in anonymous namespace; static is redundant here [readability-static-definition-in-anonymous-namespace]
+// CHECK-FIXES: {{^}}int c = 1;
+static const int d = 1;
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'd' is a static definition in anonymous namespace
+// CHECK-FIXES: {{^}}const int d = 1;
+const static int e = 1;
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'e' is a static definition in anonymous namespace
+// CHECK-FIXES: {{^}}const int e = 1;
+
+void f() {
+ int a = 1;
+ static int b = 1;
+}
+
+static int g() {
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: 'g' is a static definition in anonymous namespace
+// CHECK-FIXES: {{^}}int g() {
+ return 1;
+}
+
+#define DEFINE_STATIC static
+// CHECK-FIXES: {{^}}#define DEFINE_STATIC static
+DEFINE_STATIC int h = 1;
+// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: 'h' is a static definition in anonymous namespace
+// CHECK-FIXES: {{^}}DEFINE_STATIC int h = 1;
+
+#define DEFINE_STATIC_VAR(x) static int x = 2
+// CHECK-FIXES: {{^}}#define DEFINE_STATIC_VAR(x) static int x = 2
+DEFINE_STATIC_VAR(i);
+// CHECK-FIXES: {{^}}DEFINE_STATIC_VAR(i);
+
+} // namespace
+
+namespace N {
+
+int a = 1;
+const int b = 1;
+static int c = 1;
+static const int d = 1;
+const static int e = 1;
+
+} // namespace N
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-string-compare.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-string-compare.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-string-compare.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-string-compare.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,119 @@
+// RUN: %check_clang_tidy %s readability-string-compare %t
+
+namespace std {
+template <typename T>
+class allocator {};
+template <typename T>
+class char_traits {};
+template <typename C, typename T = std::char_traits<C>, typename A = std::allocator<C>>
+class basic_string {
+public:
+ basic_string();
+ basic_string(const C *, unsigned int size);
+ int compare(const basic_string<char> &str) const;
+ int compare(const C *) const;
+ int compare(int, int, const basic_string<char> &str) const;
+ bool empty();
+};
+bool operator==(const basic_string<char> &lhs, const basic_string<char> &rhs);
+bool operator!=(const basic_string<char> &lhs, const basic_string<char> &rhs);
+bool operator==(const basic_string<char> &lhs, const char *&rhs);
+typedef basic_string<char> string;
+}
+
+void func(bool b);
+
+std::string comp() {
+ std::string str("a", 1);
+ return str;
+}
+
+void Test() {
+ std::string str1("a", 1);
+ std::string str2("b", 1);
+
+ if (str1.compare(str2)) {
+ }
+ // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings; use the string equality operator instead [readability-string-compare]
+ if (!str1.compare(str2)) {
+ }
+ // CHECK-MESSAGES: [[@LINE-2]]:8: warning: do not use 'compare' to test equality of strings; use the string equality operator instead [readability-string-compare]
+ if (str1.compare(str2) == 0) {
+ }
+ // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+ // CHECK-FIXES: if (str1 == str2) {
+ if (str1.compare(str2) != 0) {
+ }
+ // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+ // CHECK-FIXES: if (str1 != str2) {
+ if (str1.compare("foo") == 0) {
+ }
+ // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+ // CHECK-FIXES: if (str1 == "foo") {
+ if (0 == str1.compare(str2)) {
+ }
+ // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+ // CHECK-FIXES: if (str2 == str1) {
+ if (0 != str1.compare(str2)) {
+ }
+ // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+ // CHECK-FIXES: if (str2 != str1) {
+ func(str1.compare(str2));
+ // CHECK-MESSAGES: [[@LINE-1]]:8: warning: do not use 'compare' to test equality of strings;
+ if (str2.empty() || str1.compare(str2) != 0) {
+ }
+ // CHECK-MESSAGES: [[@LINE-2]]:23: warning: do not use 'compare' to test equality of strings;
+ // CHECK-FIXES: if (str2.empty() || str1 != str2) {
+ std::string *str3 = &str1;
+ if (str3->compare(str2)) {
+ }
+ // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+ if (str3->compare(str2) == 0) {
+ }
+ // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+ // CHECK-FIXES: if (*str3 == str2) {
+ if (str2.compare(*str3) == 0) {
+ }
+ // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+ // CHECK-FIXES: if (str2 == *str3) {
+ if (comp().compare(str1) == 0) {
+ }
+ // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+ // CHECK-FIXES: if (comp() == str1) {
+ if (str1.compare(comp()) == 0) {
+ }
+ // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+ // CHECK-FIXES: if (str1 == comp()) {
+ if (str1.compare(comp())) {
+ }
+ // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+}
+
+void Valid() {
+ std::string str1("a", 1);
+ std::string str2("b", 1);
+ if (str1 == str2) {
+ }
+ if (str1 != str2) {
+ }
+ if (str1.compare(str2) == str1.compare(str2)) {
+ }
+ if (0 == 0) {
+ }
+ if (str1.compare(str2) > 0) {
+ }
+ if (str1.compare(1, 3, str2)) {
+ }
+ if (str1.compare(str2) > 0) {
+ }
+ if (str1.compare(str2) < 0) {
+ }
+ if (str1.compare(str2) == 2) {
+ }
+ if (str1.compare(str2) == -3) {
+ }
+ if (str1.compare(str2) == 1) {
+ }
+ if (str1.compare(str2) == -1) {
+ }
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uniqueptr-delete-release.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uniqueptr-delete-release.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uniqueptr-delete-release.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uniqueptr-delete-release.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,76 @@
+// RUN: %check_clang_tidy %s readability-uniqueptr-delete-release %t
+
+namespace std {
+template <typename T>
+struct default_delete {};
+
+template <typename T, typename D = default_delete<T>>
+class unique_ptr {
+ public:
+ unique_ptr();
+ ~unique_ptr();
+ explicit unique_ptr(T*);
+ template <typename U, typename E>
+ unique_ptr(unique_ptr<U, E>&&);
+ T* release();
+};
+} // namespace std
+
+std::unique_ptr<int>& ReturnsAUnique();
+
+void Positives() {
+ std::unique_ptr<int> P;
+ delete P.release();
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer '= nullptr' to 'delete x.release()' to reset unique_ptr<> objects [readability-uniqueptr-delete-release]
+ // CHECK-FIXES: {{^}} P = nullptr;
+
+ auto P2 = P;
+ delete P2.release();
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer '= nullptr' to 'delete x.release()' to reset unique_ptr<> objects [readability-uniqueptr-delete-release]
+ // CHECK-FIXES: {{^}} P2 = nullptr;
+
+ std::unique_ptr<int> Array[20];
+ delete Array[4].release();
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer '= nullptr' to 'delete
+ // CHECK-FIXES: {{^}} Array[4] = nullptr;
+
+ delete ReturnsAUnique().release();
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer '= nullptr' to 'delete
+ // CHECK-FIXES: {{^}} ReturnsAUnique() = nullptr;
+}
+
+struct NotDefaultDeleter {};
+
+struct NotUniquePtr {
+ int* release();
+};
+
+void Negatives() {
+ std::unique_ptr<int, NotDefaultDeleter> P;
+ delete P.release();
+
+ NotUniquePtr P2;
+ delete P2.release();
+}
+
+template <typename T, typename D>
+void NegativeDeleterT() {
+ // Ideally this would trigger a warning, but we have all dependent types
+ // disabled for now.
+ std::unique_ptr<T> P;
+ delete P.release();
+
+ // We ignore this one because the deleter is a template argument.
+ // Not all instantiations will use the default deleter.
+ std::unique_ptr<int, D> P2;
+ delete P2.release();
+}
+template void NegativeDeleterT<int, std::default_delete<int>>();
+
+// Test some macros
+
+#define DELETE_RELEASE(x) delete (x).release()
+void NegativesWithTemplate() {
+ std::unique_ptr<int> P;
+ DELETE_RELEASE(P);
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uppercase-literal-suffix-float16.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uppercase-literal-suffix-float16.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uppercase-literal-suffix-float16.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uppercase-literal-suffix-float16.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,51 @@
+// RUN: %check_clang_tidy %s readability-uppercase-literal-suffix %t -- -- -target aarch64-linux-gnu -I %S
+
+#include "readability-uppercase-literal-suffix.h"
+
+void float16_normal_literals() {
+ // _Float16
+
+ static constexpr auto v14 = 1.f16;
+ // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'f16', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v14 = 1.f16;
+ // CHECK-MESSAGES-NEXT: ^ ~
+ // CHECK-MESSAGES-NEXT: {{^ *}}F16{{$}}
+ // CHECK-FIXES: static constexpr auto v14 = 1.F16;
+ static_assert(is_same<decltype(v14), const _Float16>::value, "");
+ static_assert(v14 == 1.F16, "");
+
+ static constexpr auto v15 = 1.e0f16;
+ // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'f16', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v15 = 1.e0f16;
+ // CHECK-MESSAGES-NEXT: ^ ~
+ // CHECK-MESSAGES-NEXT: {{^ *}}F16{{$}}
+ // CHECK-FIXES: static constexpr auto v15 = 1.e0F16;
+ static_assert(is_same<decltype(v15), const _Float16>::value, "");
+ static_assert(v15 == 1.F16, "");
+
+ static constexpr auto v16 = 1.F16; // OK.
+ static_assert(is_same<decltype(v16), const _Float16>::value, "");
+ static_assert(v16 == 1.F16, "");
+
+ static constexpr auto v17 = 1.e0F16; // OK.
+ static_assert(is_same<decltype(v17), const _Float16>::value, "");
+ static_assert(v17 == 1.F16, "");
+}
+
+void float16_hexadecimal_literals() {
+// _Float16
+
+ static constexpr auto v13 = 0xfp0f16;
+ // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'f16', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v13 = 0xfp0f16;
+ // CHECK-MESSAGES-NEXT: ^ ~
+ // CHECK-MESSAGES-NEXT: {{^ *}}F16{{$}}
+ // CHECK-FIXES: static constexpr auto v13 = 0xfp0F16;
+ static_assert(is_same<decltype(v13), const _Float16>::value, "");
+ static_assert(v13 == 0xfp0F16, "");
+
+ static constexpr auto v14 = 0xfp0F16; // OK.
+ static_assert(is_same<decltype(v14), const _Float16>::value, "");
+ static_assert(v14 == 0xfp0F16, "");
+
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uppercase-literal-suffix-floating-point-opencl-half.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uppercase-literal-suffix-floating-point-opencl-half.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uppercase-literal-suffix-floating-point-opencl-half.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uppercase-literal-suffix-floating-point-opencl-half.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,30 @@
+// RUN: %check_clang_tidy -std=cl2.0 %s readability-uppercase-literal-suffix %t -- -- -target x86_64-pc-linux-gnu -I %S -x cl
+// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
+// RUN: clang-tidy %t.cpp -checks='-*,readability-uppercase-literal-suffix' -fix -- -target x86_64-pc-linux-gnu -I %S -std=cl2.0 -x cl
+// RUN: clang-tidy %t.cpp -checks='-*,readability-uppercase-literal-suffix' -warnings-as-errors='-*,readability-uppercase-literal-suffix' -- -target x86_64-pc-linux-gnu -I %S -std=cl2.0 -x cl
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+void floating_point_half_suffix() {
+ static half v0 = 0x0p0; // no literal
+
+ // half
+
+ static half v2 = 1.h;
+ // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: floating point literal has suffix 'h', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static half v2 = 1.h;
+ // CHECK-MESSAGES-NEXT: ^ ~
+ // CHECK-MESSAGES-NEXT: {{^ *}}H{{$}}
+ // CHECK-HIXES: static half v2 = 1.H;
+
+ static half v3 = 1.e0h;
+ // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: floating point literal has suffix 'h', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static half v3 = 1.e0h;
+ // CHECK-MESSAGES-NEXT: ^ ~
+ // CHECK-MESSAGES-NEXT: {{^ *}}H{{$}}
+ // CHECK-HIXES: static half v3 = 1.e0H;
+
+ static half v4 = 1.H; // OK.
+
+ static half v5 = 1.e0H; // OK.
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uppercase-literal-suffix-floating-point.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uppercase-literal-suffix-floating-point.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uppercase-literal-suffix-floating-point.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uppercase-literal-suffix-floating-point.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,170 @@
+// RUN: %check_clang_tidy %s readability-uppercase-literal-suffix %t -- -- -target x86_64-pc-linux-gnu -I %S
+// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
+// RUN: clang-tidy %t.cpp -checks='-*,readability-uppercase-literal-suffix' -fix -- -target x86_64-pc-linux-gnu -I %S
+// RUN: clang-tidy %t.cpp -checks='-*,readability-uppercase-literal-suffix' -warnings-as-errors='-*,readability-uppercase-literal-suffix' -- -target x86_64-pc-linux-gnu -I %S
+
+#include "readability-uppercase-literal-suffix.h"
+
+void floating_point_suffix() {
+ static constexpr auto v0 = 1.; // no literal
+ static_assert(is_same<decltype(v0), const double>::value, "");
+ static_assert(v0 == 1., "");
+
+ static constexpr auto v1 = 1.e0; // no literal
+ static_assert(is_same<decltype(v1), const double>::value, "");
+ static_assert(v1 == 1., "");
+
+ // Float
+
+ static constexpr auto v2 = 1.f;
+ // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'f', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v2 = 1.f;
+ // CHECK-MESSAGES-NEXT: ^ ~
+ // CHECK-MESSAGES-NEXT: {{^ *}}F{{$}}
+ // CHECK-FIXES: static constexpr auto v2 = 1.F;
+ static_assert(is_same<decltype(v2), const float>::value, "");
+ static_assert(v2 == 1.0F, "");
+
+ static constexpr auto v3 = 1.e0f;
+ // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'f', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v3 = 1.e0f;
+ // CHECK-MESSAGES-NEXT: ^ ~
+ // CHECK-MESSAGES-NEXT: {{^ *}}F{{$}}
+ // CHECK-FIXES: static constexpr auto v3 = 1.e0F;
+ static_assert(is_same<decltype(v3), const float>::value, "");
+ static_assert(v3 == 1.0F, "");
+
+ static constexpr auto v4 = 1.F; // OK.
+ static_assert(is_same<decltype(v4), const float>::value, "");
+ static_assert(v4 == 1.0F, "");
+
+ static constexpr auto v5 = 1.e0F; // OK.
+ static_assert(is_same<decltype(v5), const float>::value, "");
+ static_assert(v5 == 1.0F, "");
+
+ // Long double
+
+ static constexpr auto v6 = 1.l;
+ // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'l', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v6 = 1.l;
+ // CHECK-MESSAGES-NEXT: ^ ~
+ // CHECK-MESSAGES-NEXT: {{^ *}}L{{$}}
+ // CHECK-FIXES: static constexpr auto v6 = 1.L;
+ static_assert(is_same<decltype(v6), const long double>::value, "");
+ static_assert(v6 == 1., "");
+
+ static constexpr auto v7 = 1.e0l;
+ // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'l', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v7 = 1.e0l;
+ // CHECK-MESSAGES-NEXT: ^ ~
+ // CHECK-MESSAGES-NEXT: {{^ *}}L{{$}}
+ // CHECK-FIXES: static constexpr auto v7 = 1.e0L;
+ static_assert(is_same<decltype(v7), const long double>::value, "");
+ static_assert(v7 == 1., "");
+
+ static constexpr auto v8 = 1.L; // OK.
+ static_assert(is_same<decltype(v8), const long double>::value, "");
+ static_assert(v8 == 1., "");
+
+ static constexpr auto v9 = 1.e0L; // OK.
+ static_assert(is_same<decltype(v9), const long double>::value, "");
+ static_assert(v9 == 1., "");
+
+ // __float128
+
+ static constexpr auto v10 = 1.q;
+ // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'q', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v10 = 1.q;
+ // CHECK-MESSAGES-NEXT: ^ ~
+ // CHECK-MESSAGES-NEXT: {{^ *}}Q{{$}}
+ // CHECK-FIXES: static constexpr auto v10 = 1.Q;
+ static_assert(is_same<decltype(v10), const __float128>::value, "");
+ static_assert(v10 == 1., "");
+
+ static constexpr auto v11 = 1.e0q;
+ // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'q', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v11 = 1.e0q;
+ // CHECK-MESSAGES-NEXT: ^ ~
+ // CHECK-MESSAGES-NEXT: {{^ *}}Q{{$}}
+ // CHECK-FIXES: static constexpr auto v11 = 1.e0Q;
+ static_assert(is_same<decltype(v11), const __float128>::value, "");
+ static_assert(v11 == 1., "");
+
+ static constexpr auto v12 = 1.Q; // OK.
+ static_assert(is_same<decltype(v12), const __float128>::value, "");
+ static_assert(v12 == 1., "");
+
+ static constexpr auto v13 = 1.e0Q; // OK.
+ static_assert(is_same<decltype(v13), const __float128>::value, "");
+ static_assert(v13 == 1., "");
+}
+
+void floating_point_complex_suffix() {
+ // _Complex, I
+
+ static constexpr auto v14 = 1.i;
+ // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'i', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v14 = 1.i;
+ // CHECK-MESSAGES-NEXT: ^ ~
+ // CHECK-MESSAGES-NEXT: {{^ *}}I{{$}}
+ // CHECK-FIXES: static constexpr auto v14 = 1.I;
+ static_assert(is_same<decltype(v14), const _Complex double>::value, "");
+ static_assert(v14 == 1.I, "");
+
+ static constexpr auto v15 = 1.e0i;
+ // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'i', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v15 = 1.e0i;
+ // CHECK-MESSAGES-NEXT: ^ ~
+ // CHECK-MESSAGES-NEXT: {{^ *}}I{{$}}
+ // CHECK-FIXES: static constexpr auto v15 = 1.e0I;
+ static_assert(is_same<decltype(v15), const _Complex double>::value, "");
+ static_assert(v15 == 1.I, "");
+
+ static constexpr auto v16 = 1.I; // OK.
+ static_assert(is_same<decltype(v16), const _Complex double>::value, "");
+ static_assert(v16 == 1.I, "");
+
+ static constexpr auto v17 = 1.e0I; // OK.
+ static_assert(is_same<decltype(v17), const _Complex double>::value, "");
+ static_assert(v17 == 1.I, "");
+
+ // _Complex, J
+
+ static constexpr auto v18 = 1.j;
+ // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'j', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v18 = 1.j;
+ // CHECK-MESSAGES-NEXT: ^ ~
+ // CHECK-MESSAGES-NEXT: {{^ *}}J{{$}}
+ // CHECK-FIXES: static constexpr auto v18 = 1.J;
+ static_assert(is_same<decltype(v18), const _Complex double>::value, "");
+ static_assert(v18 == 1.J, "");
+
+ static constexpr auto v19 = 1.e0j;
+ // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'j', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v19 = 1.e0j;
+ // CHECK-MESSAGES-NEXT: ^ ~
+ // CHECK-MESSAGES-NEXT: {{^ *}}J{{$}}
+ // CHECK-FIXES: static constexpr auto v19 = 1.e0J;
+ static_assert(is_same<decltype(v19), const _Complex double>::value, "");
+ static_assert(v19 == 1.J, "");
+
+ static constexpr auto v20 = 1.J; // OK.
+ static_assert(is_same<decltype(v20), const _Complex double>::value, "");
+ static_assert(v20 == 1.J, "");
+
+ static constexpr auto v21 = 1.e0J; // OK.
+ static_assert(is_same<decltype(v21), const _Complex double>::value, "");
+ static_assert(v21 == 1.J, "");
+}
+
+void macros() {
+#define PASSTHROUGH(X) X
+ static constexpr auto m0 = PASSTHROUGH(1.f);
+ // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: floating point literal has suffix 'f', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto m0 = PASSTHROUGH(1.f);
+ // CHECK-MESSAGES-NEXT: ^ ~
+ // CHECK-MESSAGES-NEXT: {{^ *}}F{{$}}
+ // CHECK-FIXES: static constexpr auto m0 = PASSTHROUGH(1.F);
+ static_assert(is_same<decltype(m0), const float>::value, "");
+ static_assert(m0 == 1.0F, "");
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uppercase-literal-suffix-hexadecimal-floating-point.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uppercase-literal-suffix-hexadecimal-floating-point.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uppercase-literal-suffix-hexadecimal-floating-point.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uppercase-literal-suffix-hexadecimal-floating-point.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,140 @@
+// RUN: %check_clang_tidy %s readability-uppercase-literal-suffix %t -- -- -target x86_64-pc-linux-gnu -I %S
+// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
+// RUN: clang-tidy %t.cpp -checks='-*,readability-uppercase-literal-suffix' -fix -- -target x86_64-pc-linux-gnu -I %S
+// RUN: clang-tidy %t.cpp -checks='-*,readability-uppercase-literal-suffix' -warnings-as-errors='-*,readability-uppercase-literal-suffix' -- -target x86_64-pc-linux-gnu -I %S
+
+#include "readability-uppercase-literal-suffix.h"
+
+void floating_point_suffix() {
+ static constexpr auto v0 = 0x0p0; // no literal
+ static_assert(is_same<decltype(v0), const double>::value, "");
+ static_assert(v0 == 0, "");
+
+ // Float
+
+ static constexpr auto v1 = 0xfp0f;
+ // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'f', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v1 = 0xfp0f;
+ // CHECK-MESSAGES-NEXT: ^ ~
+ // CHECK-MESSAGES-NEXT: {{^ *}}F{{$}}
+ // CHECK-FIXES: static constexpr auto v1 = 0xfp0F;
+ static_assert(is_same<decltype(v1), const float>::value, "");
+ static_assert(v1 == 15, "");
+
+ static constexpr auto v2 = 0xfp0F; // OK
+ static_assert(is_same<decltype(v2), const float>::value, "");
+ static_assert(v2 == 15, "");
+
+ static constexpr auto v3 = 0xfP0f;
+ // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'f', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v3 = 0xfP0f;
+ // CHECK-MESSAGES-NEXT: ^ ~
+ // CHECK-MESSAGES-NEXT: {{^ *}}F{{$}}
+ // CHECK-FIXES: static constexpr auto v3 = 0xfP0F;
+ static_assert(is_same<decltype(v3), const float>::value, "");
+ static_assert(v3 == 15, "");
+
+ static constexpr auto v4 = 0xfP0F; // OK
+ static_assert(is_same<decltype(v4), const float>::value, "");
+ static_assert(v4 == 15, "");
+
+ static constexpr auto v5 = 0xFP0f;
+ // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'f', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v5 = 0xFP0f;
+ // CHECK-MESSAGES-NEXT: ^ ~
+ // CHECK-MESSAGES-NEXT: {{^ *}}F{{$}}
+ // CHECK-FIXES: static constexpr auto v5 = 0xFP0F;
+ static_assert(is_same<decltype(v5), const float>::value, "");
+ static_assert(v5 == 15, "");
+
+ static constexpr auto v6 = 0xFP0F; // OK
+ static_assert(is_same<decltype(v6), const float>::value, "");
+ static_assert(v6 == 15, "");
+
+ static constexpr auto v7 = 0xFp0f;
+ // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'f', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v7 = 0xFp0f;
+ // CHECK-MESSAGES-NEXT: ^ ~
+ // CHECK-MESSAGES-NEXT: {{^ *}}F{{$}}
+ // CHECK-FIXES: static constexpr auto v7 = 0xFp0F;
+ static_assert(is_same<decltype(v7), const float>::value, "");
+ static_assert(v7 == 15, "");
+
+ static constexpr auto v8 = 0xFp0F; // OK
+ static_assert(is_same<decltype(v8), const float>::value, "");
+ static_assert(v8 == 15, "");
+
+ // long double
+
+ static constexpr auto v9 = 0xfp0l;
+ // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'l', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v9 = 0xfp0l;
+ // CHECK-MESSAGES-NEXT: ^ ~
+ // CHECK-MESSAGES-NEXT: {{^ *}}L{{$}}
+ // CHECK-FIXES: static constexpr auto v9 = 0xfp0L;
+ static_assert(is_same<decltype(v9), const long double>::value, "");
+ static_assert(v9 == 0xfp0, "");
+
+ static constexpr auto v10 = 0xfp0L; // OK.
+ static_assert(is_same<decltype(v10), const long double>::value, "");
+ static_assert(v10 == 0xfp0, "");
+
+ // __float128
+
+ static constexpr auto v11 = 0xfp0q;
+ // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'q', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v11 = 0xfp0q;
+ // CHECK-MESSAGES-NEXT: ^ ~
+ // CHECK-MESSAGES-NEXT: {{^ *}}Q{{$}}
+ // CHECK-FIXES: static constexpr auto v11 = 0xfp0Q;
+ static_assert(is_same<decltype(v11), const __float128>::value, "");
+ static_assert(v11 == 0xfp0, "");
+
+ static constexpr auto v12 = 0xfp0Q; // OK.
+ static_assert(is_same<decltype(v12), const __float128>::value, "");
+ static_assert(v12 == 0xfp0, "");
+}
+
+void floating_point_complex_suffix() {
+ // _Complex, I
+
+ static constexpr auto v14 = 0xfp0i;
+ // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'i', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v14 = 0xfp0i;
+ // CHECK-MESSAGES-NEXT: ^ ~
+ // CHECK-MESSAGES-NEXT: {{^ *}}I{{$}}
+ // CHECK-FIXES: static constexpr auto v14 = 0xfp0I;
+ static_assert(is_same<decltype(v14), const _Complex double>::value, "");
+ static_assert(v14 == 0xfp0I, "");
+
+ static constexpr auto v16 = 0xfp0I; // OK.
+ static_assert(is_same<decltype(v16), const _Complex double>::value, "");
+ static_assert(v16 == 0xfp0I, "");
+
+ // _Complex, J
+
+ static constexpr auto v18 = 0xfp0j;
+ // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'j', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v18 = 0xfp0j;
+ // CHECK-MESSAGES-NEXT: ^ ~
+ // CHECK-MESSAGES-NEXT: {{^ *}}J{{$}}
+ // CHECK-FIXES: static constexpr auto v18 = 0xfp0J;
+ static_assert(is_same<decltype(v18), const _Complex double>::value, "");
+ static_assert(v18 == 0xfp0J, "");
+
+ static constexpr auto v20 = 0xfp0J; // OK.
+ static_assert(is_same<decltype(v20), const _Complex double>::value, "");
+ static_assert(v20 == 0xfp0J, "");
+}
+
+void macros() {
+#define PASSTHROUGH(X) X
+ static constexpr auto m0 = PASSTHROUGH(0x0p0f);
+ // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: floating point literal has suffix 'f', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto m0 = PASSTHROUGH(0x0p0f);
+ // CHECK-MESSAGES-NEXT: ^ ~
+ // CHECK-MESSAGES-NEXT: {{^ *}}F{{$}}
+ // CHECK-FIXES: static constexpr auto m0 = PASSTHROUGH(0x0p0F);
+ static_assert(is_same<decltype(m0), const float>::value, "");
+ static_assert(m0 == 0x0p0F, "");
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uppercase-literal-suffix-integer-custom-list.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uppercase-literal-suffix-integer-custom-list.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uppercase-literal-suffix-integer-custom-list.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uppercase-literal-suffix-integer-custom-list.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,130 @@
+// RUN: %check_clang_tidy %s readability-uppercase-literal-suffix %t -- -config="{CheckOptions: [{key: readability-uppercase-literal-suffix.NewSuffixes, value: 'L;uL'}]}" -- -I %S
+// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
+// RUN: clang-tidy %t.cpp -checks='-*,readability-uppercase-literal-suffix' -fix -config="{CheckOptions: [{key: readability-uppercase-literal-suffix.NewSuffixes, value: 'L;uL'}]}" -- -I %S
+// RUN: clang-tidy %t.cpp -checks='-*,readability-uppercase-literal-suffix' -warnings-as-errors='-*,readability-uppercase-literal-suffix' -config="{CheckOptions: [{key: readability-uppercase-literal-suffix.NewSuffixes, value: 'L;uL'}]}" -- -I %S
+
+#include "readability-uppercase-literal-suffix.h"
+
+void integer_suffix() {
+ // Unsigned
+
+ static constexpr auto v3 = 1u; // OK.
+ static_assert(is_same<decltype(v3), const unsigned int>::value, "");
+ static_assert(v3 == 1, "");
+
+ static constexpr auto v4 = 1U; // OK.
+ static_assert(is_same<decltype(v4), const unsigned int>::value, "");
+ static_assert(v4 == 1, "");
+
+ // Long
+
+ static constexpr auto v5 = 1l;
+ // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'l', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v5 = 1l;
+ // CHECK-MESSAGES-NEXT: ^~
+ // CHECK-MESSAGES-NEXT: {{^ *}}L{{$}}
+ // CHECK-FIXES: static constexpr auto v5 = 1L;
+ static_assert(is_same<decltype(v5), const long>::value, "");
+ static_assert(v5 == 1, "");
+
+ static constexpr auto v6 = 1L; // OK.
+ static_assert(is_same<decltype(v6), const long>::value, "");
+ static_assert(v6 == 1, "");
+
+ // Long Long
+
+ static constexpr auto v7 = 1ll; // OK.
+ static_assert(is_same<decltype(v7), const long long>::value, "");
+ static_assert(v7 == 1, "");
+
+ static constexpr auto v8 = 1LL; // OK.
+ static_assert(is_same<decltype(v8), const long long>::value, "");
+ static_assert(v8 == 1, "");
+
+ // Unsigned Long
+
+ static constexpr auto v9 = 1ul;
+ // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'ul', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v9 = 1ul;
+ // CHECK-MESSAGES-NEXT: ^~~
+ // CHECK-MESSAGES-NEXT: {{^ *}}uL{{$}}
+ // CHECK-FIXES: static constexpr auto v9 = 1uL;
+ static_assert(is_same<decltype(v9), const unsigned long>::value, "");
+ static_assert(v9 == 1, "");
+
+ static constexpr auto v10 = 1uL; // OK.
+ static_assert(is_same<decltype(v10), const unsigned long>::value, "");
+ static_assert(v10 == 1, "");
+
+ static constexpr auto v11 = 1Ul;
+ // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'Ul', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v11 = 1Ul;
+ // CHECK-MESSAGES-NEXT: ^~~
+ // CHECK-MESSAGES-NEXT: {{^ *}}uL{{$}}
+ // CHECK-FIXES: static constexpr auto v11 = 1uL;
+ static_assert(is_same<decltype(v11), const unsigned long>::value, "");
+ static_assert(v11 == 1, "");
+
+ static constexpr auto v12 = 1UL; // OK.
+ // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'UL', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v12 = 1UL;
+ // CHECK-MESSAGES-NEXT: ^~~
+ // CHECK-MESSAGES-NEXT: {{^ *}}uL{{$}}
+ // CHECK-FIXES: static constexpr auto v12 = 1uL;
+ static_assert(is_same<decltype(v12), const unsigned long>::value, "");
+ static_assert(v12 == 1, "");
+
+ // Long Unsigned
+
+ static constexpr auto v13 = 1lu; // OK.
+ static_assert(is_same<decltype(v13), const unsigned long>::value, "");
+ static_assert(v13 == 1, "");
+
+ static constexpr auto v14 = 1Lu; // OK.
+ static_assert(is_same<decltype(v14), const unsigned long>::value, "");
+ static_assert(v14 == 1, "");
+
+ static constexpr auto v15 = 1lU; // OK.
+ static_assert(is_same<decltype(v15), const unsigned long>::value, "");
+ static_assert(v15 == 1, "");
+
+ static constexpr auto v16 = 1LU; // OK.
+ static_assert(is_same<decltype(v16), const unsigned long>::value, "");
+ static_assert(v16 == 1, "");
+
+ // Unsigned Long Long
+
+ static constexpr auto v17 = 1ull; // OK.
+ static_assert(is_same<decltype(v17), const unsigned long long>::value, "");
+ static_assert(v17 == 1, "");
+
+ static constexpr auto v18 = 1uLL; // OK.
+ static_assert(is_same<decltype(v18), const unsigned long long>::value, "");
+ static_assert(v18 == 1, "");
+
+ static constexpr auto v19 = 1Ull; // OK.
+ static_assert(is_same<decltype(v19), const unsigned long long>::value, "");
+ static_assert(v19 == 1, "");
+
+ static constexpr auto v20 = 1ULL; // OK.
+ static_assert(is_same<decltype(v20), const unsigned long long>::value, "");
+ static_assert(v20 == 1, "");
+
+ // Long Long Unsigned
+
+ static constexpr auto v21 = 1llu; // OK.
+ static_assert(is_same<decltype(v21), const unsigned long long>::value, "");
+ static_assert(v21 == 1, "");
+
+ static constexpr auto v22 = 1LLu; // OK.
+ static_assert(is_same<decltype(v22), const unsigned long long>::value, "");
+ static_assert(v22 == 1, "");
+
+ static constexpr auto v23 = 1llU; // OK.
+ static_assert(is_same<decltype(v23), const unsigned long long>::value, "");
+ static_assert(v23 == 1, "");
+
+ static constexpr auto v24 = 1LLU; // OK.
+ static_assert(is_same<decltype(v24), const unsigned long long>::value, "");
+ static_assert(v24 == 1, "");
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uppercase-literal-suffix-integer-macro.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uppercase-literal-suffix-integer-macro.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uppercase-literal-suffix-integer-macro.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uppercase-literal-suffix-integer-macro.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,27 @@
+// RUN: %check_clang_tidy %s readability-uppercase-literal-suffix %t -- \
+// RUN: -config="{CheckOptions: [{key: readability-uppercase-literal-suffix.IgnoreMacros, value: 0}]}" \
+// RUN: -- -I %S
+
+void macros() {
+#define INMACRO(X) 1.f
+ static constexpr auto m1 = INMACRO();
+ // CHECK-NOTES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'f', which is not uppercase
+ // CHECK-NOTES: :[[@LINE-3]]:20: note: expanded from macro 'INMACRO'
+ // CHECK-FIXES: #define INMACRO(X) 1.f
+ // CHECK-FIXES: static constexpr auto m1 = INMACRO();
+ // ^ so no fix-its here.
+}
+
+void horrible_macros() {
+#define MAKE_UNSIGNED(x) x##u
+#define ONE MAKE_UNSIGNED(1)
+ static constexpr auto hm0 = ONE;
+ // CHECK-NOTES: :[[@LINE-1]]:31: warning: integer literal has suffix 'u', which is not uppercase
+ // CHECK-NOTES: :[[@LINE-3]]:13: note: expanded from macro 'ONE'
+ // CHECK-NOTES: :[[@LINE-5]]:26: note: expanded from macro 'MAKE_UNSIGNED'
+ // CHECK-NOTES: note: expanded from here
+ // CHECK-FIXES: #define MAKE_UNSIGNED(x) x##u
+ // CHECK-FIXES: #define ONE MAKE_UNSIGNED(1)
+ // CHECK-FIXES: static constexpr auto hm0 = ONE;
+ // Certainly no fix-its.
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uppercase-literal-suffix-integer-ms.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uppercase-literal-suffix-integer-ms.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uppercase-literal-suffix-integer-ms.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uppercase-literal-suffix-integer-ms.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,77 @@
+// RUN: %check_clang_tidy %s readability-uppercase-literal-suffix %t -- -- -target x86_64-pc-linux-gnu -I %S -fms-extensions
+// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
+// RUN: clang-tidy %t.cpp -checks='-*,readability-uppercase-literal-suffix' -fix -- -target x86_64-pc-linux-gnu -I %S -fms-extensions
+// RUN: clang-tidy %t.cpp -checks='-*,readability-uppercase-literal-suffix' -warnings-as-errors='-*,readability-uppercase-literal-suffix' -- -target x86_64-pc-linux-gnu -I %S -fms-extensions
+
+#include "readability-uppercase-literal-suffix.h"
+
+void integer_suffix() {
+ static constexpr auto v0 = __LINE__; // synthetic
+ static_assert(v0 == 9 || v0 == 5, "");
+
+ static constexpr auto v1 = __cplusplus; // synthetic, long
+
+ static constexpr auto v2 = 1; // no literal
+ static_assert(is_same<decltype(v2), const int>::value, "");
+ static_assert(v2 == 1, "");
+
+ // i32
+
+ static constexpr auto v3 = 1i32;
+ // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'i32', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v3 = 1i32;
+ // CHECK-MESSAGES-NEXT: ^~
+ // CHECK-MESSAGES-NEXT: {{^ *}}I32{{$}}
+ // CHECK-FIXES: static constexpr auto v3 = 1I32;
+ static_assert(is_same<decltype(v3), const int>::value, "");
+ static_assert(v3 == 1I32, "");
+
+ static constexpr auto v4 = 1I32; // OK.
+ static_assert(is_same<decltype(v4), const int>::value, "");
+ static_assert(v4 == 1I32, "");
+
+ // i64
+
+ static constexpr auto v5 = 1i64;
+ // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'i64', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v5 = 1i64;
+ // CHECK-MESSAGES-NEXT: ^~
+ // CHECK-MESSAGES-NEXT: {{^ *}}I64{{$}}
+ // CHECK-FIXES: static constexpr auto v5 = 1I64;
+ static_assert(is_same<decltype(v5), const long int>::value, "");
+ static_assert(v5 == 1I64, "");
+
+ static constexpr auto v6 = 1I64; // OK.
+ static_assert(is_same<decltype(v6), const long int>::value, "");
+ static_assert(v6 == 1I64, "");
+
+ // i16
+
+ static constexpr auto v7 = 1i16;
+ // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'i16', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v7 = 1i16;
+ // CHECK-MESSAGES-NEXT: ^~
+ // CHECK-MESSAGES-NEXT: {{^ *}}I16{{$}}
+ // CHECK-FIXES: static constexpr auto v7 = 1I16;
+ static_assert(is_same<decltype(v7), const short>::value, "");
+ static_assert(v7 == 1I16, "");
+
+ static constexpr auto v8 = 1I16; // OK.
+ static_assert(is_same<decltype(v8), const short>::value, "");
+ static_assert(v8 == 1I16, "");
+
+ // i8
+
+ static constexpr auto v9 = 1i8;
+ // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'i8', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v9 = 1i8;
+ // CHECK-MESSAGES-NEXT: ^~
+ // CHECK-MESSAGES-NEXT: {{^ *}}I8{{$}}
+ // CHECK-FIXES: static constexpr auto v9 = 1I8;
+ static_assert(is_same<decltype(v9), const char>::value, "");
+ static_assert(v9 == 1I8, "");
+
+ static constexpr auto v10 = 1I8; // OK.
+ static_assert(is_same<decltype(v10), const char>::value, "");
+ static_assert(v10 == 1I8, "");
+}
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uppercase-literal-suffix-integer.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uppercase-literal-suffix-integer.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uppercase-literal-suffix-integer.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uppercase-literal-suffix-integer.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,272 @@
+// RUN: %check_clang_tidy %s readability-uppercase-literal-suffix %t -- -- -I %S
+// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
+// RUN: clang-tidy %t.cpp -checks='-*,readability-uppercase-literal-suffix' -fix -- -I %S
+// RUN: clang-tidy %t.cpp -checks='-*,readability-uppercase-literal-suffix' -warnings-as-errors='-*,readability-uppercase-literal-suffix' -- -I %S
+
+#include "readability-uppercase-literal-suffix.h"
+
+void integer_suffix() {
+ static constexpr auto v0 = __LINE__; // synthetic
+ static_assert(v0 == 9 || v0 == 5, "");
+
+ static constexpr auto v1 = __cplusplus; // synthetic, long
+
+ static constexpr auto v2 = 1; // no literal
+ static_assert(is_same<decltype(v2), const int>::value, "");
+ static_assert(v2 == 1, "");
+
+ // Unsigned
+
+ static constexpr auto v3 = 1u;
+ // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'u', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v3 = 1u;
+ // CHECK-MESSAGES-NEXT: ^~
+ // CHECK-MESSAGES-NEXT: {{^ *}}U{{$}}
+ // CHECK-FIXES: static constexpr auto v3 = 1U;
+ static_assert(is_same<decltype(v3), const unsigned int>::value, "");
+ static_assert(v3 == 1, "");
+
+ static constexpr auto v4 = 1U; // OK.
+ static_assert(is_same<decltype(v4), const unsigned int>::value, "");
+ static_assert(v4 == 1, "");
+
+ // Long
+
+ static constexpr auto v5 = 1l;
+ // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'l', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v5 = 1l;
+ // CHECK-MESSAGES-NEXT: ^~
+ // CHECK-MESSAGES-NEXT: {{^ *}}L{{$}}
+ // CHECK-FIXES: static constexpr auto v5 = 1L;
+ static_assert(is_same<decltype(v5), const long>::value, "");
+ static_assert(v5 == 1, "");
+
+ static constexpr auto v6 = 1L; // OK.
+ static_assert(is_same<decltype(v6), const long>::value, "");
+ static_assert(v6 == 1, "");
+
+ // Long Long
+
+ static constexpr auto v7 = 1ll;
+ // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'll', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v7 = 1ll;
+ // CHECK-MESSAGES-NEXT: ^~~
+ // CHECK-MESSAGES-NEXT: {{^ *}}LL{{$}}
+ // CHECK-FIXES: static constexpr auto v7 = 1LL;
+ static_assert(is_same<decltype(v7), const long long>::value, "");
+ static_assert(v7 == 1, "");
+
+ static constexpr auto v8 = 1LL; // OK.
+ static_assert(is_same<decltype(v8), const long long>::value, "");
+ static_assert(v8 == 1, "");
+
+ // Unsigned Long
+
+ static constexpr auto v9 = 1ul;
+ // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'ul', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v9 = 1ul;
+ // CHECK-MESSAGES-NEXT: ^~~
+ // CHECK-MESSAGES-NEXT: {{^ *}}UL{{$}}
+ // CHECK-FIXES: static constexpr auto v9 = 1UL;
+ static_assert(is_same<decltype(v9), const unsigned long>::value, "");
+ static_assert(v9 == 1, "");
+
+ static constexpr auto v10 = 1uL;
+ // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'uL', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v10 = 1uL;
+ // CHECK-MESSAGES-NEXT: ^~~
+ // CHECK-MESSAGES-NEXT: {{^ *}}UL{{$}}
+ // CHECK-FIXES: static constexpr auto v10 = 1UL;
+ static_assert(is_same<decltype(v10), const unsigned long>::value, "");
+ static_assert(v10 == 1, "");
+
+ static constexpr auto v11 = 1Ul;
+ // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'Ul', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v11 = 1Ul;
+ // CHECK-MESSAGES-NEXT: ^~~
+ // CHECK-MESSAGES-NEXT: {{^ *}}UL{{$}}
+ // CHECK-FIXES: static constexpr auto v11 = 1UL;
+ static_assert(is_same<decltype(v11), const unsigned long>::value, "");
+ static_assert(v11 == 1, "");
+
+ static constexpr auto v12 = 1UL; // OK.
+ static_assert(is_same<decltype(v12), const unsigned long>::value, "");
+ static_assert(v12 == 1, "");
+
+ // Long Unsigned
+
+ static constexpr auto v13 = 1lu;
+ // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'lu', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v13 = 1lu;
+ // CHECK-MESSAGES-NEXT: ^~~
+ // CHECK-MESSAGES-NEXT: {{^ *}}LU{{$}}
+ // CHECK-FIXES: static constexpr auto v13 = 1LU;
+ static_assert(is_same<decltype(v13), const unsigned long>::value, "");
+ static_assert(v13 == 1, "");
+
+ static constexpr auto v14 = 1Lu;
+ // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'Lu', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v14 = 1Lu;
+ // CHECK-MESSAGES-NEXT: ^~~
+ // CHECK-MESSAGES-NEXT: {{^ *}}LU{{$}}
+ // CHECK-FIXES: static constexpr auto v14 = 1LU;
+ static_assert(is_same<decltype(v14), const unsigned long>::value, "");
+ static_assert(v14 == 1, "");
+
+ static constexpr auto v15 = 1lU;
+ // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'lU', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v15 = 1lU;
+ // CHECK-MESSAGES-NEXT: ^~~
+ // CHECK-MESSAGES-NEXT: {{^ *}}LU{{$}}
+ // CHECK-FIXES: static constexpr auto v15 = 1LU;
+ static_assert(is_same<decltype(v15), const unsigned long>::value, "");
+ static_assert(v15 == 1, "");
+
+ static constexpr auto v16 = 1LU; // OK.
+ static_assert(is_same<decltype(v16), const unsigned long>::value, "");
+ static_assert(v16 == 1, "");
+
+ // Unsigned Long Long
+
+ static constexpr auto v17 = 1ull;
+ // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'ull', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v17 = 1ull;
+ // CHECK-MESSAGES-NEXT: ^~~~
+ // CHECK-MESSAGES-NEXT: {{^ *}}ULL{{$}}
+ // CHECK-FIXES: static constexpr auto v17 = 1ULL;
+ static_assert(is_same<decltype(v17), const unsigned long long>::value, "");
+ static_assert(v17 == 1, "");
+
+ static constexpr auto v18 = 1uLL;
+ // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'uLL', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v18 = 1uLL;
+ // CHECK-MESSAGES-NEXT: ^~~~
+ // CHECK-MESSAGES-NEXT: {{^ *}}ULL{{$}}
+ // CHECK-FIXES: static constexpr auto v18 = 1ULL;
+ static_assert(is_same<decltype(v18), const unsigned long long>::value, "");
+ static_assert(v18 == 1, "");
+
+ static constexpr auto v19 = 1Ull;
+ // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'Ull', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v19 = 1Ull;
+ // CHECK-MESSAGES-NEXT: ^~~~
+ // CHECK-MESSAGES-NEXT: {{^ *}}ULL{{$}}
+ // CHECK-FIXES: static constexpr auto v19 = 1ULL;
+ static_assert(is_same<decltype(v19), const unsigned long long>::value, "");
+ static_assert(v19 == 1, "");
+
+ static constexpr auto v20 = 1ULL; // OK.
+ static_assert(is_same<decltype(v20), const unsigned long long>::value, "");
+ static_assert(v20 == 1, "");
+
+ // Long Long Unsigned
+
+ static constexpr auto v21 = 1llu;
+ // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'llu', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v21 = 1llu;
+ // CHECK-MESSAGES-NEXT: ^~~~
+ // CHECK-MESSAGES-NEXT: {{^ *}}LLU{{$}}
+ // CHECK-FIXES: static constexpr auto v21 = 1LLU;
+ static_assert(is_same<decltype(v21), const unsigned long long>::value, "");
+ static_assert(v21 == 1, "");
+
+ static constexpr auto v22 = 1LLu;
+ // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'LLu', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v22 = 1LLu;
+ // CHECK-MESSAGES-NEXT: ^~~~
+ // CHECK-MESSAGES-NEXT: {{^ *}}LLU{{$}}
+ // CHECK-FIXES: static constexpr auto v22 = 1LLU;
+ static_assert(is_same<decltype(v22), const unsigned long long>::value, "");
+ static_assert(v22 == 1, "");
+
+ static constexpr auto v23 = 1llU;
+ // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'llU', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v23 = 1llU;
+ // CHECK-MESSAGES-NEXT: ^~~~
+ // CHECK-MESSAGES-NEXT: {{^ *}}LLU{{$}}
+ // CHECK-FIXES: static constexpr auto v23 = 1LLU;
+ static_assert(is_same<decltype(v23), const unsigned long long>::value, "");
+ static_assert(v23 == 1, "");
+
+ static constexpr auto v24 = 1LLU; // OK.
+ static_assert(is_same<decltype(v24), const unsigned long long>::value, "");
+ static_assert(v24 == 1, "");
+}
+
+void integer_complex_suffix() {
+ // _Complex, I
+
+ static constexpr auto v25 = 1i;
+ // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'i', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v25 = 1i;
+ // CHECK-MESSAGES-NEXT: ^~
+ // CHECK-MESSAGES-NEXT: {{^ *}}I{{$}}
+ // CHECK-FIXES: static constexpr auto v25 = 1I;
+ static_assert(is_same<decltype(v25), const _Complex int>::value, "");
+ static_assert(v25 == 1I, "");
+
+ static constexpr auto v26 = 1I; // OK.
+ static_assert(is_same<decltype(v26), const _Complex int>::value, "");
+ static_assert(v26 == 1I, "");
+
+ // _Complex, J
+
+ static constexpr auto v27 = 1j;
+ // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'j', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto v27 = 1j;
+ // CHECK-MESSAGES-NEXT: ^~
+ // CHECK-MESSAGES-NEXT: {{^ *}}J{{$}}
+ // CHECK-FIXES: static constexpr auto v27 = 1J;
+ static_assert(is_same<decltype(v27), const _Complex int>::value, "");
+ static_assert(v27 == 1J, "");
+
+ static constexpr auto v28 = 1J; // OK.
+ static_assert(is_same<decltype(v28), const _Complex int>::value, "");
+ static_assert(v28 == 1J, "");
+}
+
+void macros() {
+#define PASSTHROUGH(X) X
+ static constexpr auto m0 = PASSTHROUGH(1u);
+ // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: integer literal has suffix 'u', which is not uppercase
+ // CHECK-MESSAGES-NEXT: static constexpr auto m0 = PASSTHROUGH(1u);
+ // CHECK-MESSAGES-NEXT: ^~
+ // CHECK-MESSAGES-NEXT: {{^ *}}U{{$}}
+ // CHECK-FIXES: static constexpr auto m0 = PASSTHROUGH(1U);
+ static_assert(is_same<decltype(m0), const unsigned int>::value, "");
+ static_assert(m0 == 1, "");
+
+ // This location is inside a macro, no warning on that by default.
+#define MACRO 1u
+ int foo = MACRO;
+}
+
+// Check that user-defined literals do not cause any diags.
+
+unsigned long long int operator"" _ull(unsigned long long int);
+void user_defined_literals() {
+ 1_ull;
+}
+
+template <unsigned alignment>
+void template_test() {
+ static_assert(alignment, "");
+}
+void actual_template_test() {
+ template_test<4>();
+}
+
+const int table[6] = {};
+void read_test() {
+ for (auto i : table) {
+ }
+}
+
+namespace {
+enum a { b };
+constexpr bool operator&(a, a) { return int(); }
+template <a l>
+void c() { l &a(); }
+void d();
+void d() { c<b>(); }
+} // namespace
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uppercase-literal-suffix.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uppercase-literal-suffix.h?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uppercase-literal-suffix.h (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/readability-uppercase-literal-suffix.h Fri Oct 11 05:05:42 2019
@@ -0,0 +1,16 @@
+template <class T, T v>
+struct integral_constant {
+ static constexpr T value = v;
+ typedef T value_type;
+ typedef integral_constant type; // using injected-class-name
+ constexpr operator value_type() const noexcept { return value; }
+};
+
+using false_type = integral_constant<bool, false>;
+using true_type = integral_constant<bool, true>;
+
+template <class T, class U>
+struct is_same : false_type {};
+
+template <class T>
+struct is_same<T, T> : true_type {};
Added: clang-tools-extra/trunk/test/clang-tidy/checkers/zircon-temporary-objects.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/zircon-temporary-objects.cpp?rev=374540&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/checkers/zircon-temporary-objects.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/zircon-temporary-objects.cpp Fri Oct 11 05:05:42 2019
@@ -0,0 +1,108 @@
+// RUN: %check_clang_tidy %s zircon-temporary-objects %t -- \
+// RUN: -config="{CheckOptions: [{key: zircon-temporary-objects.Names, value: 'Foo;NS::Bar'}]}" \
+// RUN: -header-filter=.*
+
+// Should flag instances of Foo, NS::Bar.
+
+class Foo {
+public:
+ Foo() = default;
+ Foo(int Val) : Val(Val){};
+
+private:
+ int Val;
+};
+
+namespace NS {
+
+class Bar {
+public:
+ Bar() = default;
+ Bar(int Val) : Val(Val){};
+
+private:
+ int Val;
+};
+
+} // namespace NS
+
+class Bar {
+public:
+ Bar() = default;
+ Bar(int Val) : Val(Val){};
+
+private:
+ int Val;
+};
+
+int func(Foo F) { return 1; };
+
+int main() {
+ Foo F;
+ Foo *F2 = new Foo();
+ new Foo();
+ Foo();
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: creating a temporary object of type 'Foo' is prohibited
+ Foo F3 = Foo();
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: creating a temporary object of type 'Foo' is prohibited
+
+ Bar();
+ NS::Bar();
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: creating a temporary object of type 'NS::Bar' is prohibited
+
+ int A = func(Foo());
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: creating a temporary object of type 'Foo' is prohibited
+
+ Foo F4(0);
+ Foo *F5 = new Foo(0);
+ new Foo(0);
+ Foo(0);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: creating a temporary object of type 'Foo' is prohibited
+ Foo F6 = Foo(0);
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: creating a temporary object of type 'Foo' is prohibited
+
+ Bar(0);
+ NS::Bar(0);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: creating a temporary object of type 'NS::Bar' is prohibited
+
+ int B = func(Foo(0));
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: creating a temporary object of type 'Foo' is prohibited
+}
+
+namespace NS {
+
+void f() {
+ Bar();
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: creating a temporary object of type 'NS::Bar' is prohibited
+ Bar(0);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: creating a temporary object of type 'NS::Bar' is prohibited
+}
+
+} // namespace NS
+
+template <typename Ty>
+Ty make_ty() { return Ty(); }
+// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: creating a temporary object of type 'Foo' is prohibited
+// CHECK-MESSAGES: :[[@LINE-2]]:23: warning: creating a temporary object of type 'NS::Bar' is prohibited
+
+void ty_func() {
+ make_ty<Bar>();
+ make_ty<NS::Bar>();
+ make_ty<Foo>();
+}
+
+// Inheriting the disallowed class does not trigger the check.
+
+class Bingo : NS::Bar {}; // Not explicitly disallowed
+
+void f2() {
+ Bingo();
+}
+
+template <typename Ty>
+class Quux : Ty {};
+
+void f3() {
+ Quux<NS::Bar>();
+ Quux<Bar>();
+}
Removed: clang-tools-extra/trunk/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp (removed)
@@ -1,5 +0,0 @@
-// RUN: clang-tidy %s -checks=-*,modernize-use-nullptr -- | count 0
-
-#if !defined(__clang_analyzer__)
-#error __clang_analyzer__ is not defined
-#endif
Removed: clang-tools-extra/trunk/test/clang-tidy/clang-tidy-diff.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/clang-tidy-diff.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/clang-tidy-diff.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/clang-tidy-diff.cpp (removed)
@@ -1,26 +0,0 @@
-// REQUIRES: shell
-// RUN: sed 's/placeholder_for_f/f/' %s > %t.cpp
-// RUN: clang-tidy -checks=-*,modernize-use-override %t.cpp -- -std=c++11 | FileCheck -check-prefix=CHECK-SANITY %s
-// RUN: not diff -U0 %s %t.cpp | %clang_tidy_diff -checks=-*,modernize-use-override -- -std=c++11 2>&1 | FileCheck %s
-// RUN: not diff -U0 %s %t.cpp | %clang_tidy_diff -checks=-*,modernize-use-override -quiet -- -std=c++11 2>&1 | FileCheck -check-prefix=CHECK-QUIET %s
-// RUN: mkdir -p %T/compilation-database-test/
-// RUN: echo '[{"directory": "%T", "command": "clang++ -o test.o -std=c++11 %t.cpp", "file": "%t.cpp"}]' > %T/compilation-database-test/compile_commands.json
-// RUN: not diff -U0 %s %t.cpp | %clang_tidy_diff -checks=-*,modernize-use-override -path %T/compilation-database-test 2>&1 | FileCheck -check-prefix=CHECK %s
-struct A {
- virtual void f() {}
- virtual void g() {}
-};
-// CHECK-NOT: warning:
-// CHECK-QUIET-NOT: warning:
-struct B : public A {
- void placeholder_for_f() {}
-// CHECK-SANITY: [[@LINE-1]]:8: warning: annotate this
-// CHECK: [[@LINE-2]]:8: warning: annotate this
-// CHECK-QUIET: [[@LINE-3]]:8: warning: annotate this
- void g() {}
-// CHECK-SANITY: [[@LINE-1]]:8: warning: annotate this
-// CHECK-NOT: warning:
-// CHECK-QUIET-NOT: warning:
-};
-// CHECK-SANITY-NOT: Suppressed
-// CHECK-QUIET-NOT: Suppressed
Removed: clang-tools-extra/trunk/test/clang-tidy/clang-tidy-enable-check-profile-one-tu.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/clang-tidy-enable-check-profile-one-tu.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/clang-tidy-enable-check-profile-one-tu.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/clang-tidy-enable-check-profile-one-tu.cpp (removed)
@@ -1,24 +0,0 @@
-// RUN: clang-tidy -enable-check-profile -checks='-*,readability-function-size' %s -- 2>&1 | FileCheck --match-full-lines -implicit-check-not='{{warning:|error:}}' %s
-
-// CHECK: ===-------------------------------------------------------------------------===
-// CHECK-NEXT: clang-tidy checks profiling
-// CHECK-NEXT: ===-------------------------------------------------------------------------===
-// CHECK-NEXT: Total Execution Time: {{.*}} seconds ({{.*}} wall clock)
-
-// CHECK: {{.*}} --- Name ---
-// CHECK-NEXT: {{.*}} readability-function-size
-// CHECK-NEXT: {{.*}} Total
-
-// CHECK-NOT: ===-------------------------------------------------------------------------===
-// CHECK-NOT: clang-tidy checks profiling
-// CHECK-NOT: ===-------------------------------------------------------------------------===
-// CHECK-NOT: Total Execution Time: {{.*}} seconds ({{.*}} wall clock)
-
-// CHECK-NOT: {{.*}} --- Name ---
-// CHECK-NOT: {{.*}} readability-function-size
-// CHECK-NOT: {{.*}} Total
-
-class A {
- A() {}
- ~A() {}
-};
Removed: clang-tools-extra/trunk/test/clang-tidy/clang-tidy-enable-check-profile-two-tu.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/clang-tidy-enable-check-profile-two-tu.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/clang-tidy-enable-check-profile-two-tu.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/clang-tidy-enable-check-profile-two-tu.cpp (removed)
@@ -1,33 +0,0 @@
-// RUN: clang-tidy -enable-check-profile -checks='-*,readability-function-size' %s %s -- 2>&1 | FileCheck --match-full-lines -implicit-check-not='{{warning:|error:}}' %s
-
-// CHECK: ===-------------------------------------------------------------------------===
-// CHECK-NEXT: clang-tidy checks profiling
-// CHECK-NEXT: ===-------------------------------------------------------------------------===
-// CHECK-NEXT: Total Execution Time: {{.*}} seconds ({{.*}} wall clock)
-
-// CHECK: {{.*}} --- Name ---
-// CHECK-NEXT: {{.*}} readability-function-size
-// CHECK-NEXT: {{.*}} Total
-
-// CHECK: ===-------------------------------------------------------------------------===
-// CHECK-NEXT: clang-tidy checks profiling
-// CHECK-NEXT: ===-------------------------------------------------------------------------===
-// CHECK-NEXT: Total Execution Time: {{.*}} seconds ({{.*}} wall clock)
-
-// CHECK: {{.*}} --- Name ---
-// CHECK-NEXT: {{.*}} readability-function-size
-// CHECK-NEXT: {{.*}} Total
-
-// CHECK-NOT: ===-------------------------------------------------------------------------===
-// CHECK-NOT: clang-tidy checks profiling
-// CHECK-NOT: ===-------------------------------------------------------------------------===
-// CHECK-NOT: Total Execution Time: {{.*}} seconds ({{.*}} wall clock)
-
-// CHECK-NOT: {{.*}} --- Name ---
-// CHECK-NOT: {{.*}} readability-function-size
-// CHECK-NOT: {{.*}} Total
-
-class A {
- A() {}
- ~A() {}
-};
Removed: clang-tools-extra/trunk/test/clang-tidy/clang-tidy-mac-libcxx.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/clang-tidy-mac-libcxx.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/clang-tidy-mac-libcxx.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/clang-tidy-mac-libcxx.cpp (removed)
@@ -1,17 +0,0 @@
-// Clang on MacOS can find libc++ living beside the installed compiler.
-// This test makes sure clang-tidy emulates this properly.
-//
-// RUN: rm -rf %t
-// RUN: mkdir %t
-//
-// Install the mock libc++ (simulates the libc++ directory structure).
-// RUN: cp -r %S/Inputs/mock-libcxx %t/
-//
-// Pretend clang is installed beside the mock library that we provided.
-// RUN: echo '[{"directory":"%t","command":"%t/mock-libcxx/bin/clang++ -stdlib=libc++ -std=c++11 -target x86_64-apple-darwin -c test.cpp","file":"test.cpp"}]' | sed -e 's/\\/\//g' > %t/compile_commands.json
-// RUN: cp "%s" "%t/test.cpp"
-// RUN: clang-tidy -header-filter='.*' -system-headers -checks='-*,modernize-use-using' "%t/test.cpp" | FileCheck %s
-// CHECK: mock_vector:{{[0-9]+}}:{{[0-9]+}}: warning: use 'using' instead of 'typedef'
-
-#include <mock_vector>
-typedef vector* vec_ptr;
Removed: clang-tools-extra/trunk/test/clang-tidy/clang-tidy-run-with-database.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/clang-tidy-run-with-database.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/clang-tidy-run-with-database.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/clang-tidy-run-with-database.cpp (removed)
@@ -1,29 +0,0 @@
-// RUN: mkdir -p %T/compilation-database-test/include
-// RUN: mkdir -p %T/compilation-database-test/a
-// RUN: mkdir -p %T/compilation-database-test/b
-// RUN: echo 'int *AA = 0;' > %T/compilation-database-test/a/a.cpp
-// RUN: echo 'int *AB = 0;' > %T/compilation-database-test/a/b.cpp
-// RUN: echo 'int *BB = 0;' > %T/compilation-database-test/b/b.cpp
-// RUN: echo 'int *BC = 0;' > %T/compilation-database-test/b/c.cpp
-// RUN: echo 'int *HP = 0;' > %T/compilation-database-test/include/header.h
-// RUN: echo '#include "header.h"' > %T/compilation-database-test/b/d.cpp
-// RUN: sed 's|test_dir|%/T/compilation-database-test|g' %S/Inputs/compilation-database/template.json > %T/compile_commands.json
-
-// Regression test: shouldn't crash.
-// RUN: not clang-tidy --checks=-*,modernize-use-nullptr -p %T %T/compilation-database-test/b/not-exist -header-filter=.* 2>&1 | FileCheck %s -check-prefix=CHECK-NOT-EXIST
-// CHECK-NOT-EXIST: Error while processing {{.*[/\\]}}not-exist.
-// CHECK-NOT-EXIST: unable to handle compilation
-// CHECK-NOT-EXIST: Found compiler error
-
-// RUN: clang-tidy --checks=-*,modernize-use-nullptr -p %T %T/compilation-database-test/a/a.cpp %T/compilation-database-test/a/b.cpp %T/compilation-database-test/b/b.cpp %T/compilation-database-test/b/c.cpp %T/compilation-database-test/b/d.cpp -header-filter=.* -fix
-// RUN: FileCheck -input-file=%T/compilation-database-test/a/a.cpp %s -check-prefix=CHECK-FIX1
-// RUN: FileCheck -input-file=%T/compilation-database-test/a/b.cpp %s -check-prefix=CHECK-FIX2
-// RUN: FileCheck -input-file=%T/compilation-database-test/b/b.cpp %s -check-prefix=CHECK-FIX3
-// RUN: FileCheck -input-file=%T/compilation-database-test/b/c.cpp %s -check-prefix=CHECK-FIX4
-// RUN: FileCheck -input-file=%T/compilation-database-test/include/header.h %s -check-prefix=CHECK-FIX5
-
-// CHECK-FIX1: int *AA = nullptr;
-// CHECK-FIX2: int *AB = nullptr;
-// CHECK-FIX3: int *BB = nullptr;
-// CHECK-FIX4: int *BC = nullptr;
-// CHECK-FIX5: int *HP = nullptr;
Removed: clang-tools-extra/trunk/test/clang-tidy/clang-tidy-store-check-profile-one-tu.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/clang-tidy-store-check-profile-one-tu.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/clang-tidy-store-check-profile-one-tu.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/clang-tidy-store-check-profile-one-tu.cpp (removed)
@@ -1,37 +0,0 @@
-// RUN: rm -rf %T/out
-// RUN: clang-tidy -enable-check-profile -checks='-*,readability-function-size' -store-check-profile=%T/out %s -- 2>&1 | not FileCheck --match-full-lines -implicit-check-not='{{warning:|error:}}' -check-prefix=CHECK-CONSOLE %s
-// RUN: cat %T/out/*-clang-tidy-store-check-profile-one-tu.cpp.json | FileCheck --match-full-lines -implicit-check-not='{{warning:|error:}}' -check-prefix=CHECK-FILE %s
-// RUN: rm -rf %T/out
-// RUN: clang-tidy -enable-check-profile -checks='-*,readability-function-size' -store-check-profile=%T/out %s -- 2>&1
-// RUN: cat %T/out/*-clang-tidy-store-check-profile-one-tu.cpp.json | FileCheck --match-full-lines -implicit-check-not='{{warning:|error:}}' -check-prefix=CHECK-FILE %s
-
-// CHECK-CONSOLE-NOT: ===-------------------------------------------------------------------------===
-// CHECK-CONSOLE-NOT: {{.*}} --- Name ---
-// CHECK-CONSOLE-NOT: {{.*}} readability-function-size
-// CHECK-CONSOLE-NOT: {{.*}} Total
-// CHECK-CONSOLE-NOT: ===-------------------------------------------------------------------------===
-
-// CHECK-FILE: {
-// CHECK-FILE-NEXT:"file": "{{.*}}clang-tidy-store-check-profile-one-tu.cpp",
-// CHECK-FILE-NEXT:"timestamp": "{{[0-9]+}}-{{[0-9]+}}-{{[0-9]+}} {{[0-9]+}}:{{[0-9]+}}:{{[0-9]+}}.{{[0-9]+}}",
-// CHECK-FILE-NEXT:"profile": {
-// CHECK-FILE-NEXT: "time.clang-tidy.readability-function-size.wall": {{.*}}{{[0-9]}}.{{[0-9]+}}e{{[-+]}}{{[0-9]}}{{[0-9]}},
-// CHECK-FILE-NEXT: "time.clang-tidy.readability-function-size.user": {{.*}}{{[0-9]}}.{{[0-9]+}}e{{[-+]}}{{[0-9]}}{{[0-9]}},
-// CHECK-FILE-NEXT: "time.clang-tidy.readability-function-size.sys": {{.*}}{{[0-9]}}.{{[0-9]+}}e{{[-+]}}{{[0-9]}}{{[0-9]}}
-// CHECK-FILE-NEXT: }
-// CHECK-FILE-NEXT: }
-
-// CHECK-FILE-NOT: {
-// CHECK-FILE-NOT: "file": {{.*}}clang-tidy-store-check-profile-one-tu.cpp{{.*}},
-// CHECK-FILE-NOT: "timestamp": "{{[0-9]+}}-{{[0-9]+}}-{{[0-9]+}} {{[0-9]+}}:{{[0-9]+}}:{{[0-9]+}}.{{[0-9]+}}",
-// CHECK-FILE-NOT: "profile": {
-// CHECK-FILE-NOT: "time.clang-tidy.readability-function-size.wall": {{.*}}{{[0-9]}}.{{[0-9]+}}e{{[-+]}}{{[0-9]}}{{[0-9]}},
-// CHECK-FILE-NOT: "time.clang-tidy.readability-function-size.user": {{.*}}{{[0-9]}}.{{[0-9]+}}e{{[-+]}}{{[0-9]}}{{[0-9]}},
-// CHECK-FILE-NOT: "time.clang-tidy.readability-function-size.sys": {{.*}}{{[0-9]}}.{{[0-9]+}}e{{[-+]}}{{[0-9]}}{{[0-9]}}
-// CHECK-FILE-NOT: }
-// CHECK-FILE-NOT: }
-
-class A {
- A() {}
- ~A() {}
-};
Removed: clang-tools-extra/trunk/test/clang-tidy/clean-up-code.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/clean-up-code.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/clean-up-code.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/clean-up-code.cpp (removed)
@@ -1,14 +0,0 @@
-// RUN: %check_clang_tidy %s misc-unused-using-decls %t
-// RUN: %check_clang_tidy %s misc-unused-using-decls %t -- -format-style=none --
-// RUN: %check_clang_tidy %s misc-unused-using-decls %t -- -format-style=llvm --
-namespace a { class A {}; }
-namespace b {
-using a::A;
-}
-namespace c {}
-// CHECK-MESSAGES: :[[@LINE-3]]:10: warning: using decl 'A' is unused [misc-unused-using-decls]
-// CHECK-FIXES: {{^namespace a { class A {}; }$}}
-// CHECK-FIXES-NOT: namespace
-// CHECK-FIXES: {{^namespace c {}$}}
-// FIXME: cleanupAroundReplacements leaves whitespace. Otherwise we could just
-// check the next line.
Removed: clang-tools-extra/trunk/test/clang-tidy/config-files.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/config-files.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/config-files.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/config-files.cpp (removed)
@@ -1,12 +0,0 @@
-// RUN: clang-tidy -dump-config %S/Inputs/config-files/- -- | FileCheck %s -check-prefix=CHECK-BASE
-// CHECK-BASE: Checks: {{.*}}from-parent
-// CHECK-BASE: HeaderFilterRegex: parent
-// RUN: clang-tidy -dump-config %S/Inputs/config-files/1/- -- | FileCheck %s -check-prefix=CHECK-CHILD1
-// CHECK-CHILD1: Checks: {{.*}}from-child1
-// CHECK-CHILD1: HeaderFilterRegex: child1
-// RUN: clang-tidy -dump-config %S/Inputs/config-files/2/- -- | FileCheck %s -check-prefix=CHECK-CHILD2
-// CHECK-CHILD2: Checks: {{.*}}from-parent
-// CHECK-CHILD2: HeaderFilterRegex: parent
-// RUN: clang-tidy -dump-config -checks='from-command-line' -header-filter='from command line' %S/Inputs/config-files/- -- | FileCheck %s -check-prefix=CHECK-COMMAND-LINE
-// CHECK-COMMAND-LINE: Checks: {{.*}}from-parent,from-command-line
-// CHECK-COMMAND-LINE: HeaderFilterRegex: from command line
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-avoid-goto.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-avoid-goto.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-avoid-goto.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-avoid-goto.cpp (removed)
@@ -1,139 +0,0 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-avoid-goto %t
-
-void noop() {}
-
-int main() {
- noop();
- goto jump_to_me;
- // CHECK-NOTES: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
- // CHECK-NOTES: [[@LINE+3]]:1: note: label defined here
- noop();
-
-jump_to_me:;
-
-jump_backwards:;
- noop();
- goto jump_backwards;
- // CHECK-NOTES: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
- // CHECK-NOTES: [[@LINE-4]]:1: note: label defined here
-
- goto jump_in_line;
- ;
-jump_in_line:;
- // CHECK-NOTES: [[@LINE-3]]:3: warning: avoid using 'goto' for flow control
- // CHECK-NOTES: [[@LINE-2]]:1: note: label defined here
-
- // Test the GNU extension https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
-some_label:;
- void *dynamic_label = &&some_label;
-
- // FIXME: `IndirectGotoStmt` is not detected.
- goto *dynamic_label;
-}
-
-void forward_jump_out_nested_loop() {
- int array[] = {1, 2, 3, 4, 5};
- for (int i = 0; i < 10; ++i) {
- noop();
- for (int j = 0; j < 10; ++j) {
- noop();
- if (i + j > 10)
- goto early_exit1;
- }
- noop();
- }
-
- for (int i = 0; i < 10; ++i) {
- noop();
- while (true) {
- noop();
- if (i > 5)
- goto early_exit1;
- }
- noop();
- }
-
- for (auto value : array) {
- noop();
- for (auto number : array) {
- noop();
- if (number == 5)
- goto early_exit1;
- }
- }
-
- do {
- noop();
- do {
- noop();
- goto early_exit1;
- } while (true);
- } while (true);
-
- do {
- for (auto number : array) {
- noop();
- if (number == 2)
- goto early_exit1;
- }
- } while (true);
-
- // Jumping further results in error, because the variable declaration would
- // be skipped.
-early_exit1:;
-
- int i = 0;
- while (true) {
- noop();
- while (true) {
- noop();
- if (i > 5)
- goto early_exit2;
- i++;
- }
- noop();
- }
-
- while (true) {
- noop();
- for (int j = 0; j < 10; ++j) {
- noop();
- if (j > 5)
- goto early_exit2;
- }
- noop();
- }
-
- while (true) {
- noop();
- for (auto number : array) {
- if (number == 1)
- goto early_exit2;
- noop();
- }
- }
-
- while (true) {
- noop();
- do {
- noop();
- goto early_exit2;
- } while (true);
- }
-early_exit2:;
-}
-
-void jump_out_backwards() {
-
-before_the_loop:
- noop();
-
- for (int i = 0; i < 10; ++i) {
- for (int j = 0; j < 10; ++j) {
- if (i * j > 80)
- goto before_the_loop;
- // CHECK-NOTES: [[@LINE-1]]:9: warning: avoid using 'goto' for flow control
- // CHECK-NOTES: [[@LINE-8]]:1: note: label defined here
- }
- }
-}
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-init-variables.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-init-variables.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-init-variables.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-init-variables.cpp (removed)
@@ -1,80 +0,0 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-init-variables %t -- -- -fno-delayed-template-parsing
-
-// Ensure that function declarations are not changed.
-void some_func(int x, double d, bool b, const char *p);
-
-// Ensure that function arguments are not changed
-int identity_function(int x) {
- return x;
-}
-
-int do_not_modify_me;
-
-static int should_not_be_initialized;
-extern int should_not_be_initialized2;
-
-typedef struct {
- int unaltered1;
- int unaltered2;
-} UnusedStruct;
-
-typedef int my_int_type;
-#define MACRO_INT int
-#define FULL_DECLARATION() int macrodecl;
-
-template <typename T>
-void template_test_function() {
- T t;
- int uninitialized;
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: variable 'uninitialized' is not initialized [cppcoreguidelines-init-variables]
- // CHECK-FIXES: {{^}} int uninitialized = 0;{{$}}
-}
-
-void init_unit_tests() {
- int x;
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: variable 'x' is not initialized [cppcoreguidelines-init-variables]
- // CHECK-FIXES: {{^}} int x = 0;{{$}}
- my_int_type myint;
- // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: variable 'myint' is not initialized [cppcoreguidelines-init-variables]
- // CHECK-FIXES: {{^}} my_int_type myint = 0;{{$}}
-
- MACRO_INT macroint;
- // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: variable 'macroint' is not initialized [cppcoreguidelines-init-variables]
- // CHECK-FIXES: {{^}} MACRO_INT macroint = 0;{{$}}
- FULL_DECLARATION();
-
- int x0 = 1, x1, x2 = 2;
- // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: variable 'x1' is not initialized [cppcoreguidelines-init-variables]
- // CHECK-FIXES: {{^}} int x0 = 1, x1 = 0, x2 = 2;{{$}}
- int y0, y1 = 1, y2;
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: variable 'y0' is not initialized [cppcoreguidelines-init-variables]
- // CHECK-MESSAGES: :[[@LINE-2]]:19: warning: variable 'y2' is not initialized [cppcoreguidelines-init-variables]
- // CHECK-FIXES: {{^}} int y0 = 0, y1 = 1, y2 = 0;{{$}}
- int hasval = 42;
-
- float f;
- // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: variable 'f' is not initialized [cppcoreguidelines-init-variables]
- // CHECK-FIXES: {{^}} float f = NAN;{{$}}
- float fval = 85.0;
- double d;
- // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: variable 'd' is not initialized [cppcoreguidelines-init-variables]
- // CHECK-FIXES: {{^}} double d = NAN;{{$}}
- double dval = 99.0;
-
- bool b;
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: variable 'b' is not initialized [cppcoreguidelines-init-variables]
- // CHECK-FIXES: {{^}} bool b = 0;{{$}}
- bool bval = true;
-
- const char *ptr;
- // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: variable 'ptr' is not initialized [cppcoreguidelines-init-variables]
- // CHECK-FIXES: {{^}} const char *ptr = nullptr;{{$}}
- const char *ptrval = "a string";
-
- UnusedStruct u;
-
- static int does_not_need_an_initializer;
- extern int does_not_need_an_initializer2;
- int parens(42);
- int braces{42};
-}
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-interfaces-global-init.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-interfaces-global-init.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-interfaces-global-init.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-interfaces-global-init.cpp (removed)
@@ -1,84 +0,0 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-interfaces-global-init %t
-
-constexpr int makesInt() { return 3; }
-constexpr int takesInt(int i) { return i + 1; }
-constexpr int takesIntPtr(int *i) { return *i; }
-
-extern int ExternGlobal;
-static int GlobalScopeBadInit1 = ExternGlobal;
-// CHECK-MESSAGES: [[@LINE-1]]:12: warning: initializing non-local variable with non-const expression depending on uninitialized non-local variable 'ExternGlobal'
-static int GlobalScopeBadInit2 = takesInt(ExternGlobal);
-// CHECK-MESSAGES: [[@LINE-1]]:12: warning: initializing non-local variable with non-const expression depending on uninitialized non-local variable 'ExternGlobal'
-static int GlobalScopeBadInit3 = takesIntPtr(&ExternGlobal);
-// CHECK-MESSAGES: [[@LINE-1]]:12: warning: initializing non-local variable with non-const expression depending on uninitialized non-local variable 'ExternGlobal'
-static int GlobalScopeBadInit4 = 3 * (ExternGlobal + 2);
-// CHECK-MESSAGES: [[@LINE-1]]:12: warning: initializing non-local variable with non-const expression depending on uninitialized non-local variable 'ExternGlobal'
-
-namespace ns {
-static int NamespaceScope = makesInt();
-static int NamespaceScopeBadInit = takesInt(ExternGlobal);
-// CHECK-MESSAGES: [[@LINE-1]]:12: warning: initializing non-local variable with non-const expression depending on uninitialized non-local variable 'ExternGlobal'
-
-struct A {
- static int ClassScope;
- static int ClassScopeBadInit;
-};
-
-int A::ClassScopeBadInit = takesInt(ExternGlobal);
-// CHECK-MESSAGES: [[@LINE-1]]:8: warning: initializing non-local variable with non-const expression depending on uninitialized non-local variable 'ExternGlobal'
-
-static int FromClassBadInit = takesInt(A::ClassScope);
-// CHECK-MESSAGES: [[@LINE-1]]:12: warning: initializing non-local variable with non-const expression depending on uninitialized non-local variable 'ClassScope'
-} // namespace ns
-
-// "const int B::I;" is fine, it just ODR-defines B::I. See [9.4.3] Static
-// members [class.static]. However the ODR-definitions are not in the right
-// order (C::I after C::J, see [3.6.2.3]).
-class B1 {
- static const int I = 0;
- static const int J = I;
-};
-const int B1::J;
-// CHECK-MESSAGES: [[@LINE-1]]:15: warning: initializing non-local variable with non-const expression depending on uninitialized non-local variable 'I'
-const int B1::I;
-
-void f() {
- // This is fine, it's executed after dynamic initialization occurs.
- static int G = takesInt(ExternGlobal);
-}
-
-// Declaration then definition then usage is fine.
-extern int ExternGlobal2;
-extern int ExternGlobal2;
-int ExternGlobal2 = 123;
-static int GlobalScopeGoodInit1 = ExternGlobal2;
-
-
-// Defined global variables are fine:
-static int GlobalScope = makesInt();
-static int GlobalScopeGoodInit2 = takesInt(GlobalScope);
-static int GlobalScope2 = takesInt(ns::NamespaceScope);
-// Enums are fine.
-enum Enum { kEnumValue = 1 };
-static int GlobalScopeFromEnum = takesInt(kEnumValue);
-
-// Leave constexprs alone.
-extern constexpr int GlobalScopeConstexpr = makesInt();
-static constexpr int GlobalScopeConstexprOk =
- takesInt(GlobalScopeConstexpr);
-
-// This is a pretty common instance: People are usually not using constexpr, but
-// this is what they should write:
-static constexpr const char kValue[] = "value";
-constexpr int Fingerprint(const char *value) { return 0; }
-static int kFingerprint = Fingerprint(kValue);
-
-// This is fine because the ODR-definitions are in the right order (C::J after
-// C::I).
-class B2 {
- static const int I = 0;
- static const int J = I;
-};
-const int B2::I;
-const int B2::J;
-
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-macro-usage-caps-only.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-macro-usage-caps-only.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-macro-usage-caps-only.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-macro-usage-caps-only.cpp (removed)
@@ -1,24 +0,0 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-macro-usage %t \
-// RUN: -config='{CheckOptions: \
-// RUN: [{key: cppcoreguidelines-macro-usage.CheckCapsOnly, value: 1}]}' --
-
-#ifndef INCLUDE_GUARD
-#define INCLUDE_GUARD
-
-#define problematic_constant 0
-// CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro definition does not define the macro name 'problematic_constant' using all uppercase characters
-
-#define problematic_function(x, y) ((a) > (b) ? (a) : (b))
-// CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro definition does not define the macro name 'problematic_function' using all uppercase characters
-
-#define problematic_variadic(...) (__VA_ARGS__)
-// CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro definition does not define the macro name 'problematic_variadic' using all uppercase characters
-//
-#define problematic_variadic2(x, ...) (__VA_ARGS__)
-// CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro definition does not define the macro name 'problematic_variadic2' using all uppercase characters
-
-#define OKISH_CONSTANT 42
-#define OKISH_FUNCTION(x, y) ((a) > (b) ? (a) : (b))
-#define OKISH_VARIADIC(...) (__VA_ARGS__)
-
-#endif
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-macro-usage-command-line-macros.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-macro-usage-command-line-macros.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-macro-usage-command-line-macros.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-macro-usage-command-line-macros.cpp (removed)
@@ -1,8 +0,0 @@
-// RUN: %check_clang_tidy -check-suffixes=NORMAL %s cppcoreguidelines-macro-usage %t -- -- -D_ZZZ_IM_A_MACRO
-// RUN: %check_clang_tidy -check-suffixes=NORMAL %s cppcoreguidelines-macro-usage %t -- -config='{CheckOptions: [{key: cppcoreguidelines-macro-usage.IgnoreCommandLineMacros, value: 1}]}' -- -D_ZZZ_IM_A_MACRO
-// RUN: %check_clang_tidy -check-suffixes=NORMAL,CL %s cppcoreguidelines-macro-usage %t -- -config='{CheckOptions: [{key: cppcoreguidelines-macro-usage.IgnoreCommandLineMacros, value: 0}]}' -- -D_ZZZ_IM_A_MACRO
-
-// CHECK-MESSAGES-CL: warning: macro '_ZZZ_IM_A_MACRO' used to declare a constant; consider using a 'constexpr' constant
-
-#define PROBLEMATIC_CONSTANT 0
-// CHECK-MESSAGES-NORMAL: [[@LINE-1]]:9: warning: macro 'PROBLEMATIC_CONSTANT' used to declare a constant; consider using a 'constexpr' constant
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-macro-usage-custom.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-macro-usage-custom.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-macro-usage-custom.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-macro-usage-custom.cpp (removed)
@@ -1,28 +0,0 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-macro-usage %t \
-// RUN: -config='{CheckOptions: \
-// RUN: [{key: cppcoreguidelines-macro-usage.AllowedRegexp, value: "DEBUG_*|TEST_*"}]}' --
-
-#ifndef INCLUDE_GUARD
-#define INCLUDE_GUARD
-
-#define PROBLEMATIC_CONSTANT 0
-// CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro 'PROBLEMATIC_CONSTANT' used to declare a constant; consider using a 'constexpr' constant
-
-#define PROBLEMATIC_FUNCTION(x, y) ((a) > (b) ? (a) : (b))
-// CHECK-MESSAGES: [[@LINE-1]]:9: warning: function-like macro 'PROBLEMATIC_FUNCTION' used; consider a 'constexpr' template function
-
-#define PROBLEMATIC_VARIADIC(...) (__VA_ARGS__)
-// CHECK-MESSAGES: [[@LINE-1]]:9: warning: variadic macro 'PROBLEMATIC_VARIADIC' used; consider using a 'constexpr' variadic template function
-
-#define PROBLEMATIC_VARIADIC2(x, ...) (__VA_ARGS__)
-// CHECK-MESSAGES: [[@LINE-1]]:9: warning: variadic macro 'PROBLEMATIC_VARIADIC2' used; consider using a 'constexpr' variadic template function
-
-#define DEBUG_CONSTANT 0
-#define DEBUG_FUNCTION(x, y) ((a) > (b) ? (a) : (b))
-#define DEBUG_VARIADIC(...) (__VA_ARGS__)
-#define TEST_CONSTANT 0
-#define TEST_FUNCTION(x, y) ((a) > (b) ? (a) : (b))
-#define TEST_VARIADIC(...) (__VA_ARGS__)
-#define TEST_VARIADIC2(x, ...) (__VA_ARGS__)
-
-#endif
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-macro-usage.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-macro-usage.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-macro-usage.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-macro-usage.cpp (removed)
@@ -1,18 +0,0 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-macro-usage %t -- -header-filter=.* -system-headers --
-
-#ifndef INCLUDE_GUARD
-#define INCLUDE_GUARD
-
-#define PROBLEMATIC_CONSTANT 0
-// CHECK-MESSAGES: [[@LINE-1]]:9: warning: macro 'PROBLEMATIC_CONSTANT' used to declare a constant; consider using a 'constexpr' constant
-
-#define PROBLEMATIC_FUNCTION(x, y) ((a) > (b) ? (a) : (b))
-// CHECK-MESSAGES: [[@LINE-1]]:9: warning: function-like macro 'PROBLEMATIC_FUNCTION' used; consider a 'constexpr' template function
-
-#define PROBLEMATIC_VARIADIC(...) (__VA_ARGS__)
-// CHECK-MESSAGES: [[@LINE-1]]:9: warning: variadic macro 'PROBLEMATIC_VARIADIC' used; consider using a 'constexpr' variadic template function
-
-#define PROBLEMATIC_VARIADIC2(x, ...) (__VA_ARGS__)
-// CHECK-MESSAGES: [[@LINE-1]]:9: warning: variadic macro 'PROBLEMATIC_VARIADIC2' used; consider using a 'constexpr' variadic template function
-
-#endif
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-narrowing-conversions-long-is-32bits.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-narrowing-conversions-long-is-32bits.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-narrowing-conversions-long-is-32bits.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-narrowing-conversions-long-is-32bits.cpp (removed)
@@ -1,23 +0,0 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-narrowing-conversions %t \
-// RUN: -- -- -target x86_64-unknown-linux -m32
-
-static_assert(sizeof(int) * 8 == 32, "int is 32-bits");
-static_assert(sizeof(long) * 8 == 32, "long is 32-bits");
-static_assert(sizeof(long long) * 8 == 64, "long long is 64-bits");
-
-void narrow_integer_to_signed_integer_is_not_ok() {
- int i; // i.e. int32_t
- long l; // i.e. int32_t
- long long ll; // i.e. int64_t
-
- unsigned int ui; // i.e. uint32_t
- unsigned long ul; // i.e. uint32_t
- unsigned long long ull; // i.e. uint64_t
-
- i = l; // int and long are the same type.
- i = ll; // int64_t does not fit in an int32_t
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: narrowing conversion from 'long long' to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions]
- ll = ul; // uint32_t fits into int64_t
- ll = ull; // uint64_t does not fit in an int64_t
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: narrowing conversion from 'unsigned long long' to signed type 'long long' is implementation-defined [cppcoreguidelines-narrowing-conversions]
-}
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-narrowing-conversions-narrowingfloatingpoint-option.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-narrowing-conversions-narrowingfloatingpoint-option.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-narrowing-conversions-narrowingfloatingpoint-option.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-narrowing-conversions-narrowingfloatingpoint-option.cpp (removed)
@@ -1,57 +0,0 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-narrowing-conversions %t \
-// RUN: -- -- -target x86_64-unknown-linux -fsigned-char
-
-namespace floats {
-
-void narrow_constant_floating_point_to_int_not_ok(double d) {
- int i = 0;
- i += 0.5;
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: narrowing conversion from constant 'double' to 'int' [cppcoreguidelines-narrowing-conversions]
- i += 0.5f;
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: narrowing conversion from constant 'float' to 'int' [cppcoreguidelines-narrowing-conversions]
- i *= 0.5f;
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: narrowing conversion from constant 'float' to 'int' [cppcoreguidelines-narrowing-conversions]
- i /= 0.5f;
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: narrowing conversion from constant 'float' to 'int' [cppcoreguidelines-narrowing-conversions]
- i += (double)0.5f;
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: narrowing conversion from constant 'double' to 'int' [cppcoreguidelines-narrowing-conversions]
- i += 2.0;
- i += 2.0f;
-}
-
-double operator"" _double(unsigned long long);
-
-float narrow_double_to_float_return() {
- return 0.5;
-}
-
-void narrow_double_to_float_not_ok(double d) {
- float f;
- f = d;
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: narrowing conversion from 'double' to 'float' [cppcoreguidelines-narrowing-conversions]
- f = 15_double;
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: narrowing conversion from 'double' to 'float' [cppcoreguidelines-narrowing-conversions]
- f += d;
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: narrowing conversion from 'double' to 'float' [cppcoreguidelines-narrowing-conversions]
- f = narrow_double_to_float_return();
-}
-
-void narrow_fp_constants() {
- float f;
- f = 0.5; // [dcl.init.list] 7.2 : in-range fp constant to narrower float is not a narrowing.
-
- f = __builtin_huge_valf(); // max float is not narrowing.
- f = -__builtin_huge_valf(); // -max float is not narrowing.
- f = __builtin_inff(); // float infinity is not narrowing.
- f = __builtin_nanf("0"); // float NaN is not narrowing.
-
- f = __builtin_huge_val(); // max double is not within-range of float.
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: narrowing conversion from constant 'double' to 'float' [cppcoreguidelines-narrowing-conversions]
- f = -__builtin_huge_val(); // -max double is not within-range of float.
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: narrowing conversion from constant 'double' to 'float' [cppcoreguidelines-narrowing-conversions]
- f = __builtin_inf(); // double infinity is not within-range of float.
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: narrowing conversion from constant 'double' to 'float' [cppcoreguidelines-narrowing-conversions]
- f = __builtin_nan("0"); // double NaN is not narrowing.
-}
-
-} // namespace floats
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-narrowing-conversions-pedanticmode-option.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-narrowing-conversions-pedanticmode-option.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-narrowing-conversions-pedanticmode-option.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-narrowing-conversions-pedanticmode-option.cpp (removed)
@@ -1,23 +0,0 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-narrowing-conversions %t \
-// RUN: -config="{CheckOptions: [ \
-// RUN: {key: "cppcoreguidelines-narrowing-conversions.PedanticMode", value: 1} \
-// RUN: ]}" \
-// RUN: -- -target x86_64-unknown-linux -fsigned-char
-
-namespace floats {
-
-void triggers_wrong_constant_type_warning(double d) {
- int i = 0.0;
- // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: constant value should be of type of type 'int' instead of 'double' [cppcoreguidelines-narrowing-conversions]
- i += 2.0;
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: constant value should be of type of type 'int' instead of 'double' [cppcoreguidelines-narrowing-conversions]
- i += 2.0f;
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: constant value should be of type of type 'int' instead of 'float' [cppcoreguidelines-narrowing-conversions]
-}
-
-void triggers_narrowing_warning_when_overflowing() {
- unsigned short us = 65537.0;
- // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: narrowing conversion from constant 'double' to 'unsigned short' [cppcoreguidelines-narrowing-conversions]
-}
-
-} // namespace floats
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-narrowing-conversions-unsigned-char.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-narrowing-conversions-unsigned-char.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-narrowing-conversions-unsigned-char.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-narrowing-conversions-unsigned-char.cpp (removed)
@@ -1,83 +0,0 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-narrowing-conversions %t \
-// RUN: -- -- -target x86_64-unknown-linux -funsigned-char
-
-void narrow_integer_to_unsigned_integer_is_ok() {
- signed char sc;
- short s;
- int i;
- long l;
- long long ll;
-
- char c;
- unsigned short us;
- unsigned int ui;
- unsigned long ul;
- unsigned long long ull;
-
- ui = sc;
- c = s;
- c = i;
- c = l;
- c = ll;
-
- c = c;
- c = us;
- c = ui;
- c = ul;
- c = ull;
-}
-
-void narrow_integer_to_signed_integer_is_not_ok() {
- signed char sc;
- short s;
- int i;
- long l;
- long long ll;
-
- char c;
- unsigned short us;
- unsigned int ui;
- unsigned long ul;
- unsigned long long ull;
-
- sc = sc;
- sc = s;
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: narrowing conversion from 'short' to signed type 'signed char' is implementation-defined [cppcoreguidelines-narrowing-conversions]
- sc = i;
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: narrowing conversion from 'int' to signed type 'signed char' is implementation-defined [cppcoreguidelines-narrowing-conversions]
- sc = l;
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: narrowing conversion from 'long' to signed type 'signed char' is implementation-defined [cppcoreguidelines-narrowing-conversions]
- sc = ll;
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: narrowing conversion from 'long long' to signed type 'signed char' is implementation-defined [cppcoreguidelines-narrowing-conversions]
-
- sc = c;
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: narrowing conversion from 'char' to signed type 'signed char' is implementation-defined [cppcoreguidelines-narrowing-conversions]
- sc = us;
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: narrowing conversion from 'unsigned short' to signed type 'signed char' is implementation-defined [cppcoreguidelines-narrowing-conversions]
- sc = ui;
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: narrowing conversion from 'unsigned int' to signed type 'signed char' is implementation-defined [cppcoreguidelines-narrowing-conversions]
- sc = ul;
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: narrowing conversion from 'unsigned long' to signed type 'signed char' is implementation-defined [cppcoreguidelines-narrowing-conversions]
- sc = ull;
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: narrowing conversion from 'unsigned long long' to signed type 'signed char' is implementation-defined [cppcoreguidelines-narrowing-conversions]
-}
-
-void narrow_constant_to_unsigned_integer_is_ok() {
- char c1 = -128; // unsigned dst type is well defined.
- char c2 = 127; // unsigned dst type is well defined.
- char c3 = -129; // unsigned dst type is well defined.
- char c4 = 128; // unsigned dst type is well defined.
- unsigned char uc1 = 0;
- unsigned char uc2 = 255;
- unsigned char uc3 = -1; // unsigned dst type is well defined.
- unsigned char uc4 = 256; // unsigned dst type is well defined.
- signed char sc = 128;
- // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: narrowing conversion from constant value 128 (0x00000080) of type 'int' to signed type 'signed char' is implementation-defined [cppcoreguidelines-narrowing-conversions]
-}
-
-void narrow_conditional_operator_contant_to_unsigned_is_ok(bool b) {
- // conversion to unsigned char type is well defined.
- char c1 = b ? 1 : 0;
- char c2 = b ? 1 : 256;
- char c3 = b ? -1 : 0;
-}
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-narrowing-conversions.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-narrowing-conversions.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-narrowing-conversions.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-narrowing-conversions.cpp (removed)
@@ -1,346 +0,0 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-narrowing-conversions %t \
-// RUN: -config="{CheckOptions: [ \
-// RUN: {key: "cppcoreguidelines-narrowing-conversions.WarnOnFloatingPointNarrowingConversion", value: 0}, \
-// RUN: ]}" \
-// RUN: -- -target x86_64-unknown-linux -fsigned-char
-
-float ceil(float);
-namespace std {
-double ceil(double);
-long double floor(long double);
-} // namespace std
-
-namespace floats {
-
-struct ConvertsToFloat {
- operator float() const { return 0.5f; }
-};
-
-float operator"" _float(unsigned long long);
-
-void narrow_fp_to_int_not_ok(double d) {
- int i = 0;
- i = d;
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: narrowing conversion from 'double' to 'int' [cppcoreguidelines-narrowing-conversions]
- i = 0.5f;
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: narrowing conversion from constant 'float' to 'int' [cppcoreguidelines-narrowing-conversions]
- i = static_cast<float>(d);
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: narrowing conversion from 'float' to 'int' [cppcoreguidelines-narrowing-conversions]
- i = ConvertsToFloat();
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: narrowing conversion from 'float' to 'int' [cppcoreguidelines-narrowing-conversions]
- i = 15_float;
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: narrowing conversion from 'float' to 'int' [cppcoreguidelines-narrowing-conversions]
- i += d;
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: narrowing conversion from 'double' to 'int' [cppcoreguidelines-narrowing-conversions]
- i += 0.5;
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: narrowing conversion from constant 'double' to 'int' [cppcoreguidelines-narrowing-conversions]
- i += 0.5f;
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: narrowing conversion from constant 'float' to 'int' [cppcoreguidelines-narrowing-conversions]
- i *= 0.5f;
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: narrowing conversion from constant 'float' to 'int' [cppcoreguidelines-narrowing-conversions]
- i /= 0.5f;
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: narrowing conversion from constant 'float' to 'int' [cppcoreguidelines-narrowing-conversions]
- i += (double)0.5f;
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: narrowing conversion from constant 'double' to 'int' [cppcoreguidelines-narrowing-conversions]
- i += 2.0;
- i += 2.0f;
-}
-
-double operator"" _double(unsigned long long);
-
-float narrow_double_to_float_return() {
- return 0.5; // [dcl.init.list] 7.2 : in-range fp constant to narrower float is not a narrowing.
-}
-
-void narrow_double_to_float_ok(double d) {
- float f;
- f = d;
- f = 15_double;
-}
-
-void narrow_fp_constants() {
- float f;
- f = 0.5; // [dcl.init.list] 7.2 : in-range fp constant to narrower float is not a narrowing.
-
- f = __builtin_huge_valf(); // max float is not narrowing.
- f = -__builtin_huge_valf(); // -max float is not narrowing.
- f = __builtin_inff(); // float infinity is not narrowing.
- f = __builtin_nanf("0"); // float NaN is not narrowing.
-
- f = __builtin_huge_val(); // max double is not within-range of float.
- f = -__builtin_huge_val(); // -max double is not within-range of float.
- f = __builtin_inf(); // double infinity is not within-range of float.
- f = __builtin_nan("0"); // double NaN is not narrowing.
-}
-
-void narrow_double_to_float_not_ok_binary_ops(double d) {
- float f;
- f += 0.5; // [dcl.init.list] 7.2 : in-range fp constant to narrower float is not a narrowing.
- f += 2.0; // [dcl.init.list] 7.2 : in-range fp constant to narrower float is not a narrowing.
- f *= 0.5; // [dcl.init.list] 7.2 : in-range fp constant to narrower float is not a narrowing.
- f /= 0.5; // [dcl.init.list] 7.2 : in-range fp constant to narrower float is not a narrowing.
- f += (double)0.5f; // [dcl.init.list] 7.2 : in-range fp constant to narrower float is not a narrowing.
- f += d; // We do not warn about floating point narrowing by default.
-}
-
-void narrow_fp_constant_to_bool_not_ok() {
- bool b1 = 1.0;
- // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: narrowing conversion from constant 'double' to 'bool' [cppcoreguidelines-narrowing-conversions]
- bool b2 = 1.0f;
- // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: narrowing conversion from constant 'float' to 'bool' [cppcoreguidelines-narrowing-conversions]
-}
-
-void narrow_integer_to_floating() {
- {
- long long ll; // 64 bits
- float f = ll; // doesn't fit in 24 bits
- // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: narrowing conversion from 'long long' to 'float' [cppcoreguidelines-narrowing-conversions]
- double d = ll; // doesn't fit in 53 bits.
- // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: narrowing conversion from 'long long' to 'double' [cppcoreguidelines-narrowing-conversions]
- }
- {
- int i; // 32 bits
- float f = i; // doesn't fit in 24 bits
- // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: narrowing conversion from 'int' to 'float' [cppcoreguidelines-narrowing-conversions]
- double d = i; // fits in 53 bits.
- }
- {
- short n1, n2;
- float f = n1 + n2; // 'n1 + n2' is of type 'int' because of integer rules
- // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: narrowing conversion from 'int' to 'float' [cppcoreguidelines-narrowing-conversions]
- }
- {
- short s; // 16 bits
- float f = s; // fits in 24 bits
- double d = s; // fits in 53 bits.
- }
-}
-
-void narrow_integer_to_unsigned_integer_is_ok() {
- char c;
- short s;
- int i;
- long l;
- long long ll;
-
- unsigned char uc;
- unsigned short us;
- unsigned int ui;
- unsigned long ul;
- unsigned long long ull;
-
- ui = c;
- uc = s;
- uc = i;
- uc = l;
- uc = ll;
-
- uc = uc;
- uc = us;
- uc = ui;
- uc = ul;
- uc = ull;
-}
-
-void narrow_integer_to_signed_integer_is_not_ok() {
- char c;
- short s;
- int i;
- long l;
- long long ll;
-
- unsigned char uc;
- unsigned short us;
- unsigned int ui;
- unsigned long ul;
- unsigned long long ull;
-
- c = c;
- c = s;
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: narrowing conversion from 'short' to signed type 'char' is implementation-defined [cppcoreguidelines-narrowing-conversions]
- c = i;
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: narrowing conversion from 'int' to signed type 'char' is implementation-defined [cppcoreguidelines-narrowing-conversions]
- c = l;
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: narrowing conversion from 'long' to signed type 'char' is implementation-defined [cppcoreguidelines-narrowing-conversions]
- c = ll;
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: narrowing conversion from 'long long' to signed type 'char' is implementation-defined [cppcoreguidelines-narrowing-conversions]
-
- c = uc;
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: narrowing conversion from 'unsigned char' to signed type 'char' is implementation-defined [cppcoreguidelines-narrowing-conversions]
- c = us;
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: narrowing conversion from 'unsigned short' to signed type 'char' is implementation-defined [cppcoreguidelines-narrowing-conversions]
- c = ui;
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: narrowing conversion from 'unsigned int' to signed type 'char' is implementation-defined [cppcoreguidelines-narrowing-conversions]
- c = ul;
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: narrowing conversion from 'unsigned long' to signed type 'char' is implementation-defined [cppcoreguidelines-narrowing-conversions]
- c = ull;
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: narrowing conversion from 'unsigned long long' to signed type 'char' is implementation-defined [cppcoreguidelines-narrowing-conversions]
-
- i = c;
- i = s;
- i = i;
- i = l;
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: narrowing conversion from 'long' to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions]
- i = ll;
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: narrowing conversion from 'long long' to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions]
-
- i = uc;
- i = us;
- i = ui;
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: narrowing conversion from 'unsigned int' to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions]
- i = ul;
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: narrowing conversion from 'unsigned long' to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions]
- i = ull;
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: narrowing conversion from 'unsigned long long' to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions]
-
- ll = c;
- ll = s;
- ll = i;
- ll = l;
- ll = ll;
-
- ll = uc;
- ll = us;
- ll = ui;
- ll = ul;
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: narrowing conversion from 'unsigned long' to signed type 'long long' is implementation-defined [cppcoreguidelines-narrowing-conversions]
- ll = ull;
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: narrowing conversion from 'unsigned long long' to signed type 'long long' is implementation-defined [cppcoreguidelines-narrowing-conversions]
-}
-
-void narrow_constant_to_unsigned_integer_is_ok() {
- unsigned char uc1 = 0;
- unsigned char uc2 = 255;
- unsigned char uc3 = -1; // unsigned dst type is well defined.
- unsigned char uc4 = 256; // unsigned dst type is well defined.
- unsigned short us1 = 0;
- unsigned short us2 = 65535;
- unsigned short us3 = -1; // unsigned dst type is well defined.
- unsigned short us4 = 65536; // unsigned dst type is well defined.
-}
-
-void narrow_constant_to_signed_integer_is_not_ok() {
- char c1 = -128;
- char c2 = 127;
- char c3 = -129;
- // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: narrowing conversion from constant value -129 (0xFFFFFF7F) of type 'int' to signed type 'char' is implementation-defined [cppcoreguidelines-narrowing-conversions]
- char c4 = 128;
- // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: narrowing conversion from constant value 128 (0x00000080) of type 'int' to signed type 'char' is implementation-defined [cppcoreguidelines-narrowing-conversions]
-
- short s1 = -32768;
- short s2 = 32767;
- short s3 = -32769;
- // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: narrowing conversion from constant value -32769 (0xFFFF7FFF) of type 'int' to signed type 'short' is implementation-defined [cppcoreguidelines-narrowing-conversions]
- short s4 = 32768;
- // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: narrowing conversion from constant value 32768 (0x00008000) of type 'int' to signed type 'short' is implementation-defined [cppcoreguidelines-narrowing-conversions]
-}
-
-void narrow_conditional_operator_contant_to_unsigned_is_ok(bool b) {
- // conversion to unsigned dst type is well defined.
- unsigned char c1 = b ? 1 : 0;
- unsigned char c2 = b ? 1 : 256;
- unsigned char c3 = b ? -1 : 0;
-}
-
-void narrow_conditional_operator_contant_to_signed_is_not_ok(bool b) {
- char uc1 = b ? 1 : 0;
- char uc2 = b ? 1 : 128;
- // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: narrowing conversion from constant value 128 (0x00000080) of type 'int' to signed type 'char' is implementation-defined [cppcoreguidelines-narrowing-conversions]
- char uc3 = b ? -129 : 0;
- // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: narrowing conversion from constant value -129 (0xFFFFFF7F) of type 'int' to signed type 'char' is implementation-defined [cppcoreguidelines-narrowing-conversions]
- unsigned long long ysize;
- long long mirror = b ? -1 : ysize - 1;
- // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: narrowing conversion from constant value 18446744073709551615 (0xFFFFFFFFFFFFFFFF) of type 'unsigned long long' to signed type 'long long' is implementation-defined [cppcoreguidelines-narrowing-conversions]
- // CHECK-MESSAGES: :[[@LINE-2]]:37: warning: narrowing conversion from 'unsigned long long' to signed type 'long long' is implementation-defined [cppcoreguidelines-narrowing-conversions]
-}
-
-void narrow_constant_to_floating_point() {
- float f_ok = 1ULL << 24; // fits in 24 bits mantissa.
- float f_not_ok = (1ULL << 24) + 1ULL; // doesn't fit in 24 bits mantissa.
- // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: narrowing conversion from constant value 16777217 of type 'unsigned long long' to 'float' [cppcoreguidelines-narrowing-conversions]
- double d_ok = 1ULL << 53; // fits in 53 bits mantissa.
- double d_not_ok = (1ULL << 53) + 1ULL; // doesn't fit in 53 bits mantissa.
- // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: narrowing conversion from constant value 9007199254740993 of type 'unsigned long long' to 'double' [cppcoreguidelines-narrowing-conversions]
-}
-
-void casting_integer_to_bool_is_ok() {
- int i;
- while (i) {
- }
- for (; i;) {
- }
- if (i) {
- }
-}
-
-void casting_float_to_bool_is_not_ok() {
- float f;
- while (f) {
- // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: narrowing conversion from 'float' to 'bool' [cppcoreguidelines-narrowing-conversions]
- }
- for (; f;) {
- // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: narrowing conversion from 'float' to 'bool' [cppcoreguidelines-narrowing-conversions]
- }
- if (f) {
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: narrowing conversion from 'float' to 'bool' [cppcoreguidelines-narrowing-conversions]
- }
-}
-
-void legitimate_comparison_do_not_warn(unsigned long long size) {
- for (int i = 0; i < size; ++i) {
- }
-}
-
-void ok(double d) {
- int i = 0;
- i = 1;
- i = static_cast<int>(0.5);
- i = static_cast<int>(d);
- i = std::ceil(0.5);
- i = ::std::floor(0.5);
- {
- using std::ceil;
- i = ceil(0.5f);
- }
- i = ceil(0.5f);
-}
-
-void ok_binary_ops(double d) {
- int i = 0;
- i += 1;
- i += static_cast<int>(0.5);
- i += static_cast<int>(d);
- i += (int)d;
- i += std::ceil(0.5);
- i += ::std::floor(0.5);
- {
- using std::ceil;
- i += ceil(0.5f);
- }
- i += ceil(0.5f);
-}
-
-// We're bailing out in templates and macros.
-template <typename T1, typename T2>
-void f(T1 one, T2 two) {
- one += two;
-}
-
-void template_context() {
- f(1, 2);
- f(1, .5f);
- f(1, .5);
- f(1, .5l);
-}
-
-#define DERP(i, j) (i += j)
-
-void macro_context() {
- int i = 0;
- DERP(i, 2);
- DERP(i, .5f);
- DERP(i, .5);
- DERP(i, .5l);
-}
-
-} // namespace floats
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-no-malloc-custom.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-no-malloc-custom.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-no-malloc-custom.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-no-malloc-custom.cpp (removed)
@@ -1,59 +0,0 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-no-malloc %t \
-// RUN: -config='{CheckOptions: \
-// RUN: [{key: cppcoreguidelines-no-malloc.Allocations, value: "::malloc;::align_malloc;::calloc"},\
-// RUN: {key: cppcoreguidelines-no-malloc.Reallocations, value: "::realloc;::align_realloc"},\
-// RUN: {key: cppcoreguidelines-no-malloc.Deallocations, value: "::free;::align_free"}]}' \
-// RUN: --
-
-using size_t = __SIZE_TYPE__;
-
-void *malloc(size_t size);
-void *align_malloc(size_t size, unsigned short aligmnent);
-void *calloc(size_t num, size_t size);
-void *realloc(void *ptr, size_t size);
-void *align_realloc(void *ptr, size_t size, unsigned short alignment);
-void free(void *ptr);
-void *align_free(void *ptr);
-
-void malloced_array() {
- int *array0 = (int *)malloc(sizeof(int) * 20);
- // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: do not manage memory manually; consider a container or a smart pointer [cppcoreguidelines-no-malloc]
-
- int *zeroed = (int *)calloc(20, sizeof(int));
- // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: do not manage memory manually; consider a container or a smart pointer [cppcoreguidelines-no-malloc]
-
- int *aligned = (int *)align_malloc(20 * sizeof(int), 16);
- // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: do not manage memory manually; consider a container or a smart pointer [cppcoreguidelines-no-malloc]
-
- // reallocation memory, std::vector shall be used
- char *realloced = (char *)realloc(array0, 50 * sizeof(int));
- // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: do not manage memory manually; consider std::vector or std::string [cppcoreguidelines-no-malloc]
-
- char *align_realloced = (char *)align_realloc(aligned, 50 * sizeof(int), 16);
- // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: do not manage memory manually; consider std::vector or std::string [cppcoreguidelines-no-malloc]
-
- // freeing memory the bad way
- free(realloced);
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not manage memory manually; use RAII [cppcoreguidelines-no-malloc]
-
- align_free(align_realloced);
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not manage memory manually; use RAII [cppcoreguidelines-no-malloc]
-
- // check if a call to malloc as function argument is found as well
- free(malloc(20));
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not manage memory manually; use RAII [cppcoreguidelines-no-malloc]
- // CHECK-MESSAGES: :[[@LINE-2]]:8: warning: do not manage memory manually; consider a container or a smart pointer [cppcoreguidelines-no-malloc]
-}
-
-/// newing an array is still not good, but not relevant to this checker
-void newed_array() {
- int *new_array = new int[10]; // OK(1)
-}
-
-void arbitrary_call() {
- // we dont want every function to raise the warning even if malloc is in the name
- malloced_array(); // OK(2)
-
- // completly unrelated function call to malloc
- newed_array(); // OK(3)
-}
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-no-malloc-no-functions.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-no-malloc-no-functions.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-no-malloc-no-functions.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-no-malloc-no-functions.cpp (removed)
@@ -1,17 +0,0 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-no-malloc %t \
-// RUN: -config='{CheckOptions: \
-// RUN: [{key: cppcoreguidelines-no-malloc.Allocations, value: "::malloc"},\
-// RUN: {key: cppcoreguidelines-no-malloc.Reallocations, value: ""},\
-// RUN: {key: cppcoreguidelines-no-malloc.Deallocations, value: ""}]}' \
-// RUN: --
-
-// Just ensure, the check will not crash, when no functions shall be checked.
-
-using size_t = __SIZE_TYPE__;
-
-void *malloc(size_t size);
-
-void malloced_array() {
- int *array0 = (int *)malloc(sizeof(int) * 20);
- // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: do not manage memory manually; consider a container or a smart pointer [cppcoreguidelines-no-malloc]
-}
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-no-malloc.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-no-malloc.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-no-malloc.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-no-malloc.cpp (removed)
@@ -1,42 +0,0 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-no-malloc %t
-
-using size_t = __SIZE_TYPE__;
-
-void *malloc(size_t size);
-void *calloc(size_t num, size_t size);
-void *realloc(void *ptr, size_t size);
-void free(void *ptr);
-
-void malloced_array() {
- int *array0 = (int *)malloc(sizeof(int) * 20);
- // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: do not manage memory manually; consider a container or a smart pointer [cppcoreguidelines-no-malloc]
-
- int *zeroed = (int *)calloc(20, sizeof(int));
- // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: do not manage memory manually; consider a container or a smart pointer [cppcoreguidelines-no-malloc]
-
- // reallocation memory, std::vector shall be used
- char *realloced = (char *)realloc(array0, 50 * sizeof(int));
- // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: do not manage memory manually; consider std::vector or std::string [cppcoreguidelines-no-malloc]
-
- // freeing memory the bad way
- free(realloced);
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not manage memory manually; use RAII [cppcoreguidelines-no-malloc]
-
- // check if a call to malloc as function argument is found as well
- free(malloc(20));
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not manage memory manually; use RAII [cppcoreguidelines-no-malloc]
- // CHECK-MESSAGES: :[[@LINE-2]]:8: warning: do not manage memory manually; consider a container or a smart pointer [cppcoreguidelines-no-malloc]
-}
-
-/// newing an array is still not good, but not relevant to this checker
-void newed_array() {
- int *new_array = new int[10]; // OK(1)
-}
-
-void arbitrary_call() {
- // we dont want every function to raise the warning even if malloc is in the name
- malloced_array(); // OK(2)
-
- // completly unrelated function call to malloc
- newed_array(); // OK(3)
-}
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory-containers.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory-containers.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory-containers.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory-containers.cpp (removed)
@@ -1,62 +0,0 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-owning-memory %t
-
-namespace gsl {
-template <typename T>
-using owner = T;
-}
-
-namespace std {
-
-// Not actually a vector, but more a dynamic, fixed size array. Just to demonstrate
-// functionality or the lack of the same.
-template <typename T>
-class vector {
-public:
- vector(unsigned long size, T val) : data{new T[size]}, size{size} {
- for (unsigned long i = 0ul; i < size; ++i) {
- data[i] = val;
- }
- }
-
- T *begin() { return data; }
- T *end() { return &data[size]; }
- T &operator[](unsigned long index) { return data[index]; }
-
-private:
- T *data;
- unsigned long size;
-};
-
-} // namespace std
-
-// All of the following codesnippets should be valid with appropriate 'owner<>' anaylsis,
-// but currently the type information of 'gsl::owner<>' gets lost in typededuction.
-int main() {
- std::vector<gsl::owner<int *>> OwnerStdVector(100, nullptr);
-
- // Rangebased looping in resource vector.
- for (auto *Element : OwnerStdVector) {
- Element = new int(42);
- // CHECK-NOTES: [[@LINE-1]]:5: warning: assigning newly created 'gsl::owner<>' to non-owner 'int *'
- }
- for (auto *Element : OwnerStdVector) {
- delete Element;
- // CHECK-NOTES: [[@LINE-1]]:5: warning: deleting a pointer through a type that is not marked 'gsl::owner<>'; consider using a smart pointer instead
- // CHECK-NOTES: [[@LINE-3]]:8: note: variable declared here
- }
-
- // Indexbased looping in resource vector.
- for (int i = 0; i < 100; ++i) {
- OwnerStdVector[i] = new int(42);
- // CHECK-NOTES: [[@LINE-1]]:5: warning: assigning newly created 'gsl::owner<>' to non-owner 'int *'
- }
- for (int i = 0; i < 100; ++i) {
- delete OwnerStdVector[i];
- // CHECK-NOTES: [[@LINE-1]]:5: warning: deleting a pointer through a type that is not marked 'gsl::owner<>'; consider using a smart pointer instead
- // CHECK-NOTES: [[@LINE-21]]:3: note: variable declared here
- // A note gets emitted here pointing to the return value of the operator[] from the
- // vector implementation. Maybe this is considered misleading.
- }
-
- return 0;
-}
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory-legacy-functions.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory-legacy-functions.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory-legacy-functions.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory-legacy-functions.cpp (removed)
@@ -1,194 +0,0 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-owning-memory %t \
-// RUN: -config='{CheckOptions: \
-// RUN: [{key: cppcoreguidelines-owning-memory.LegacyResourceProducers, value: "::malloc;::aligned_alloc;::realloc;::calloc;::fopen;::freopen;::tmpfile"}, \
-// RUN: {key: cppcoreguidelines-owning-memory.LegacyResourceConsumers, value: "::free;::realloc;::freopen;::fclose"}]}' \
-// RUN: -- -nostdlib -nostdinc++
-
-namespace gsl {
-template <class T>
-using owner = T;
-} // namespace gsl
-
-extern "C" {
-using size_t = decltype(sizeof(void*));
-using FILE = int;
-
-void *malloc(size_t ByteCount);
-void *aligned_alloc(size_t Alignment, size_t Size);
-void *calloc(size_t Count, size_t SizeSingle);
-void *realloc(void *Resource, size_t NewByteCount);
-void free(void *Resource);
-
-FILE *tmpfile(void);
-FILE *fopen(const char *filename, const char *mode);
-FILE *freopen(const char *filename, const char *mode, FILE *stream);
-void fclose(FILE *Resource);
-}
-
-namespace std {
-using ::FILE;
-using ::size_t;
-
-using ::fclose;
-using ::fopen;
-using ::freopen;
-using ::tmpfile;
-
-using ::aligned_alloc;
-using ::calloc;
-using ::free;
-using ::malloc;
-using ::realloc;
-} // namespace std
-
-void nonOwningCall(int *Resource, size_t Size) {}
-void nonOwningCall(FILE *Resource) {}
-
-void consumesResource(gsl::owner<int *> Resource, size_t Size) {}
-void consumesResource(gsl::owner<FILE *> Resource) {}
-
-void testNonCasted(void *Resource) {}
-
-void testNonCastedOwner(gsl::owner<void *> Resource) {}
-
-FILE *fileFactory1() { return ::fopen("new_file.txt", "w"); }
-// CHECK-MESSAGES: [[@LINE-1]]:24: warning: returning a newly created resource of type 'FILE *' (aka 'int *') or 'gsl::owner<>' from a function whose return type is not 'gsl::owner<>'
-gsl::owner<FILE *> fileFactory2() { return std::fopen("new_file.txt", "w"); } // Ok
-
-int *arrayFactory1() { return (int *)std::malloc(100); }
-// CHECK-MESSAGES: [[@LINE-1]]:24: warning: returning a newly created resource of type 'int *' or 'gsl::owner<>' from a function whose return type is not 'gsl::owner<>'
-gsl::owner<int *> arrayFactory2() { return (int *)std::malloc(100); } // Ok
-void *dataFactory1() { return std::malloc(100); }
-// CHECK-MESSAGES: [[@LINE-1]]:24: warning: returning a newly created resource of type 'void *' or 'gsl::owner<>' from a function whose return type is not 'gsl::owner<>'
-gsl::owner<void *> dataFactory2() { return std::malloc(100); } // Ok
-
-void test_resource_creators() {
- const unsigned int ByteCount = 25 * sizeof(int);
- int Bad = 42;
-
- int *IntArray1 = (int *)std::malloc(ByteCount);
- // CHECK-MESSAGES: [[@LINE-1]]:3: warning: initializing non-owner 'int *' with a newly created 'gsl::owner<>'
- int *IntArray2 = static_cast<int *>(std::malloc(ByteCount)); // Bad
- // CHECK-MESSAGES: [[@LINE-1]]:3: warning: initializing non-owner 'int *' with a newly created 'gsl::owner<>'
- void *IntArray3 = std::malloc(ByteCount);
- // CHECK-MESSAGES: [[@LINE-1]]:3: warning: initializing non-owner 'void *' with a newly created 'gsl::owner<>'
-
- int *IntArray4 = (int *)::malloc(ByteCount);
- // CHECK-MESSAGES: [[@LINE-1]]:3: warning: initializing non-owner 'int *' with a newly created 'gsl::owner<>'
- int *IntArray5 = static_cast<int *>(::malloc(ByteCount)); // Bad
- // CHECK-MESSAGES: [[@LINE-1]]:3: warning: initializing non-owner 'int *' with a newly created 'gsl::owner<>'
- void *IntArray6 = ::malloc(ByteCount);
- // CHECK-MESSAGES: [[@LINE-1]]:3: warning: initializing non-owner 'void *' with a newly created 'gsl::owner<>'
-
- gsl::owner<int *> IntArray7 = (int *)malloc(ByteCount); // Ok
- gsl::owner<void *> IntArray8 = malloc(ByteCount); // Ok
-
- gsl::owner<int *> IntArray9 = &Bad;
- // CHECK-MESSAGES: [[@LINE-1]]:3: warning: expected initialization with value of type 'gsl::owner<>'; got 'int *'
-
- nonOwningCall((int *)malloc(ByteCount), 25);
- // CHECK-MESSAGES: [[@LINE-1]]:24: warning: initializing non-owner argument of type 'int *' with a newly created 'gsl::owner<>'
- nonOwningCall((int *)::malloc(ByteCount), 25);
- // CHECK-MESSAGES: [[@LINE-1]]:24: warning: initializing non-owner argument of type 'int *' with a newly created 'gsl::owner<>'
-
- consumesResource((int *)malloc(ByteCount), 25); // Ok
- consumesResource((int *)::malloc(ByteCount), 25); // Ok
-
- testNonCasted(malloc(ByteCount));
- // CHECK-MESSAGES: [[@LINE-1]]:17: warning: initializing non-owner argument of type 'void *' with a newly created 'gsl::owner<>'
- testNonCastedOwner(gsl::owner<void *>(malloc(ByteCount))); // Ok
- testNonCastedOwner(malloc(ByteCount)); // Ok
-
- FILE *File1 = std::fopen("test_name.txt", "w+");
- // CHECK-MESSAGES: [[@LINE-1]]:3: warning: initializing non-owner 'FILE *' (aka 'int *') with a newly created 'gsl::owner<>'
- FILE *File2 = ::fopen("test_name.txt", "w+");
- // CHECK-MESSAGES: [[@LINE-1]]:3: warning: initializing non-owner 'FILE *' (aka 'int *') with a newly created 'gsl::owner<>'
-
- gsl::owner<FILE *> File3 = ::fopen("test_name.txt", "w+"); // Ok
-
- FILE *File4;
- File4 = ::fopen("test_name.txt", "w+");
- // CHECK-MESSAGES: [[@LINE-1]]:3: warning: assigning newly created 'gsl::owner<>' to non-owner 'FILE *' (aka 'int *')
-
- gsl::owner<FILE *> File5;
- File5 = ::fopen("test_name.txt", "w+"); // Ok
- File5 = File1;
- // CHECK-MESSAGES: [[@LINE-1]]:3: warning: expected assignment source to be of type 'gsl::owner<>'; got 'FILE *' (aka 'int *')
-
- gsl::owner<FILE *> File6 = File1;
- // CHECK-MESSAGES: [[@LINE-1]]:3: warning: expected initialization with value of type 'gsl::owner<>'; got 'FILE *' (aka 'int *')
-
- FILE *File7 = tmpfile();
- // CHECK-MESSAGES: [[@LINE-1]]:3: warning: initializing non-owner 'FILE *' (aka 'int *') with a newly created 'gsl::owner<>'
- gsl::owner<FILE *> File8 = tmpfile(); // Ok
-
- nonOwningCall(::fopen("test_name.txt", "r"));
- // CHECK-MESSAGES: [[@LINE-1]]:17: warning: initializing non-owner argument of type 'FILE *' (aka 'int *') with a newly created 'gsl::owner<>'
- nonOwningCall(std::fopen("test_name.txt", "r"));
- // CHECK-MESSAGES: [[@LINE-1]]:17: warning: initializing non-owner argument of type 'FILE *' (aka 'int *') with a newly created 'gsl::owner<>'
-
- consumesResource(::fopen("test_name.txt", "r")); // Ok
-
- int *HeapPointer3 = (int *)aligned_alloc(16ul, 4ul * 32ul);
- // CHECK-MESSAGES: [[@LINE-1]]:3: warning: initializing non-owner 'int *' with a newly created 'gsl::owner<>'
- gsl::owner<int *> HeapPointer4 = static_cast<int *>(aligned_alloc(16ul, 4ul * 32ul)); // Ok
-
- void *HeapPointer5 = calloc(10ul, 4ul);
- // CHECK-MESSAGES: [[@LINE-1]]:3: warning: initializing non-owner 'void *' with a newly created 'gsl::owner<>'
- gsl::owner<void *> HeapPointer6 = calloc(10ul, 4ul); // Ok
-}
-
-void test_legacy_consumers() {
- int StackInteger = 42;
-
- int *StackPointer = &StackInteger;
- int *HeapPointer1 = (int *)malloc(100);
- // CHECK-MESSAGES: [[@LINE-1]]:3: warning: initializing non-owner 'int *' with a newly created 'gsl::owner<>'
- gsl::owner<int *> HeapPointer2 = (int *)malloc(100);
-
- std::free(StackPointer);
- // CHECK-MESSAGES: [[@LINE-1]]:3: warning: calling legacy resource function without passing a 'gsl::owner<>'
- std::free(HeapPointer1);
- // CHECK-MESSAGES: [[@LINE-1]]:3: warning: calling legacy resource function without passing a 'gsl::owner<>'
- std::free(HeapPointer2); // Ok
- // CHECK MESSAGES: [[@LINE-1]]:3: warning: calling legacy resource function without passing a 'gsl::owner<>'
-
- // FIXME: the check complains about initialization of 'void *' with new created owner.
- // This happens, because the argument of `free` is not marked as 'owner<>' (and cannot be),
- // and the check will not figure out could be meant as owner.
- // This property will probably never be fixed, because it is probably a rather rare
- // use-case and 'owner<>' should be wrapped in RAII classes anyway!
- std::free(std::malloc(100)); // Ok but silly :)
- // CHECK-MESSAGES: [[@LINE-1]]:13: warning: initializing non-owner argument of type 'void *' with a newly created 'gsl::owner<>'
-
- // Demonstrate, that multi-argument functions are diagnosed as well.
- std::realloc(StackPointer, 200);
- // CHECK-MESSAGES: [[@LINE-1]]:3: warning: calling legacy resource function without passing a 'gsl::owner<>'
- std::realloc(HeapPointer1, 200);
- // CHECK-MESSAGES: [[@LINE-1]]:3: warning: calling legacy resource function without passing a 'gsl::owner<>'
- std::realloc(HeapPointer2, 200); // Ok
- std::realloc(std::malloc(100), 200); // Ok but silly
- // CHECK-MESSAGES: [[@LINE-1]]:16: warning: initializing non-owner argument of type 'void *' with a newly created 'gsl::owner<>'
-
- fclose(fileFactory1());
- // CHECK-MESSAGES: [[@LINE-1]]:3: warning: calling legacy resource function without passing a 'gsl::owner<>'
- fclose(fileFactory2()); // Ok, same as FIXME with `free(malloc(100))` applies here
- // CHECK-MESSAGES: [[@LINE-1]]:10: warning: initializing non-owner argument of type 'FILE *' (aka 'int *') with a newly created 'gsl::owner<>'
-
- gsl::owner<FILE *> File1 = fopen("testfile.txt", "r"); // Ok
- FILE *File2 = freopen("testfile.txt", "w", File1);
- // CHECK-MESSAGES: [[@LINE-1]]:3: warning: initializing non-owner 'FILE *' (aka 'int *') with a newly created 'gsl::owner<>'
- // CHECK-MESSAGES: [[@LINE-2]]:17: warning: calling legacy resource function without passing a 'gsl::owner<>'
- // FIXME: The warning for not passing and owner<> is a false positive since both the filename and the
- // mode are not supposed to be owners but still pointers. The check is to coarse for
- // this function. Maybe `freopen` gets special treatment.
-
- gsl::owner<FILE *> File3 = freopen("testfile.txt", "w", File2); // Bad, File2 no owner
- // CHECK-MESSAGES: [[@LINE-1]]:30: warning: calling legacy resource function without passing a 'gsl::owner<>'
-
- FILE *TmpFile = tmpfile();
- // CHECK-MESSAGES: [[@LINE-1]]:3: warning: initializing non-owner 'FILE *' (aka 'int *') with a newly created 'gsl::owner<>'
- FILE *File6 = freopen("testfile.txt", "w", TmpFile); // Bad, both return and argument
- // CHECK-MESSAGES: [[@LINE-1]]:3: warning: initializing non-owner 'FILE *' (aka 'int *') with a newly created 'gsl::owner<>'
- // CHECK-MESSAGES: [[@LINE-2]]:17: warning: calling legacy resource function without passing a 'gsl::owner<>'
-}
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-owning-memory.cpp (removed)
@@ -1,391 +0,0 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-owning-memory %t
-
-namespace gsl {
-template <class T>
-using owner = T;
-} // namespace gsl
-
-template <typename T>
-class unique_ptr {
-public:
- unique_ptr(gsl::owner<T> resource) : memory(resource) {}
- unique_ptr(const unique_ptr<T> &) = default;
-
- ~unique_ptr() { delete memory; }
-
-private:
- gsl::owner<T> memory;
-};
-
-void takes_owner(gsl::owner<int *> owned_int) {
-}
-
-void takes_pointer(int *unowned_int) {
-}
-
-void takes_owner_and_more(int some_int, gsl::owner<int *> owned_int, float f) {
-}
-
-template <typename T>
-void takes_templated_owner(gsl::owner<T> owned_T) {
-}
-
-gsl::owner<int *> returns_owner1() { return gsl::owner<int *>(new int(42)); } // Ok
-gsl::owner<int *> returns_owner2() { return new int(42); } // Ok
-
-int *returns_no_owner1() { return nullptr; }
-int *returns_no_owner2() {
- return new int(42);
- // CHECK-NOTES: [[@LINE-1]]:3: warning: returning a newly created resource of type 'int *' or 'gsl::owner<>' from a function whose return type is not 'gsl::owner<>'
-}
-int *returns_no_owner3() {
- int *should_be_owner = new int(42);
- // CHECK-NOTES: [[@LINE-1]]:3: warning: initializing non-owner 'int *' with a newly created 'gsl::owner<>'
- return should_be_owner;
-}
-int *returns_no_owner4() {
- gsl::owner<int *> owner = new int(42);
- return owner;
- // CHECK-NOTES: [[@LINE-1]]:3: warning: returning a newly created resource of type 'int *' or 'gsl::owner<>' from a function whose return type is not 'gsl::owner<>'
-}
-
-unique_ptr<int *> returns_no_owner5() {
- return unique_ptr<int *>(new int(42)); // Ok
-}
-
-/// FIXME: CSA finds it, but the report is misleading. Ownersemantics can catch this
-/// by flow analysis similar to bugprone-use-after-move.
-void csa_not_finding_leak() {
- gsl::owner<int *> o1 = new int(42); // Ok
-
- gsl::owner<int *> o2 = o1; // Ok
- o2 = new int(45); // conceptual leak, the memory from o1 is now leaked, since its considered moved in the guidelines
-
- delete o2;
- // actual leak occurs here, its found, but mixed
- delete o1;
-}
-
-void test_assignment_and_initialization() {
- int stack_int1 = 15;
- int stack_int2;
-
- gsl::owner<int *> owned_int1 = &stack_int1; // BAD
- // CHECK-NOTES: [[@LINE-1]]:3: warning: expected initialization with value of type 'gsl::owner<>'; got 'int *'
-
- gsl::owner<int *> owned_int2;
- owned_int2 = &stack_int2; // BAD since no owner, bad since uninitialized
- // CHECK-NOTES: [[@LINE-1]]:3: warning: expected assignment source to be of type 'gsl::owner<>'; got 'int *'
-
- gsl::owner<int *> owned_int3 = new int(42); // Good
- owned_int3 = nullptr; // Good
-
- gsl::owner<int *> owned_int4(nullptr); // Ok
- owned_int4 = new int(42); // Good
-
- gsl::owner<int *> owned_int5 = owned_int3; // Good
-
- gsl::owner<int *> owned_int6{nullptr}; // Ok
- owned_int6 = owned_int4; // Good
-
- // FIXME:, flow analysis for the case of reassignment. Value must be released before
- owned_int6 = owned_int3; // BAD, because reassignment without resource release
-
- auto owned_int7 = returns_owner1(); // Bad, since type deduction eliminates the owner wrapper
- // CHECK-NOTES: [[@LINE-1]]:3: warning: initializing non-owner 'int *' with a newly created 'gsl::owner<>'
- // CHECK-NOTES: [[@LINE-2]]:3: note: type deduction did not result in an owner
-
- const auto owned_int8 = returns_owner2(); // Bad, since type deduction eliminates the owner wrapper
- // CHECK-NOTES: [[@LINE-1]]:3: warning: initializing non-owner 'int *const' with a newly created 'gsl::owner<>'
- // CHECK-NOTES: [[@LINE-2]]:3: note: type deduction did not result in an owner
-
- gsl::owner<int *> owned_int9 = returns_owner1(); // Ok
- int *unowned_int3 = returns_owner1(); // Bad
- // CHECK-NOTES: [[@LINE-1]]:3: warning: initializing non-owner 'int *' with a newly created 'gsl::owner<>'
-
- gsl::owner<int *> owned_int10;
- owned_int10 = returns_owner1(); // Ok
-
- int *unowned_int4;
- unowned_int4 = returns_owner1(); // Bad
- // CHECK-NOTES: [[@LINE-1]]:3: warning: assigning newly created 'gsl::owner<>' to non-owner 'int *'
-
- gsl::owner<int *> owned_int11 = returns_no_owner1(); // Bad since no owner
- // CHECK-NOTES: [[@LINE-1]]:3: warning: expected initialization with value of type 'gsl::owner<>'; got 'int *'
-
- gsl::owner<int *> owned_int12;
- owned_int12 = returns_no_owner1(); // Bad since no owner
- // CHECK-NOTES: [[@LINE-1]]:3: warning: expected assignment source to be of type 'gsl::owner<>'; got 'int *'
-
- int *unowned_int5 = returns_no_owner1(); // Ok
- int *unowned_int6;
- unowned_int6 = returns_no_owner1(); // Ok
-
- int *unowned_int7 = new int(42); // Bad, since resource not assigned to an owner
- // CHECK-NOTES: [[@LINE-1]]:3: warning: initializing non-owner 'int *' with a newly created 'gsl::owner<>'
-
- int *unowned_int8;
- unowned_int8 = new int(42);
- // CHECK-NOTES: [[@LINE-1]]:3: warning: assigning newly created 'gsl::owner<>' to non-owner 'int *'
-
- gsl::owner<int *> owned_int13 = nullptr; // Ok
-}
-
-void test_deletion() {
- gsl::owner<int *> owned_int1 = new int(42);
- delete owned_int1; // Good
-
- gsl::owner<int *> owned_int2 = new int[42];
- delete[] owned_int2; // Good
-
- int *unowned_int1 = new int(42); // BAD, since new creates and owner
- // CHECK-NOTES: [[@LINE-1]]:3: warning: initializing non-owner 'int *' with a newly created 'gsl::owner<>'
- delete unowned_int1; // BAD, since no owner
- // CHECK-NOTES: [[@LINE-1]]:3: warning: deleting a pointer through a type that is not marked 'gsl::owner<>'; consider using a smart pointer instead
- // CHECK-NOTES: [[@LINE-4]]:3: note: variable declared here
-
- int *unowned_int2 = new int[42]; // BAD, since new creates and owner
- // CHECK-NOTES: [[@LINE-1]]:3: warning: initializing non-owner 'int *' with a newly created 'gsl::owner<>'
- delete[] unowned_int2; // BAD since no owner
- // CHECK-NOTES: [[@LINE-1]]:3: warning: deleting a pointer through a type that is not marked 'gsl::owner<>'; consider using a smart pointer instead
- // CHECK-NOTES: [[@LINE-4]]:3: note: variable declared here
-
- delete new int(42); // Technically ok, but stupid
- delete[] new int[42]; // Technically ok, but stupid
-}
-
-void test_owner_function_calls() {
- int stack_int = 42;
- int *unowned_int1 = &stack_int;
- takes_owner(&stack_int); // BAD
- // CHECK-NOTES: [[@LINE-1]]:15: warning: expected argument of type 'gsl::owner<>'; got 'int *'
- takes_owner(unowned_int1); // BAD
- // CHECK-NOTES: [[@LINE-1]]:15: warning: expected argument of type 'gsl::owner<>'; got 'int *'
-
- gsl::owner<int *> owned_int1 = new int(42);
- takes_owner(owned_int1); // Ok
-
- takes_owner_and_more(42, &stack_int, 42.0f); // BAD
- // CHECK-NOTES: [[@LINE-1]]:28: warning: expected argument of type 'gsl::owner<>'; got 'int *'
- takes_owner_and_more(42, unowned_int1, 42.0f); // BAD
- // CHECK-NOTES: [[@LINE-1]]:28: warning: expected argument of type 'gsl::owner<>'; got 'int *'
-
- takes_owner_and_more(42, new int(42), 42.0f); // Ok, since new is consumed by owner
- takes_owner_and_more(42, owned_int1, 42.0f); // Ok, since owner as argument
-
- takes_templated_owner(owned_int1); // Ok
- takes_templated_owner(new int(42)); // Ok
- takes_templated_owner(unowned_int1); // Bad
- // CHECK-NOTES: [[@LINE-1]]:25: warning: expected argument of type 'gsl::owner<>'; got 'int *'
-
- takes_owner(returns_owner1()); // Ok
- takes_owner(returns_no_owner1()); // BAD
- // CHECK-NOTES: [[@LINE-1]]:15: warning: expected argument of type 'gsl::owner<>'; got 'int *'
-}
-
-void test_unowned_function_calls() {
- int stack_int = 42;
- int *unowned_int1 = &stack_int;
- gsl::owner<int *> owned_int1 = new int(42);
-
- takes_pointer(&stack_int); // Ok
- takes_pointer(unowned_int1); // Ok
- takes_pointer(owned_int1); // Ok
- takes_pointer(new int(42)); // Bad, since new creates and owner
- // CHECK-NOTES: [[@LINE-1]]:17: warning: initializing non-owner argument of type 'int *' with a newly created 'gsl::owner<>'
-
- takes_pointer(returns_owner1()); // Bad
- // CHECK-NOTES: [[@LINE-1]]:17: warning: initializing non-owner argument of type 'int *' with a newly created 'gsl::owner<>'
-
- takes_pointer(returns_no_owner1()); // Ok
-}
-
-// FIXME: Typedefing owner<> to something else does not work.
-// This might be necessary for code already having a similar typedef like owner<> and
-// replacing it with owner<>. This might be the same problem as with templates.
-// The canonical type will ignore the owner<> alias, since its a typedef as well.
-//
-// Check, if owners hidden by typedef are handled the same as 'obvious' owners.
-#if 0
-using heap_int = gsl::owner<int *>;
-typedef gsl::owner<float *> heap_float;
-
-// This tests only a subset, assuming that the check will either see through the
-// typedef or not (it doesn't!).
-void test_typedefed_values() {
- // Modern typedef.
- int StackInt1 = 42;
- heap_int HeapInt1 = &StackInt1;
- // CHECK MESSAGES: [[@LINE-1]]:3: warning: expected assignment source to be of type 'gsl::owner<>'; got 'int *'
-
- //FIXME: Typedef not considered correctly here.
- // heap_int HeapInt2 = new int(42); // Ok
- takes_pointer(HeapInt1); // Ok
- takes_owner(HeapInt1); // Ok
-
- // Traditional typedef.
- float StackFloat1 = 42.0f;
- heap_float HeapFloat1 = &StackFloat1;
- // CHECK MESSAGES: [[@LINE-1]]:3: warning: expected assignment source to be of type 'gsl::owner<>'; got 'float *'
-
- //FIXME: Typedef not considered correctly here.
- // heap_float HeapFloat2 = new float(42.0f);
- HeapFloat2 = HeapFloat1; // Ok
-}
-#endif
-
-struct ArbitraryClass {};
-struct ClassWithOwner { // Does not define destructor, necessary with owner
- ClassWithOwner() : owner_var(nullptr) {} // Ok
-
- ClassWithOwner(ArbitraryClass &other) : owner_var(&other) {}
- // CHECK-NOTES: [[@LINE-1]]:43: warning: expected initialization of owner member variable with value of type 'gsl::owner<>'; got 'ArbitraryClass *'
-
- ClassWithOwner(gsl::owner<ArbitraryClass *> other) : owner_var(other) {} // Ok
-
- ClassWithOwner(gsl::owner<ArbitraryClass *> data, int /* unused */) { // Ok
- owner_var = data; // Ok
- }
-
- ClassWithOwner(ArbitraryClass *bad_data, int /* unused */, int /* unused */) {
- owner_var = bad_data;
- // CHECK-NOTES: [[@LINE-1]]:5: warning: expected assignment source to be of type 'gsl::owner<>'; got 'ArbitraryClass *'
- }
-
- ClassWithOwner(ClassWithOwner &&other) : owner_var{other.owner_var} {} // Ok
-
- ClassWithOwner &operator=(ClassWithOwner &&other) {
- owner_var = other.owner_var; // Ok
- return *this;
- }
-
- // Returning means, that the owner is "moved", so the class should not access this
- // variable anymore after this method gets called.
- gsl::owner<ArbitraryClass *> buggy_but_returns_owner() { return owner_var; }
-
- gsl::owner<ArbitraryClass *> owner_var;
- // CHECK-NOTES: [[@LINE-1]]:3: warning: member variable of type 'gsl::owner<>' requires the class 'ClassWithOwner' to implement a destructor to release the owned resource
-};
-
-class DefaultedDestructor { // Bad since default constructor with owner
- ~DefaultedDestructor() = default; // Bad, since will not destroy the owner
- gsl::owner<int *> Owner;
- // CHECK-NOTES: [[@LINE-1]]:3: warning: member variable of type 'gsl::owner<>' requires the class 'DefaultedDestructor' to implement a destructor to release the owned resource
-};
-
-struct DeletedDestructor {
- ~DeletedDestructor() = delete;
- gsl::owner<int *> Owner;
- // CHECK-NOTES: [[@LINE-1]]:3: warning: member variable of type 'gsl::owner<>' requires the class 'DeletedDestructor' to implement a destructor to release the owned resource
-};
-
-void test_class_with_owner() {
- ArbitraryClass A;
- ClassWithOwner C1; // Ok
- ClassWithOwner C2{A}; // Bad, since the owner would be initialized with an non-owner, but catched in the class
- ClassWithOwner C3{gsl::owner<ArbitraryClass *>(new ArbitraryClass)}; // Ok
-
- const auto Owner1 = C3.buggy_but_returns_owner(); // BAD, deduces Owner1 to ArbitraryClass *const
- // CHECK-NOTES: [[@LINE-1]]:3: warning: initializing non-owner 'ArbitraryClass *const' with a newly created 'gsl::owner<>'
- // CHECK-NOTES: [[@LINE-2]]:3: note: type deduction did not result in an owner
-
- auto Owner2 = C2.buggy_but_returns_owner(); // BAD, deduces Owner2 to ArbitraryClass *
- // CHECK-NOTES: [[@LINE-1]]:3: warning: initializing non-owner 'ArbitraryClass *' with a newly created 'gsl::owner<>'
- // CHECK-NOTES: [[@LINE-2]]:3: note: type deduction did not result in an owner
-
- Owner2 = &A; // Ok, since type deduction did NOT result in owner<int*>
-
- gsl::owner<ArbitraryClass *> Owner3 = C1.buggy_but_returns_owner(); // Ok, still an owner
- Owner3 = &A; // Bad, since assignment of non-owner to owner
- // CHECK-NOTES: [[@LINE-1]]:3: warning: expected assignment source to be of type 'gsl::owner<>'; got 'ArbitraryClass *'
-}
-
-template <typename T>
-struct HeapArray { // Ok, since destructor with owner
- HeapArray() : _data(nullptr), size(0) {} // Ok
- HeapArray(int size) : _data(new int[size]), size(size) {} // Ok
- HeapArray(int size, T val) {
- _data = new int[size]; // Ok
- size = size;
- for (auto i = 0u; i < size; ++i)
- _data[i] = val; // Ok
- }
- HeapArray(int size, T val, int *problematic) : _data{problematic}, size(size) {} // Bad
- // CHECK-NOTES: [[@LINE-1]]:50: warning: expected initialization of owner member variable with value of type 'gsl::owner<>'; got 'void'
- // FIXME: void is incorrect type, probably wrong thing matched
-
- HeapArray(HeapArray &&other) : _data(other._data), size(other.size) { // Ok
- other._data = nullptr; // Ok
- other.size = 0;
- }
-
- HeapArray<T> &operator=(HeapArray<T> &&other) {
- _data = other._data; // Ok, NOLINT warning here about bad types, why?
- size = other.size;
- return *this;
- }
-
- ~HeapArray() { delete[] _data; } // Ok
-
- T *data() { return _data; } // Ok NOLINT, because it "looks" like a factory
-
- gsl::owner<T *> _data;
- unsigned int size;
-};
-
-void test_inner_template() {
- HeapArray<int> Array1;
- HeapArray<int> Array2(100);
- HeapArray<int> Array3(100, 0);
- HeapArray<int> Array4(100, 0, nullptr);
-
- Array1 = static_cast<HeapArray<int> &&>(Array2);
- HeapArray<int> Array5(static_cast<HeapArray<int> &&>(Array3));
-
- int *NonOwningPtr = Array1.data(); // Ok
- gsl::owner<int *> OwningPtr = Array1.data(); // Bad, since it does not return the owner
- // CHECK-NOTES: [[@LINE-1]]:3: warning: expected initialization with value of type 'gsl::owner<>'; got 'int *'
-}
-
-// FIXME: Typededuction removes the owner - wrapper, therefore gsl::owner can not be used
-// with Template classes like this. Is there a walkaround?
-template <typename T>
-struct TemplateValue {
- TemplateValue() = default;
- TemplateValue(T t) : val{t} {}
-
- void setVal(const T &t) { val = t; }
- const T getVal() const { return val; }
-
- T val;
-};
-
-// FIXME: Same typededcution problems
-template <typename T>
-void template_function(T t) {
- gsl::owner<int *> owner_t = t; // Probably bad, since type deduction still wrong
- // CHECK-NOTES: [[@LINE-1]]:3: warning: expected initialization with value of type 'gsl::owner<>'; got 'T'
- // CHECK-NOTES: [[@LINE-2]]:3: warning: expected initialization with value of type 'gsl::owner<>'; got 'int *'
-}
-
-// FIXME: Same typededcution problems
-void test_templates() {
- int stack_int = 42;
- int *stack_ptr1 = &stack_int;
-
- TemplateValue<gsl::owner<int *>> Owner0; // Ok, T should be owner, but is int*
-
- TemplateValue<gsl::owner<int *>> Owner1(new int(42)); // Ok, T should be owner, but is int*
- Owner1.setVal(&stack_int); // Bad since non-owner assignment
- Owner1.setVal(stack_ptr1); // Bad since non-owner assignment
- //Owner1.setVal(new int(42)); // Ok, but since type deduction is wrong, this one is considered harmful
-
- int *stack_ptr2 = Owner1.getVal(); // Bad, initializing non-owner with owner
-
- TemplateValue<int *> NonOwner1(new int(42)); // Bad, T is int *, hence dynamic memory to non-owner
- gsl::owner<int *> IntOwner1 = NonOwner1.getVal(); // Bad, since owner initialized with non-owner
- // CHECK-NOTES: [[@LINE-1]]:3: warning: expected initialization with value of type 'gsl::owner<>'; got 'int *'
-
- template_function(IntOwner1); // Ok, but not actually ok, since type deduction removes owner
- template_function(stack_ptr1); // Bad, but type deduction gets it wrong
-}
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp (removed)
@@ -1,51 +0,0 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-pro-bounds-array-to-pointer-decay %t
-#include <stddef.h>
-
-namespace gsl {
-template <class T>
-class array_view {
-public:
- template <class U, size_t N>
- array_view(U (&arr)[N]);
-};
-}
-
-void pointerfun(int *p);
-void arrayfun(int p[]);
-void arrayviewfun(gsl::array_view<int> &p);
-size_t s();
-
-void f() {
- int a[5];
- pointerfun(a);
- // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit cast instead [cppcoreguidelines-pro-bounds-array-to-pointer-decay]
- pointerfun((int *)a); // OK, explicit cast
- arrayfun(a);
- // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: do not implicitly decay an array into a pointer
-
- pointerfun(a + s() - 10); // Convert to &a[g() - 10];
- // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: do not implicitly decay an array into a pointer
-
- gsl::array_view<int> av(a);
- arrayviewfun(av); // OK
-
- int i = a[0]; // OK
- int j = a[(1 + 2)];// OK
- pointerfun(&a[0]); // OK
-
- for (auto &e : a) // OK, iteration internally decays array to pointer
- e = 1;
-}
-
-const char *g() {
- return "clang"; // OK, decay string literal to pointer
-}
-const char *g2() {
- return ("clang"); // OK, ParenExpr hides the literal-pointer decay
-}
-
-void f2(void *const *);
-void bug25362() {
- void *a[2];
- f2(static_cast<void *const*>(a)); // OK, explicit cast
-}
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index-c++03.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index-c%2B%2B03.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index-c++03.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index-c++03.cpp (removed)
@@ -1,12 +0,0 @@
-// RUN: %check_clang_tidy -std=c++98-or-later %s cppcoreguidelines-pro-bounds-constant-array-index %t
-
-// Note: this test expects no diagnostics, but FileCheck cannot handle that,
-// hence the use of | count 0.
-template <int index> struct B {
- int get() {
- // The next line used to crash the check (in C++03 mode only).
- return x[index];
- // CHECK-FIXES: return x[index];
- }
- int x[3];
-};
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index-gslheader.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index-gslheader.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index-gslheader.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index-gslheader.cpp (removed)
@@ -1,80 +0,0 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-pro-bounds-constant-array-index %t -- \
-// RUN: -config='{CheckOptions: [{key: cppcoreguidelines-pro-bounds-constant-array-index.GslHeader, value: "dir1/gslheader.h"}]}'
-// CHECK-FIXES: #include "dir1/gslheader.h"
-
-typedef __SIZE_TYPE__ size_t;
-
-namespace std {
- template<typename T, size_t N>
- struct array {
- T& operator[](size_t n);
- T& at(size_t n);
- };
-}
-
-
-namespace gsl {
- template<class T, size_t N>
- T& at( T(&a)[N], size_t index );
-
- template<class T, size_t N>
- T& at( std::array<T, N> &a, size_t index );
-}
-
-constexpr int const_index(int base) {
- return base + 3;
-}
-
-void f(std::array<int, 10> a, int pos) {
- a [ pos / 2 /*comment*/] = 1;
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use array subscript when the index is not an integer constant expression; use gsl::at() instead [cppcoreguidelines-pro-bounds-constant-array-index]
- // CHECK-FIXES: gsl::at(a, pos / 2 /*comment*/) = 1;
- int j = a[pos - 1];
- // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: do not use array subscript when the index is not an integer constant expression; use gsl::at() instead
- // CHECK-FIXES: int j = gsl::at(a, pos - 1);
-
- a.at(pos-1) = 2; // OK, at() instead of []
- gsl::at(a, pos-1) = 2; // OK, gsl::at() instead of []
-
- a[-1] = 3;
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index -1 is negative [cppcoreguidelines-pro-bounds-constant-array-index]
- a[10] = 4;
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index 10 is past the end of the array (which contains 10 elements) [cppcoreguidelines-pro-bounds-constant-array-index]
-
- a[const_index(7)] = 3;
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index 10 is past the end of the array (which contains 10 elements)
-
- a[0] = 3; // OK, constant index and inside bounds
- a[1] = 3; // OK, constant index and inside bounds
- a[9] = 3; // OK, constant index and inside bounds
- a[const_index(6)] = 3; // OK, constant index and inside bounds
-}
-
-void g() {
- int a[10];
- for (int i = 0; i < 10; ++i) {
- a[i] = i;
- // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not use array subscript when the index is not an integer constant expression; use gsl::at() instead
- // CHECK-FIXES: gsl::at(a, i) = i;
- gsl::at(a, i) = i; // OK, gsl::at() instead of []
- }
-
- a[-1] = 3; // flagged by clang-diagnostic-array-bounds
- a[10] = 4; // flagged by clang-diagnostic-array-bounds
- a[const_index(7)] = 3; // flagged by clang-diagnostic-array-bounds
-
- a[0] = 3; // OK, constant index and inside bounds
- a[1] = 3; // OK, constant index and inside bounds
- a[9] = 3; // OK, constant index and inside bounds
- a[const_index(6)] = 3; // OK, constant index and inside bounds
-}
-
-struct S {
- int& operator[](int i);
-};
-
-void customOperator() {
- S s;
- int i = 0;
- s[i] = 3; // OK, custom operator
-}
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index.cpp (removed)
@@ -1,87 +0,0 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-pro-bounds-constant-array-index %t
-
-typedef __SIZE_TYPE__ size_t;
-
-namespace std {
- template<typename T, size_t N>
- struct array {
- T& operator[](size_t n);
- T& at(size_t n);
- };
-}
-
-
-namespace gsl {
- template<class T, size_t N>
- T& at( T(&a)[N], size_t index );
-
- template<class T, size_t N>
- T& at( std::array<T, N> &a, size_t index );
-}
-
-constexpr int const_index(int base) {
- return base + 3;
-}
-
-void f(std::array<int, 10> a, int pos) {
- a [ pos / 2 /*comment*/] = 1;
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use array subscript when the index is not an integer constant expression; use gsl::at() instead [cppcoreguidelines-pro-bounds-constant-array-index]
- int j = a[pos - 1];
- // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: do not use array subscript when the index is not an integer constant expression; use gsl::at() instead
-
- a.at(pos-1) = 2; // OK, at() instead of []
- gsl::at(a, pos-1) = 2; // OK, gsl::at() instead of []
-
- a[-1] = 3;
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index -1 is negative [cppcoreguidelines-pro-bounds-constant-array-index]
- a[10] = 4;
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index 10 is past the end of the array (which contains 10 elements) [cppcoreguidelines-pro-bounds-constant-array-index]
-
- a[const_index(7)] = 3;
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index 10 is past the end of the array (which contains 10 elements)
-
- a[0] = 3; // OK, constant index and inside bounds
- a[1] = 3; // OK, constant index and inside bounds
- a[9] = 3; // OK, constant index and inside bounds
- a[const_index(6)] = 3; // OK, constant index and inside bounds
-}
-
-void g() {
- int a[10];
- for (int i = 0; i < 10; ++i) {
- a[i] = i;
- // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not use array subscript when the index is not an integer constant expression; use gsl::at() instead
- // CHECK-FIXES: gsl::at(a, i) = i;
- gsl::at(a, i) = i; // OK, gsl::at() instead of []
- }
-
- a[-1] = 3; // flagged by clang-diagnostic-array-bounds
- a[10] = 4; // flagged by clang-diagnostic-array-bounds
- a[const_index(7)] = 3; // flagged by clang-diagnostic-array-bounds
-
- a[0] = 3; // OK, constant index and inside bounds
- a[1] = 3; // OK, constant index and inside bounds
- a[9] = 3; // OK, constant index and inside bounds
- a[const_index(6)] = 3; // OK, constant index and inside bounds
-}
-
-struct S {
- int& operator[](int i);
-};
-
-void customOperator() {
- S s;
- int i = 0;
- s[i] = 3; // OK, custom operator
-}
-
-struct A {
- // The compiler-generated copy constructor uses an ArraySubscriptExpr. Don't warn.
- int x[3];
-};
-
-void use_A() {
- // Force the compiler to generate a copy constructor.
- A a;
- A a2(a);
-}
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic-pr36489.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic-pr36489.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic-pr36489.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic-pr36489.cpp (removed)
@@ -1,53 +0,0 @@
-// RUN: %check_clang_tidy -std=c++14-or-later %s cppcoreguidelines-pro-bounds-pointer-arithmetic %t
-
-// Fix PR36489 and detect auto-deduced value correctly.
-char *getPtr();
-auto getPtrAuto() { return getPtr(); }
-decltype(getPtr()) getPtrDeclType();
-decltype(auto) getPtrDeclTypeAuto() { return getPtr(); }
-auto getPtrWithTrailingReturnType() -> char *;
-
-void auto_deduction_binary() {
- auto p1 = getPtr() + 1;
- // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: do not use pointer arithmetic
- auto p2 = getPtrAuto() + 1;
- // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: do not use pointer arithmetic
- auto p3 = getPtrWithTrailingReturnType() + 1;
- // CHECK-MESSAGES: :[[@LINE-1]]:44: warning: do not use pointer arithmetic
- auto p4 = getPtr();
- auto *p5 = getPtr();
- p4 = p4 + 1;
- // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: do not use pointer arithmetic
- p5 = p5 + 1;
- // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: do not use pointer arithmetic
- auto p6 = getPtrDeclType() + 1;
- // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: do not use pointer arithmetic
- auto p7 = getPtrDeclTypeAuto() + 1;
- // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: do not use pointer arithmetic
- auto *p8 = getPtrDeclType() + 1;
- // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: do not use pointer arithmetic
- auto *p9 = getPtrDeclTypeAuto() + 1;
- // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: do not use pointer arithmetic
-}
-
-void auto_deduction_subscript() {
- char p1 = getPtr()[2];
- // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use pointer arithmetic
- auto p2 = getPtr()[3];
- // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use pointer arithmetic
-
- char p3 = getPtrAuto()[4];
- // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use pointer arithmetic
- auto p4 = getPtrAuto()[5];
- // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use pointer arithmetic
-
- char p5 = getPtrWithTrailingReturnType()[6];
- // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use pointer arithmetic
- auto p6 = getPtrWithTrailingReturnType()[7];
- // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use pointer arithmetic
-
- auto p7 = getPtrDeclType()[8];
- // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use pointer arithmetic
- auto p8 = getPtrDeclTypeAuto()[9];
- // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use pointer arithmetic
-}
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp (removed)
@@ -1,89 +0,0 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-pro-bounds-pointer-arithmetic %t
-
-enum E {
- ENUM_LITERAL = 1
-};
-
-int i = 4;
-int j = 1;
-int *p = 0;
-int *q = 0;
-
-void fail() {
- q = p + 4;
- // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic]
- p = q + i;
- // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: do not use pointer arithmetic
- p = q + ENUM_LITERAL;
- // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: do not use pointer arithmetic
-
- q = p - 1;
- // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: do not use pointer arithmetic
- p = q - i;
- // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: do not use pointer arithmetic
- p = q - ENUM_LITERAL;
- // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: do not use pointer arithmetic
-
- p += 4;
- // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not use pointer arithmetic
- p += i;
- // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not use pointer arithmetic
- p += ENUM_LITERAL;
- // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not use pointer arithmetic
-
- q -= 1;
- // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not use pointer arithmetic
- q -= i;
- // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not use pointer arithmetic
- q -= ENUM_LITERAL;
- // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not use pointer arithmetic
-
- p++;
- // CHECK-MESSAGES: :[[@LINE-1]]:4: warning: do not use pointer arithmetic
- ++p;
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use pointer arithmetic
-
- p--;
- // CHECK-MESSAGES: :[[@LINE-1]]:4: warning: do not use pointer arithmetic
- --p;
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use pointer arithmetic
-
- i = p[1];
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: do not use pointer arithmetic
-}
-
-struct S {
- operator int() const;
-};
-
-void f(S &s) {
- int *i;
- i = i + s;
- // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: do not use pointer arithmetic
-}
-
-void f2(int i[]) {
- i[1] = 0;
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use pointer arithmetic
-}
-
-void okay() {
- int a[3];
- i = a[2]; // OK, access to array
-
- p = q;
- p = &i;
-
- i++;
- ++i;
- i--;
- --i;
- i += 1;
- i -= 1;
- i = j + 1;
- i = j - 1;
-
- auto diff = p - q; // OK, result is arithmetic
-
- for(int ii : a) ; // OK, pointer arithmetic generated by compiler
-}
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-const-cast.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-const-cast.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-const-cast.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-const-cast.cpp (removed)
@@ -1,6 +0,0 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-pro-type-const-cast %t
-
-const int *i;
-int *j;
-void f() { j = const_cast<int *>(i); }
-// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: do not use const_cast [cppcoreguidelines-pro-type-const-cast]
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-cstyle-cast.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-cstyle-cast.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-cstyle-cast.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-cstyle-cast.cpp (removed)
@@ -1,141 +0,0 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-pro-type-cstyle-cast %t
-
-void reinterpretcast() {
- int i = 0;
- void *j;
- j = (int*)j;
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: do not use C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast]
-}
-
-void constcast() {
- int* i;
- const int* j;
- i = (int*)j;
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: do not use C-style cast to cast away constness
- j = (const int*)i; // OK, const added
- (void)j; // OK, not a const_cast
-}
-
-void const_and_reinterpret() {
- int* i;
- const void* j;
- i = (int*)j;
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: do not use C-style cast to convert between unrelated types
-}
-
-class Base {
-};
-
-class Derived : public Base {
-};
-
-class Base2 {
-};
-
-class MultiDerived : public Base, public Base2 {
-};
-
-class PolymorphicBase {
-public:
- virtual ~PolymorphicBase();
-};
-
-class PolymorphicDerived : public PolymorphicBase {
-};
-
-class PolymorphicMultiDerived : public Base, public PolymorphicBase {
-};
-
-void pointers() {
-
- auto P0 = (Derived*)new Base();
- // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use C-style cast to downcast from a base to a derived class
-
- const Base* B0;
- auto PC0 = (const Derived*)(B0);
- // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: do not use C-style cast to downcast from a base to a derived class
-
- auto P1 = (Base*)new Derived(); // OK, upcast to a public base
- auto P2 = (Base*)new MultiDerived(); // OK, upcast to a public base
- auto P3 = (Base2*)new MultiDerived(); // OK, upcast to a public base
-}
-
-void pointers_polymorphic() {
-
- auto PP0 = (PolymorphicDerived*)new PolymorphicBase();
- // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: do not use C-style cast to downcast from a base to a derived class; use dynamic_cast instead
- // CHECK-FIXES: auto PP0 = dynamic_cast<PolymorphicDerived*>(new PolymorphicBase());
-
- const PolymorphicBase* B0;
- auto PPC0 = (const PolymorphicDerived*)B0;
- // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: do not use C-style cast to downcast from a base to a derived class; use dynamic_cast instead
- // CHECK-FIXES: auto PPC0 = dynamic_cast<const PolymorphicDerived*>(B0);
-
-
- auto B1 = (PolymorphicBase*)new PolymorphicDerived(); // OK, upcast to a public base
- auto B2 = (PolymorphicBase*)new PolymorphicMultiDerived(); // OK, upcast to a public base
- auto B3 = (Base*)new PolymorphicMultiDerived(); // OK, upcast to a public base
-}
-
-void arrays() {
- Base ArrayOfBase[10];
- auto A0 = (Derived*)ArrayOfBase;
- // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use C-style cast to downcast from a base to a derived class
-}
-
-void arrays_polymorphic() {
- PolymorphicBase ArrayOfPolymorphicBase[10];
- auto AP0 = (PolymorphicDerived*)ArrayOfPolymorphicBase;
- // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: do not use C-style cast to downcast from a base to a derived class; use dynamic_cast instead
- // CHECK-FIXES: auto AP0 = dynamic_cast<PolymorphicDerived*>(ArrayOfPolymorphicBase);
-}
-
-void references() {
- Base B0;
- auto R0 = (Derived&)B0;
- // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use C-style cast to downcast from a base to a derived class
- Base& RefToBase = B0;
- auto R1 = (Derived&)RefToBase;
- // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use C-style cast to downcast from a base to a derived class
-
- const Base& ConstRefToBase = B0;
- auto RC1 = (const Derived&)ConstRefToBase;
- // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: do not use C-style cast to downcast from a base to a derived class
-
-
- Derived RD1;
- auto R2 = (Base&)RD1; // OK, upcast to a public base
-}
-
-void references_polymorphic() {
- PolymorphicBase B0;
- auto RP0 = (PolymorphicDerived&)B0;
- // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: do not use C-style cast to downcast from a base to a derived class; use dynamic_cast instead
- // CHECK-FIXES: auto RP0 = dynamic_cast<PolymorphicDerived&>(B0);
-
- PolymorphicBase& RefToPolymorphicBase = B0;
- auto RP1 = (PolymorphicDerived&)RefToPolymorphicBase;
- // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: do not use C-style cast to downcast from a base to a derived class; use dynamic_cast instead
- // CHECK-FIXES: auto RP1 = dynamic_cast<PolymorphicDerived&>(RefToPolymorphicBase);
-
- const PolymorphicBase& ConstRefToPolymorphicBase = B0;
- auto RPC2 = (const PolymorphicDerived&)(ConstRefToPolymorphicBase);
- // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: do not use C-style cast to downcast from a base to a derived class; use dynamic_cast instead
- // CHECK-FIXES: auto RPC2 = dynamic_cast<const PolymorphicDerived&>(ConstRefToPolymorphicBase);
-
- PolymorphicDerived d1;
- auto RP2 = (PolymorphicBase&)d1; // OK, upcast to a public base
-}
-
-template<class B, class D>
-void templ() {
- auto B0 = (B*)new D();
-}
-
-void templ_bad_call() {
- templ<Derived, Base>(); //FIXME: this should trigger a warning
-}
-
-void templ_good_call() {
- templ<Base, Derived>(); // OK, upcast to a public base
-}
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init-cxx2a.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init-cxx2a.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init-cxx2a.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init-cxx2a.cpp (removed)
@@ -1,19 +0,0 @@
-// RUN: %check_clang_tidy -std=c++2a %s cppcoreguidelines-pro-type-member-init %t -- -- -fno-delayed-template-parsing
-
-struct PositiveBitfieldMember {
- PositiveBitfieldMember() {}
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields: F
- unsigned F : 5;
- // CHECK-FIXES: unsigned F : 5{};
-};
-
-struct NegativeUnnamedBitfieldMember {
- NegativeUnnamedBitfieldMember() {}
- unsigned : 5;
-};
-
-struct NegativeInitializedBitfieldMembers {
- NegativeInitializedBitfieldMembers() : F(3) { G = 2; }
- unsigned F : 5;
- unsigned G : 5;
-};
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init-cxx98.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init-cxx98.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init-cxx98.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init-cxx98.cpp (removed)
@@ -1,116 +0,0 @@
-// RUN: %check_clang_tidy -std=c++98 %s cppcoreguidelines-pro-type-member-init %t -- -- -fno-delayed-template-parsing
-
-struct PositiveFieldBeforeConstructor {
- int F;
- PositiveFieldBeforeConstructor() /* some comment */ {}
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields: F
- // CHECK-FIXES: PositiveFieldBeforeConstructor() : F() /* some comment */ {}
-};
-
-struct PositiveFieldAfterConstructor {
- PositiveFieldAfterConstructor() {}
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields: F, G, H
- // CHECK-FIXES: PositiveFieldAfterConstructor() : F(), G(), H() {}
- int F;
- bool G /* with comment */;
- int *H;
- PositiveFieldBeforeConstructor IgnoredField;
-};
-
-struct PositiveSeparateDefinition {
- PositiveSeparateDefinition();
- int F;
-};
-
-PositiveSeparateDefinition::PositiveSeparateDefinition() {}
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: constructor does not initialize these fields: F
-// CHECK-FIXES: PositiveSeparateDefinition::PositiveSeparateDefinition() : F() {}
-
-struct PositiveMixedFieldOrder {
- PositiveMixedFieldOrder() : /* some comment */ J(0), L(0), M(0) {}
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields: I, K, N
- // CHECK-FIXES: PositiveMixedFieldOrder() : I(), /* some comment */ J(0), K(), L(0), M(0), N() {}
- int I;
- int J;
- int K;
- int L;
- int M;
- int N;
-};
-
-struct PositiveAfterBaseInitializer : public PositiveMixedFieldOrder {
- PositiveAfterBaseInitializer() : PositiveMixedFieldOrder() {}
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields: F
- // CHECK-FIXES: PositiveAfterBaseInitializer() : PositiveMixedFieldOrder(), F() {}
- int F;
-};
-
-struct NegativeFieldInitialized {
- int F;
-
- NegativeFieldInitialized() : F() {}
-};
-
-struct NegativeFieldInitializedInDefinition {
- int F;
-
- NegativeFieldInitializedInDefinition();
-};
-
-NegativeFieldInitializedInDefinition::NegativeFieldInitializedInDefinition() : F() {}
-
-struct NegativeInitializedInBody {
- NegativeInitializedInBody() { I = 0; }
- int I;
-};
-
-struct NegativeAggregateType {
- int X;
- int Y;
- int Z;
-};
-
-struct TrivialType {
- int X;
- int Y;
-};
-
-struct PositiveUninitializedBaseOrdering : public NegativeAggregateType,
- public TrivialType {
- PositiveUninitializedBaseOrdering() : NegativeAggregateType(), TrivialType(), B() {}
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields: A
- // CHECK-FIXES: PositiveUninitializedBaseOrdering() : NegativeAggregateType(), TrivialType(), A(), B() {}
-
- // This is somewhat pathological with the base class initializer at the end...
- PositiveUninitializedBaseOrdering(int) : B(), TrivialType(), A() {}
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these bases: NegativeAggregateType
- // CHECK-FIXES: PositiveUninitializedBaseOrdering(int) : B(), NegativeAggregateType(), TrivialType(), A() {}
-
- PositiveUninitializedBaseOrdering(float) : NegativeAggregateType(), A() {}
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these bases: TrivialType
- // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: constructor does not initialize these fields: B
- // CHECK-FIXES: PositiveUninitializedBaseOrdering(float) : NegativeAggregateType(), TrivialType(), A(), B() {}
-
- int A, B;
-};
-
-template <class T>
-class PositiveTemplateBase : T {
-public:
- PositiveTemplateBase() {}
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields: X
- // CHECK-FIXES: PositiveTemplateBase() : X() {}
-
- int X;
-};
-
-class PositiveIndirectMember {
- struct {
- int *A;
- };
-
- PositiveIndirectMember() : A() {}
- PositiveIndirectMember(int) {}
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields: A
- // CHECK-FIXES: PositiveIndirectMember(int) : A() {}
-};
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init-delayed.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init-delayed.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init-delayed.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init-delayed.cpp (removed)
@@ -1,32 +0,0 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-pro-type-member-init %t -- -- -fdelayed-template-parsing
-
-template <class T>
-struct PositiveFieldBeforeConstructor {
- int F;
- bool G /* with comment */;
- int *H;
- PositiveFieldBeforeConstructor() {}
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields: F, G, H
-};
-// Explicit instantiation.
-template class PositiveFieldBeforeConstructor<int>;
-
-template <class T>
-struct PositiveFieldAfterConstructor {
- PositiveFieldAfterConstructor() {}
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields: F, G, H
- int F;
- bool G /* with comment */;
- int *H;
-};
-// Explicit instantiation.
-template class PositiveFieldAfterConstructor<int>;
-
-// This declaration isn't used and won't be parsed 'delayed-template-parsing'.
-// The body of the declaration is 'null' and may cause crash if not handled
-// properly by checkers.
-template <class T>
-struct UnusedDelayedConstructor {
- UnusedDelayedConstructor() {}
- int F;
-};
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init-no-crash.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init-no-crash.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init-no-crash.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init-no-crash.cpp (removed)
@@ -1,7 +0,0 @@
-// RUN: %check_clang_tidy -expect-clang-tidy-error %s cppcoreguidelines-pro-type-member-init %t
-
-struct X {
- X x;
- // CHECK-MESSAGES: :[[@LINE-1]]:5: error: field has incomplete type 'X' [clang-diagnostic-error]
- int a = 10;
-};
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init-use-assignment.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init-use-assignment.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init-use-assignment.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init-use-assignment.cpp (removed)
@@ -1,40 +0,0 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-pro-type-member-init %t -- -config="{CheckOptions: [{key: "cppcoreguidelines-pro-type-member-init.UseAssignment", value: 1}]}" -- -fsigned-char
-
-struct T {
- int i;
-};
-
-struct S {
- bool b;
- // CHECK-FIXES: bool b = false;
- char c;
- // CHECK-FIXES: char c = 0;
- signed char sc;
- // CHECK-FIXES: signed char sc = 0;
- unsigned char uc;
- // CHECK-FIXES: unsigned char uc = 0U;
- int i;
- // CHECK-FIXES: int i = 0;
- unsigned u;
- // CHECK-FIXES: unsigned u = 0U;
- long l;
- // CHECK-FIXES: long l = 0L;
- unsigned long ul;
- // CHECK-FIXES: unsigned long ul = 0UL;
- long long ll;
- // CHECK-FIXES: long long ll = 0LL;
- unsigned long long ull;
- // CHECK-FIXES: unsigned long long ull = 0ULL;
- float f;
- // CHECK-FIXES: float f = 0.0F;
- double d;
- // CHECK-FIXES: double d = 0.0;
- long double ld;
- // CHECK-FIXES: double ld = 0.0L;
- int *ptr;
- // CHECK-FIXES: int *ptr = nullptr;
- T t;
- // CHECK-FIXES: T t{};
- S() {}
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields:
-};
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp (removed)
@@ -1,503 +0,0 @@
-// RUN: %check_clang_tidy -std=c++11,c++14,c++17 %s cppcoreguidelines-pro-type-member-init %t -- -- -fno-delayed-template-parsing
-// FIXME: Fix the checker to work in C++2a mode.
-
-struct PositiveFieldBeforeConstructor {
- int F;
- // CHECK-FIXES: int F{};
- PositiveFieldBeforeConstructor() {}
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields: F
- // CHECK-FIXES: PositiveFieldBeforeConstructor() {}
-};
-
-struct PositiveFieldAfterConstructor {
- PositiveFieldAfterConstructor() {}
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields: F, G
- // CHECK-FIXES: PositiveFieldAfterConstructor() {}
- int F;
- // CHECK-FIXES: int F{};
- bool G /* with comment */;
- // CHECK-FIXES: bool G{} /* with comment */;
- PositiveFieldBeforeConstructor IgnoredField;
-};
-
-struct PositiveSeparateDefinition {
- PositiveSeparateDefinition();
- int F;
- // CHECK-FIXES: int F{};
-};
-
-PositiveSeparateDefinition::PositiveSeparateDefinition() {}
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: constructor does not initialize these fields: F
-// CHECK-FIXES: PositiveSeparateDefinition::PositiveSeparateDefinition() {}
-
-struct PositiveMixedFieldOrder {
- PositiveMixedFieldOrder() : J(0) {}
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields: I, K
- // CHECK-FIXES: PositiveMixedFieldOrder() : J(0) {}
- int I;
- // CHECK-FIXES: int I{};
- int J;
- int K;
- // CHECK-FIXES: int K{};
-};
-
-template <typename T>
-struct Template {
- Template() {}
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields: F
- int F;
- // CHECK-FIXES: int F{};
- T T1;
- // CHECK-FIXES: T T1;
-};
-
-void instantiate() {
- Template<int> TInt;
-}
-
-struct NegativeFieldInitialized {
- int F;
-
- NegativeFieldInitialized() : F() {}
-};
-
-struct NegativeFieldInitializedInDefinition {
- int F;
-
- NegativeFieldInitializedInDefinition();
-};
-NegativeFieldInitializedInDefinition::NegativeFieldInitializedInDefinition() : F() {}
-
-struct NegativeInClassInitialized {
- int F = 0;
-
- NegativeInClassInitialized() {}
-};
-
-struct NegativeInClassInitializedDefaulted {
- int F = 0;
- NegativeInClassInitializedDefaulted() = default;
-};
-
-struct NegativeConstructorDelegated {
- int F;
-
- NegativeConstructorDelegated(int F) : F(F) {}
- NegativeConstructorDelegated() : NegativeConstructorDelegated(0) {}
-};
-
-struct NegativeInitializedInBody {
- NegativeInitializedInBody() { I = 0; }
- int I;
-};
-
-struct A {};
-template <class> class AA;
-template <class T> class NegativeTemplateConstructor {
- NegativeTemplateConstructor(const AA<T> &, A) {}
- bool Bool{false};
- // CHECK-FIXES: bool Bool{false};
-};
-
-#define UNINITIALIZED_FIELD_IN_MACRO_BODY(FIELD) \
- struct UninitializedField##FIELD { \
- UninitializedField##FIELD() {} \
- int FIELD; \
- }; \
-// Ensure FIELD is not initialized since fixes inside of macros are disabled.
-// CHECK-FIXES: int FIELD;
-
-UNINITIALIZED_FIELD_IN_MACRO_BODY(F);
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: constructor does not initialize these fields: F
-UNINITIALIZED_FIELD_IN_MACRO_BODY(G);
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: constructor does not initialize these fields: G
-
-#define UNINITIALIZED_FIELD_IN_MACRO_ARGUMENT(ARGUMENT) \
- ARGUMENT
-
-UNINITIALIZED_FIELD_IN_MACRO_ARGUMENT(struct UninitializedFieldInMacroArg {
- UninitializedFieldInMacroArg() {}
- int Field;
-});
-// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: constructor does not initialize these fields: Field
-// Ensure FIELD is not initialized since fixes inside of macros are disabled.
-// CHECK-FIXES: int Field;
-
-struct NegativeAggregateType {
- int X;
- int Y;
- int Z;
-};
-
-struct PositiveTrivialType {
- PositiveTrivialType() {}
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields: F
-
- NegativeAggregateType F;
- // CHECK-FIXES: NegativeAggregateType F{};
-};
-
-struct NegativeNonTrivialType {
- PositiveTrivialType F;
-};
-
-static void PositiveUninitializedTrivialType() {
- NegativeAggregateType X;
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: uninitialized record type: 'X'
- // CHECK-FIXES: NegativeAggregateType X{};
-
- NegativeAggregateType A[10]; // Don't warn because this isn't an object type.
-}
-
-static void NegativeInitializedTrivialType() {
- NegativeAggregateType X{};
- NegativeAggregateType Y = {};
- NegativeAggregateType Z = NegativeAggregateType();
- NegativeAggregateType A[10]{};
- NegativeAggregateType B[10] = {};
- int C; // No need to initialize this because we don't have a constructor.
- int D[8];
- NegativeAggregateType E = {0, 1, 2};
- NegativeAggregateType F({});
-}
-
-struct NonTrivialType {
- NonTrivialType() = default;
- NonTrivialType(const NonTrivialType &RHS) : X(RHS.X), Y(RHS.Y) {}
-
- int X;
- int Y;
-};
-
-static void PositiveNonTrivialTypeWithCopyConstructor() {
- NonTrivialType T;
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: uninitialized record type: 'T'
- // CHECK-FIXES: NonTrivialType T{};
-
- NonTrivialType A[8];
- // Don't warn because this isn't an object type
-}
-
-struct ComplexNonTrivialType {
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: constructor does not initialize these fields: Y
- NegativeFieldInitialized X;
- int Y;
- // CHECK-FIXES: int Y{};
-};
-
-static void PositiveComplexNonTrivialType() {
- ComplexNonTrivialType T;
-}
-
-struct NegativeStaticMember {
- static NonTrivialType X;
- static NonTrivialType Y;
- static constexpr NonTrivialType Z{};
-};
-
-NonTrivialType NegativeStaticMember::X;
-NonTrivialType NegativeStaticMember::Y{};
-
-struct PositiveMultipleConstructors {
- PositiveMultipleConstructors() {}
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields: A, B
-
- PositiveMultipleConstructors(int) {}
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields: A, B
-
- PositiveMultipleConstructors(const PositiveMultipleConstructors &) {}
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields: A, B
-
- // FIXME: The fix-its here collide providing an erroneous fix
- int A, B;
- // CHECK-FIXES: int A{}{}{}, B{}{}{};
-};
-
-typedef struct {
- int Member;
-} CStyleStruct;
-
-struct PositiveUninitializedBase : public NegativeAggregateType, CStyleStruct {
- PositiveUninitializedBase() {}
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these bases: NegativeAggregateType, CStyleStruct
- // CHECK-FIXES: PositiveUninitializedBase() : NegativeAggregateType(), CStyleStruct() {}
-};
-
-struct PositiveUninitializedBaseOrdering : public NegativeAggregateType,
- public NonTrivialType {
- PositiveUninitializedBaseOrdering() : B() {}
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these bases: NegativeAggregateType, NonTrivialType
- // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: constructor does not initialize these fields: A
- // CHECK-FIXES: PositiveUninitializedBaseOrdering() : NegativeAggregateType(), NonTrivialType(), B() {}
-
- // This is somewhat pathological with the base class initializer at the end...
- PositiveUninitializedBaseOrdering(int) : B(), NonTrivialType(), A() {}
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these bases: NegativeAggregateType
- // CHECK-FIXES: PositiveUninitializedBaseOrdering(int) : B(), NegativeAggregateType(), NonTrivialType(), A() {}
-
- PositiveUninitializedBaseOrdering(float) : B(), NegativeAggregateType(), A() {}
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these bases: NonTrivialType
- // CHECK-FIXES: PositiveUninitializedBaseOrdering(float) : B(), NegativeAggregateType(), NonTrivialType(), A() {}
-
- int A, B;
- // CHECK-FIXES: int A{}, B;
-};
-
-// We shouldn't need to initialize anything because PositiveUninitializedBase
-// has a user-defined constructor.
-struct NegativeUninitializedBase : public PositiveUninitializedBase {
- NegativeUninitializedBase() {}
-};
-
-struct InheritedAggregate : public NegativeAggregateType {
- int F;
-};
-
-static InheritedAggregate NegativeGlobal;
-
-enum TestEnum {
- A,
- B,
- C
-};
-
-enum class TestScopedEnum {
- A,
- B,
- C
-};
-
-struct PositiveEnumType {
- PositiveEnumType() {}
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields: X, Y
- // No proposed fixes, as we don't know whether value initialization for these
- // enums really makes sense.
-
- TestEnum X;
- TestScopedEnum Y;
-};
-
-extern "C" {
-struct NegativeCStruct {
- int X, Y, Z;
-};
-
-static void PositiveCStructVariable() {
- NegativeCStruct X;
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: uninitialized record type: 'X'
- // CHECK-FIXES: NegativeCStruct X{};
-}
-}
-
-static void NegativeStaticVariable() {
- static NegativeCStruct S;
- (void)S;
-}
-
-union NegativeUnionInClass {
- NegativeUnionInClass() {} // No message as a union can only initialize one member.
- int X = 0;
- float Y;
-};
-
-union PositiveUnion {
- PositiveUnion() : X() {} // No message as a union can only initialize one member.
- PositiveUnion(int) {}
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: union constructor should initialize one of these fields: X, Y
-
- int X;
- // CHECK-FIXES: int X{};
-
- // Make sure we don't give Y an initializer.
- float Y;
- // CHECK-FIXES-NOT: float Y{};
-};
-
-union PositiveUnionReversed {
- PositiveUnionReversed() : X() {} // No message as a union can only initialize one member.
- PositiveUnionReversed(int) {}
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: union constructor should initialize one of these fields: Y, X
-
- // Make sure we don't give Y an initializer.
- TestEnum Y;
- // CHECK-FIXES-NOT: TestEnum Y{};
-
- int X;
- // CHECK-FIXES: int X{};
-};
-
-struct PositiveAnonymousUnionAndStruct {
- PositiveAnonymousUnionAndStruct() {}
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields: A, B, Y, Z, C, D, E, F, X
-
- union {
- int A;
- // CHECK-FIXES: int A{};
- short B;
- };
-
- struct {
- int Y;
- // CHECK-FIXES: int Y{};
- char *Z;
- // CHECK-FIXES: char *Z{};
-
- struct {
- short C;
- // CHECK-FIXES: short C{};
- double D;
- // CHECK-FIXES: double D{};
- };
-
- union {
- long E;
- // CHECK-FIXES: long E{};
- float F;
- };
- };
- int X;
- // CHECK-FIXES: int X{};
-};
-
-// This check results in a CXXConstructorDecl with no body.
-struct NegativeDeletedConstructor : NegativeAggregateType {
- NegativeDeletedConstructor() = delete;
-
- Template<int> F;
-};
-
-// This pathological template fails to compile if actually instantiated. It
-// results in the check seeing a null RecordDecl when examining the base class
-// initializer list.
-template <typename T>
-class PositiveSelfInitialization : NegativeAggregateType
-{
- PositiveSelfInitialization() : PositiveSelfInitialization() {}
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these bases: NegativeAggregateType
- // CHECK-FIXES: PositiveSelfInitialization() : NegativeAggregateType(), PositiveSelfInitialization() {}
-};
-
-class PositiveIndirectMember {
- struct {
- int *A;
- // CHECK-FIXES: int *A{};
- };
-
- PositiveIndirectMember() {}
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields: A
-};
-
-void Bug30487()
-{
- NegativeInClassInitializedDefaulted s;
-}
-
-struct PositiveVirtualMethod {
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: constructor does not initialize these fields: F
- int F;
- // CHECK-FIXES: int F{};
- virtual int f() = 0;
-};
-
-struct PositiveVirtualDestructor {
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: constructor does not initialize these fields: F
- PositiveVirtualDestructor() = default;
- int F;
- // CHECK-FIXES: int F{};
- virtual ~PositiveVirtualDestructor() {}
-};
-
-struct PositiveVirtualBase : public virtual NegativeAggregateType {
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: constructor does not initialize these bases: NegativeAggregateType
- // CHECK-MESSAGES: :[[@LINE-2]]:8: warning: constructor does not initialize these fields: F
- int F;
- // CHECK-FIXES: int F{};
-};
-
-template <typename T>
-struct PositiveTemplateVirtualDestructor {
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: constructor does not initialize these fields: F
- T Val;
- int F;
- // CHECK-FIXES: int F{};
- virtual ~PositiveTemplateVirtualDestructor() = default;
-};
-
-template struct PositiveTemplateVirtualDestructor<int>;
-
-#define UNINITIALIZED_FIELD_IN_MACRO_BODY_VIRTUAL(FIELD) \
- struct UninitializedFieldVirtual##FIELD { \
- int FIELD; \
- virtual ~UninitializedFieldVirtual##FIELD() {} \
- }; \
-// Ensure FIELD is not initialized since fixes inside of macros are disabled.
-// CHECK-FIXES: int FIELD;
-
-UNINITIALIZED_FIELD_IN_MACRO_BODY_VIRTUAL(F);
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: constructor does not initialize these fields: F
-UNINITIALIZED_FIELD_IN_MACRO_BODY_VIRTUAL(G);
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: constructor does not initialize these fields: G
-
-struct NegativeEmpty {
-};
-
-static void NegativeEmptyVar() {
- NegativeEmpty e;
- (void)e;
-}
-
-struct NegativeEmptyMember {
- NegativeEmptyMember() {}
- NegativeEmpty e;
-};
-
-struct NegativeEmptyBase : NegativeEmpty {
- NegativeEmptyBase() {}
-};
-
-struct NegativeEmptyArrayMember {
- NegativeEmptyArrayMember() {}
- char e[0];
-};
-
-struct NegativeIncompleteArrayMember {
- NegativeIncompleteArrayMember() {}
- char e[];
-};
-
-template <typename T> class NoCrash {
- class B : public NoCrash {
- template <typename U> B(U u) {}
- };
-};
-
-struct PositiveBitfieldMember {
- PositiveBitfieldMember() {}
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields: F
- unsigned F : 5;
- // CHECK-FIXES-NOT: unsigned F : 5{};
-};
-
-struct NegativeUnnamedBitfieldMember {
- NegativeUnnamedBitfieldMember() {}
- unsigned : 5;
-};
-
-struct NegativeInitializedBitfieldMembers {
- NegativeInitializedBitfieldMembers() : F(3) { G = 2; }
- unsigned F : 5;
- unsigned G : 5;
-};
-
-struct NegativeImplicitInheritedCtorBase {
- NegativeImplicitInheritedCtorBase(unsigned F) : F(F) {}
- unsigned F;
-};
-
-struct NegativeImplicitInheritedCtor : NegativeImplicitInheritedCtorBase {
- using NegativeImplicitInheritedCtorBase::NegativeImplicitInheritedCtorBase;
-};
-
-void Bug33557() {
- NegativeImplicitInheritedCtor I(5);
-}
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-reinterpret-cast.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-reinterpret-cast.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-reinterpret-cast.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-reinterpret-cast.cpp (removed)
@@ -1,6 +0,0 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-pro-type-reinterpret-cast %t
-
-int i = 0;
-void *j;
-void f() { j = reinterpret_cast<void *>(i); }
-// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: do not use reinterpret_cast [cppcoreguidelines-pro-type-reinterpret-cast]
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-static-cast-downcast.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-static-cast-downcast.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-static-cast-downcast.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-static-cast-downcast.cpp (removed)
@@ -1,118 +0,0 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-pro-type-static-cast-downcast %t
-
-class Base {
-};
-
-class Derived : public Base {
-};
-
-class Base2 {
-};
-
-class MultiDerived : public Base, public Base2 {
-};
-
-class PolymorphicBase {
-public:
- virtual ~PolymorphicBase();
-};
-
-class PolymorphicDerived : public PolymorphicBase {
-};
-
-class PolymorphicMultiDerived : public Base, public PolymorphicBase {
-};
-
-void pointers() {
-
- auto P0 = static_cast<Derived*>(new Base());
- // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use static_cast to downcast from a base to a derived class [cppcoreguidelines-pro-type-static-cast-downcast]
-
- const Base* B0;
- auto PC0 = static_cast<const Derived*>(B0);
- // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: do not use static_cast to downcast from a base to a derived class [cppcoreguidelines-pro-type-static-cast-downcast]
-
- auto P1 = static_cast<Base*>(new Derived()); // OK, upcast to a public base
- auto P2 = static_cast<Base*>(new MultiDerived()); // OK, upcast to a public base
- auto P3 = static_cast<Base2*>(new MultiDerived()); // OK, upcast to a public base
-}
-
-void pointers_polymorphic() {
-
- auto PP0 = static_cast<PolymorphicDerived*>(new PolymorphicBase());
- // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: do not use static_cast to downcast from a base to a derived class; use dynamic_cast instead [cppcoreguidelines-pro-type-static-cast-downcast]
- // CHECK-FIXES: auto PP0 = dynamic_cast<PolymorphicDerived*>(new PolymorphicBase());
-
- const PolymorphicBase* B0;
- auto PPC0 = static_cast<const PolymorphicDerived*>(B0);
- // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: do not use static_cast to downcast from a base to a derived class; use dynamic_cast instead [cppcoreguidelines-pro-type-static-cast-downcast]
- // CHECK-FIXES: auto PPC0 = dynamic_cast<const PolymorphicDerived*>(B0);
-
-
- auto B1 = static_cast<PolymorphicBase*>(new PolymorphicDerived()); // OK, upcast to a public base
- auto B2 = static_cast<PolymorphicBase*>(new PolymorphicMultiDerived()); // OK, upcast to a public base
- auto B3 = static_cast<Base*>(new PolymorphicMultiDerived()); // OK, upcast to a public base
-}
-
-void arrays() {
- Base ArrayOfBase[10];
- auto A0 = static_cast<Derived*>(ArrayOfBase);
- // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use static_cast to downcast from a base to a derived class [cppcoreguidelines-pro-type-static-cast-downcast]
-}
-
-void arrays_polymorphic() {
- PolymorphicBase ArrayOfPolymorphicBase[10];
- auto AP0 = static_cast<PolymorphicDerived*>(ArrayOfPolymorphicBase);
- // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: do not use static_cast to downcast from a base to a derived class; use dynamic_cast instead
- // CHECK-FIXES: auto AP0 = dynamic_cast<PolymorphicDerived*>(ArrayOfPolymorphicBase);
-}
-
-void references() {
- Base B0;
- auto R0 = static_cast<Derived&>(B0);
- // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use static_cast to downcast from a base to a derived class [cppcoreguidelines-pro-type-static-cast-downcast]
- Base& RefToBase = B0;
- auto R1 = static_cast<Derived&>(RefToBase);
- // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use static_cast to downcast from a base to a derived class [cppcoreguidelines-pro-type-static-cast-downcast]
-
- const Base& ConstRefToBase = B0;
- auto RC1 = static_cast<const Derived&>(ConstRefToBase);
- // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: do not use static_cast to downcast from a base to a derived class [cppcoreguidelines-pro-type-static-cast-downcast]
-
-
- Derived RD1;
- auto R2 = static_cast<Base&>(RD1); // OK, upcast to a public base
-}
-
-void references_polymorphic() {
- PolymorphicBase B0;
- auto RP0 = static_cast<PolymorphicDerived&>(B0);
- // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: do not use static_cast to downcast from a base to a derived class; use dynamic_cast instead
- // CHECK-FIXES: auto RP0 = dynamic_cast<PolymorphicDerived&>(B0);
-
- PolymorphicBase& RefToPolymorphicBase = B0;
- auto RP1 = static_cast<PolymorphicDerived&>(RefToPolymorphicBase);
- // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: do not use static_cast to downcast from a base to a derived class; use dynamic_cast instead [cppcoreguidelines-pro-type-static-cast-downcast]
- // CHECK-FIXES: auto RP1 = dynamic_cast<PolymorphicDerived&>(RefToPolymorphicBase);
-
- const PolymorphicBase& ConstRefToPolymorphicBase = B0;
- auto RPC2 = static_cast<const PolymorphicDerived&>(ConstRefToPolymorphicBase);
- // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: do not use static_cast to downcast from a base to a derived class; use dynamic_cast instead [cppcoreguidelines-pro-type-static-cast-downcast]
- // CHECK-FIXES: auto RPC2 = dynamic_cast<const PolymorphicDerived&>(ConstRefToPolymorphicBase);
-
- PolymorphicDerived d1;
- auto RP2 = static_cast<PolymorphicBase&>(d1); // OK, upcast to a public base
-}
-
-template<class B, class D>
-void templ() {
- auto B0 = static_cast<B*>(new D());
-}
-
-void templ_bad_call() {
- templ<Derived, Base>(); //FIXME: this should trigger a warning
-}
-
-void templ_good_call() {
- templ<Base, Derived>(); // OK, upcast to a public base
-}
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-union-access.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-union-access.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-union-access.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-union-access.cpp (removed)
@@ -1,41 +0,0 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-pro-type-union-access %t
-
-union U {
- bool union_member1;
- char union_member2;
-} u;
-
-struct S {
- int non_union_member;
- union {
- bool union_member;
- };
- union {
- char union_member2;
- } u;
-} s;
-
-
-void f(char);
-void f2(U);
-void f3(U&);
-void f4(U*);
-
-void check()
-{
- u.union_member1 = true;
- // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not access members of unions; use (boost::)variant instead [cppcoreguidelines-pro-type-union-access]
- auto b = u.union_member2;
- // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: do not access members of unions; use (boost::)variant instead
- auto a = &s.union_member;
- // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: do not access members of unions; use (boost::)variant instead
- f(s.u.union_member2);
- // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: do not access members of unions; use (boost::)variant instead
-
- s.non_union_member = 2; // OK
-
- U u2 = u; // OK
- f2(u); // OK
- f3(u); // OK
- f4(&u); // OK
-}
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-vararg.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-vararg.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-vararg.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-vararg.cpp (removed)
@@ -1,51 +0,0 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-pro-type-vararg %t
-
-void f(int i);
-void f_vararg(int i, ...);
-
-struct C {
- void g_vararg(...);
- void g(const char*);
-} c;
-
-template<typename... P>
-void cpp_vararg(P... p);
-
-void check() {
- f_vararg(1, 7, 9);
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not call c-style vararg functions [cppcoreguidelines-pro-type-vararg]
- c.g_vararg("foo");
- // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not call c-style vararg functions
-
- f(3); // OK
- c.g("foo"); // OK
- cpp_vararg(1, 7, 9); // OK
-}
-
-// ... as a parameter is allowed (e.g. for SFINAE)
-template <typename T>
-void CallFooIfAvailableImpl(T& t, ...) {
- // nothing
-}
-template <typename T>
-void CallFooIfAvailableImpl(T& t, decltype(t.foo())*) {
- t.foo();
-}
-template <typename T>
-void CallFooIfAvailable(T& t) {
- CallFooIfAvailableImpl(t, 0); // OK to call variadic function when the argument is a literal 0
-}
-
-#include <stdarg.h>
-void my_printf(const char* format, ...) {
- va_list ap;
- va_start(ap, format);
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not call c-style vararg functions
- va_list n;
- va_copy(n, ap); // Don't warn, va_copy is anyway useless without va_start
- int i = va_arg(ap, int);
- // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: do not use va_start/va_arg to define c-style vararg functions; use variadic templates instead
- va_end(ap); // Don't warn, va_end is anyway useless without va_start
-}
-
-int my_vprintf(const char* format, va_list arg ); // OK to declare function taking va_list
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-slicing.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-slicing.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-slicing.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-slicing.cpp (removed)
@@ -1,100 +0,0 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-slicing %t
-
-class Base {
- int i;
- void f() {}
- virtual void g() {}
-};
-
-class DerivedWithMemberVariables : public Base {
- void f();
- int j;
-};
-
-class TwiceDerivedWithNoMemberVariables : public DerivedWithMemberVariables {
- void f();
-};
-
-class DerivedWithOverride : public Base {
- void f();
- void g() override {}
-};
-
-class TwiceDerivedWithNoOverride : public DerivedWithOverride {
- void f();
-};
-
-void TakesBaseByValue(Base base);
-
-DerivedWithMemberVariables ReturnsDerived();
-
-void positivesWithMemberVariables() {
- DerivedWithMemberVariables b;
- Base a{b};
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: slicing object from type 'DerivedWithMemberVariables' to 'Base' discards {{[0-9]*}} bytes of state [cppcoreguidelines-slicing]
- a = b;
- // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: slicing object from type 'DerivedWithMemberVariables' to 'Base' discards {{[0-9]*}} bytes of state
- TakesBaseByValue(b);
- // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: slicing object from type 'DerivedWithMemberVariables' to 'Base' discards {{[0-9]*}} bytes of state
-
- TwiceDerivedWithNoMemberVariables c;
- a = c;
- // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: slicing object from type 'TwiceDerivedWithNoMemberVariables' to 'Base' discards {{[0-9]*}} bytes of state
-
- a = ReturnsDerived();
- // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: slicing object from type 'DerivedWithMemberVariables' to 'Base' discards {{[0-9]*}} bytes of state
-}
-
-void positivesWithOverride() {
- DerivedWithOverride b;
- Base a{b};
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: slicing object from type 'DerivedWithOverride' to 'Base' discards override 'g'
- a = b;
- // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: slicing object from type 'DerivedWithOverride' to 'Base' discards override 'g'
- TakesBaseByValue(b);
- // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: slicing object from type 'DerivedWithOverride' to 'Base' discards override 'g'
-
- TwiceDerivedWithNoOverride c;
- a = c;
- // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: slicing object from type 'DerivedWithOverride' to 'Base' discards override 'g'
-}
-
-void TakesBaseByReference(Base &base);
-
-class DerivedThatAddsVirtualH : public Base {
- virtual void h();
-};
-
-class DerivedThatOverridesH : public DerivedThatAddsVirtualH {
- void h() override;
-};
-
-void negatives() {
- // OK, simple copying from the same type.
- Base a;
- TakesBaseByValue(a);
- DerivedWithMemberVariables b;
- DerivedWithMemberVariables c{b};
- b = c;
-
- // OK, derived type does not have extra state.
- TwiceDerivedWithNoMemberVariables d;
- DerivedWithMemberVariables e{d};
- e = d;
-
- // OK, derived does not override any method.
- TwiceDerivedWithNoOverride f;
- DerivedWithOverride g{f};
- g = f;
-
- // OK, no copying.
- TakesBaseByReference(d);
- TakesBaseByReference(f);
-
- // Derived type overrides methods, but these methods are not in the base type,
- // so cannot be called accidentally. Right now this triggers, but we might
- // want to allow it.
- DerivedThatOverridesH h;
- a = h;
- // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: slicing object from type 'DerivedThatOverridesH' to 'Base' discards override 'h'
-}
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-special-member-functions-cxx-03.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-special-member-functions-cxx-03.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-special-member-functions-cxx-03.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-special-member-functions-cxx-03.cpp (removed)
@@ -1,26 +0,0 @@
-// RUN: %check_clang_tidy -std=c++98 %s cppcoreguidelines-special-member-functions %t
-
-class DefinesDestructor {
- ~DefinesDestructor();
-};
-// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesDestructor' defines a non-default destructor but does not define a copy constructor or a copy assignment operator [cppcoreguidelines-special-member-functions]
-
-class DefinesCopyConstructor {
- DefinesCopyConstructor(const DefinesCopyConstructor &);
-};
-// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesCopyConstructor' defines a copy constructor but does not define a destructor or a copy assignment operator [cppcoreguidelines-special-member-functions]
-
-class DefinesCopyAssignment {
- DefinesCopyAssignment &operator=(const DefinesCopyAssignment &);
-};
-// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesCopyAssignment' defines a copy assignment operator but does not define a destructor or a copy constructor [cppcoreguidelines-special-member-functions]
-
-class DefinesNothing {
-};
-
-class DefinesEverything {
- DefinesEverything(const DefinesEverything &);
- DefinesEverything &operator=(const DefinesEverything &);
- ~DefinesEverything();
-};
-
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-special-member-functions-relaxed.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-special-member-functions-relaxed.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-special-member-functions-relaxed.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-special-member-functions-relaxed.cpp (removed)
@@ -1,71 +0,0 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-special-member-functions %t -- -config="{CheckOptions: [{key: cppcoreguidelines-special-member-functions.AllowMissingMoveFunctions, value: 1}, {key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor, value: 1}]}" --
-
-class DefinesDestructor {
- ~DefinesDestructor();
-};
-// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesDestructor' defines a non-default destructor but does not define a copy constructor or a copy assignment operator [cppcoreguidelines-special-member-functions]
-
-class DefinesDefaultedDestructor {
- ~DefinesDefaultedDestructor() = default;
-};
-
-class DefinesCopyConstructor {
- DefinesCopyConstructor(const DefinesCopyConstructor &);
-};
-// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesCopyConstructor' defines a copy constructor but does not define a destructor or a copy assignment operator [cppcoreguidelines-special-member-functions]
-
-class DefinesCopyAssignment {
- DefinesCopyAssignment &operator=(const DefinesCopyAssignment &);
-};
-// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesCopyAssignment' defines a copy assignment operator but does not define a destructor or a copy constructor [cppcoreguidelines-special-member-functions]
-
-class DefinesMoveConstructor {
- DefinesMoveConstructor(DefinesMoveConstructor &&);
-};
-// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesMoveConstructor' defines a move constructor but does not define a destructor, a copy constructor, a copy assignment operator or a move assignment operator [cppcoreguidelines-special-member-functions]
-
-class DefinesMoveAssignment {
- DefinesMoveAssignment &operator=(DefinesMoveAssignment &&);
-};
-// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesMoveAssignment' defines a move assignment operator but does not define a destructor, a copy constructor, a copy assignment operator or a move constructor [cppcoreguidelines-special-member-functions]
-class DefinesNothing {
-};
-
-class DefinesEverything {
- DefinesEverything(const DefinesEverything &);
- DefinesEverything &operator=(const DefinesEverything &);
- DefinesEverything(DefinesEverything &&);
- DefinesEverything &operator=(DefinesEverything &&);
- ~DefinesEverything();
-};
-
-class DeletesEverything {
- DeletesEverything(const DeletesEverything &) = delete;
- DeletesEverything &operator=(const DeletesEverything &) = delete;
- DeletesEverything(DeletesEverything &&) = delete;
- DeletesEverything &operator=(DeletesEverything &&) = delete;
- ~DeletesEverything() = delete;
-};
-
-class DeletesCopyDefaultsMove {
- DeletesCopyDefaultsMove(const DeletesCopyDefaultsMove &) = delete;
- DeletesCopyDefaultsMove &operator=(const DeletesCopyDefaultsMove &) = delete;
- DeletesCopyDefaultsMove(DeletesCopyDefaultsMove &&) = default;
- DeletesCopyDefaultsMove &operator=(DeletesCopyDefaultsMove &&) = default;
- ~DeletesCopyDefaultsMove() = default;
-};
-
-template <typename T>
-struct TemplateClass {
- TemplateClass() = default;
- TemplateClass(const TemplateClass &);
- TemplateClass &operator=(const TemplateClass &);
- TemplateClass(TemplateClass &&);
- TemplateClass &operator=(TemplateClass &&);
- ~TemplateClass();
-};
-
-// Multiple instantiations of a class template will trigger multiple matches for defined special members.
-// This should not cause problems.
-TemplateClass<int> InstantiationWithInt;
-TemplateClass<double> InstantiationWithDouble;
Removed: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-special-member-functions.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-special-member-functions.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-special-member-functions.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-special-member-functions.cpp (removed)
@@ -1,72 +0,0 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-special-member-functions %t
-
-class DefinesDestructor {
- ~DefinesDestructor();
-};
-// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesDestructor' defines a non-default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions]
-
-class DefinesDefaultedDestructor {
- ~DefinesDefaultedDestructor() = default;
-};
-// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesDefaultedDestructor' defines a default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions]
-
-class DefinesCopyConstructor {
- DefinesCopyConstructor(const DefinesCopyConstructor &);
-};
-// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesCopyConstructor' defines a copy constructor but does not define a destructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions]
-
-class DefinesCopyAssignment {
- DefinesCopyAssignment &operator=(const DefinesCopyAssignment &);
-};
-// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesCopyAssignment' defines a copy assignment operator but does not define a destructor, a copy constructor, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions]
-
-class DefinesMoveConstructor {
- DefinesMoveConstructor(DefinesMoveConstructor &&);
-};
-// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesMoveConstructor' defines a move constructor but does not define a destructor, a copy constructor, a copy assignment operator or a move assignment operator [cppcoreguidelines-special-member-functions]
-
-class DefinesMoveAssignment {
- DefinesMoveAssignment &operator=(DefinesMoveAssignment &&);
-};
-// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesMoveAssignment' defines a move assignment operator but does not define a destructor, a copy constructor, a copy assignment operator or a move constructor [cppcoreguidelines-special-member-functions]
-class DefinesNothing {
-};
-
-class DefinesEverything {
- DefinesEverything(const DefinesEverything &);
- DefinesEverything &operator=(const DefinesEverything &);
- DefinesEverything(DefinesEverything &&);
- DefinesEverything &operator=(DefinesEverything &&);
- ~DefinesEverything();
-};
-
-class DeletesEverything {
- DeletesEverything(const DeletesEverything &) = delete;
- DeletesEverything &operator=(const DeletesEverything &) = delete;
- DeletesEverything(DeletesEverything &&) = delete;
- DeletesEverything &operator=(DeletesEverything &&) = delete;
- ~DeletesEverything() = delete;
-};
-
-class DeletesCopyDefaultsMove {
- DeletesCopyDefaultsMove(const DeletesCopyDefaultsMove &) = delete;
- DeletesCopyDefaultsMove &operator=(const DeletesCopyDefaultsMove &) = delete;
- DeletesCopyDefaultsMove(DeletesCopyDefaultsMove &&) = default;
- DeletesCopyDefaultsMove &operator=(DeletesCopyDefaultsMove &&) = default;
- ~DeletesCopyDefaultsMove() = default;
-};
-
-template <typename T>
-struct TemplateClass {
- TemplateClass() = default;
- TemplateClass(const TemplateClass &);
- TemplateClass &operator=(const TemplateClass &);
- TemplateClass(TemplateClass &&);
- TemplateClass &operator=(TemplateClass &&);
- ~TemplateClass();
-};
-
-// Multiple instantiations of a class template will trigger multiple matches for defined special members.
-// This should not cause problems.
-TemplateClass<int> InstantiationWithInt;
-TemplateClass<double> InstantiationWithDouble;
Removed: clang-tools-extra/trunk/test/clang-tidy/custom-diagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/custom-diagnostics.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/custom-diagnostics.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/custom-diagnostics.cpp (removed)
@@ -1,27 +0,0 @@
-// RUN: clang-tidy -checks='-*,modernize-use-override,clang-diagnostic-shadow,clang-diagnostic-float-conversion' %s -- | count 0
-//
-// Enable warnings using -config:
-// RUN: clang-tidy -checks='-*,modernize-use-override,clang-diagnostic-shadow,clang-diagnostic-float-conversion' \
-// RUN: -config='{ExtraArgs: ["-Wshadow","-Wno-unused-variable"], ExtraArgsBefore: ["-Wno-shadow","-Wfloat-conversion","-Wunused-variable"]}' %s -- \
-// RUN: | FileCheck -implicit-check-not='{{warning:|error:}}' %s
-//
-// ... -extra-arg:
-// RUN: clang-tidy -checks='-*,modernize-use-override,clang-diagnostic-shadow,clang-diagnostic-float-conversion' \
-// RUN: -extra-arg=-Wshadow -extra-arg=-Wno-unused-variable \
-// RUN: -extra-arg-before=-Wno-shadow -extra-arg-before=-Wfloat-conversion \
-// RUN: -extra-arg-before=-Wunused-variable %s -- \
-// RUN: | FileCheck -implicit-check-not='{{warning:|error:}}' %s
-//
-// ... a combination of -config and -extra-arg(-before):
-// RUN: clang-tidy -checks='-*,modernize-use-override,clang-diagnostic-shadow,clang-diagnostic-float-conversion' \
-// RUN: -config='{ExtraArgs: ["-Wno-unused-variable"], ExtraArgsBefore: ["-Wno-shadow","-Wfloat-conversion"]}' \
-// RUN: -extra-arg=-Wshadow -extra-arg-before=-Wunused-variable %s -- \
-// RUN: | FileCheck -implicit-check-not='{{warning:|error:}}' %s
-
-void f(float x) {
- int a;
- { int a; }
- // CHECK: :[[@LINE-1]]:9: warning: declaration shadows a local variable [clang-diagnostic-shadow]
- int b = x;
- // CHECK: :[[@LINE-1]]:11: warning: implicit conversion turns floating-point number into integer: 'float' to 'int' [clang-diagnostic-float-conversion]
-}
Removed: clang-tools-extra/trunk/test/clang-tidy/darwin-avoid-spinlock.m
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/darwin-avoid-spinlock.m?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/darwin-avoid-spinlock.m (original)
+++ clang-tools-extra/trunk/test/clang-tidy/darwin-avoid-spinlock.m (removed)
@@ -1,15 +0,0 @@
-// RUN: %check_clang_tidy %s darwin-avoid-spinlock %t
-
-typedef int OSSpinLock;
-
- at implementation Foo
-- (void)f {
- int i = 1;
- OSSpinlockLock(&i);
- // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use os_unfair_lock_lock() or dispatch queue APIs instead of the deprecated OSSpinLock [darwin-avoid-spinlock]
- OSSpinlockTry(&i);
- // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use os_unfair_lock_lock() or dispatch queue APIs instead of the deprecated OSSpinLock [darwin-avoid-spinlock]
- OSSpinlockUnlock(&i);
- // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use os_unfair_lock_lock() or dispatch queue APIs instead of the deprecated OSSpinLock [darwin-avoid-spinlock]
-}
- at end
Removed: clang-tools-extra/trunk/test/clang-tidy/darwin-dispatch-once-nonstatic.mm
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/darwin-dispatch-once-nonstatic.mm?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/darwin-dispatch-once-nonstatic.mm (original)
+++ clang-tools-extra/trunk/test/clang-tidy/darwin-dispatch-once-nonstatic.mm (removed)
@@ -1,48 +0,0 @@
-// RUN: %check_clang_tidy %s darwin-dispatch-once-nonstatic %t
-
-typedef int dispatch_once_t;
-extern void dispatch_once(dispatch_once_t *pred, void(^block)(void));
-
-
-void bad_dispatch_once(dispatch_once_t once, void(^block)(void)) {}
-// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: dispatch_once_t variables must have static or global storage duration; function parameters should be pointer references [darwin-dispatch-once-nonstatic]
-
-// file-scope dispatch_once_ts have static storage duration.
-dispatch_once_t global_once;
-static dispatch_once_t file_static_once;
-namespace {
-dispatch_once_t anonymous_once;
-} // end anonymous namespace
-
-int Correct(void) {
- static int value;
- static dispatch_once_t once;
- dispatch_once(&once, ^{
- value = 1;
- });
- return value;
-}
-
-int Incorrect(void) {
- static int value;
- dispatch_once_t once;
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: dispatch_once_t variables must have static or global storage duration [darwin-dispatch-once-nonstatic]
- // CHECK-FIXES: static dispatch_once_t once;
- dispatch_once(&once, ^{
- value = 1;
- });
- return value;
-}
-
-struct OnceStruct {
- static dispatch_once_t staticOnce; // Allowed
- int value;
- dispatch_once_t once; // Allowed (at this time)
-};
-
- at interface MyObject {
- dispatch_once_t _once;
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: dispatch_once_t variables must have static or global storage duration and cannot be Objective-C instance variables [darwin-dispatch-once-nonstatic]
- // CHECK-FIXES: dispatch_once_t _once;
-}
- at end
Removed: clang-tools-extra/trunk/test/clang-tidy/deduplication.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/deduplication.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/deduplication.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/deduplication.cpp (removed)
@@ -1,10 +0,0 @@
-// RUN: %check_clang_tidy %s google-explicit-constructor %t
-
-template<typename T>
-struct A { A(T); };
-// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: single-argument constructors must be marked explicit
-
-void f() {
- A<int> a(0);
- A<double> b(0);
-}
Removed: clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp (removed)
@@ -1,52 +0,0 @@
-// RUN: not clang-tidy -checks='-*,modernize-use-override' %s.nonexistent.cpp -- | FileCheck -check-prefix=CHECK1 -implicit-check-not='{{warning:|error:}}' %s
-// RUN: not clang-tidy -checks='-*,clang-diagnostic-*,google-explicit-constructor' %s -- -fan-unknown-option | FileCheck -check-prefix=CHECK2 -implicit-check-not='{{warning:|error:}}' %s
-// RUN: not clang-tidy -checks='-*,google-explicit-constructor,clang-diagnostic-literal-conversion' %s -- -fan-unknown-option | FileCheck -check-prefix=CHECK3 -implicit-check-not='{{warning:|error:}}' %s
-// RUN: clang-tidy -checks='-*,modernize-use-override,clang-diagnostic-macro-redefined' %s -- -DMACRO_FROM_COMMAND_LINE | FileCheck -check-prefix=CHECK4 -implicit-check-not='{{warning:|error:}}' %s
-// RUN: not clang-tidy -checks='-*,modernize-use-override' %s -- -DCOMPILATION_ERROR | FileCheck -check-prefix=CHECK6 -implicit-check-not='{{warning:|error:}}' %s
-//
-// Now repeat the tests and ensure no other errors appear on stderr:
-// RUN: not clang-tidy -checks='-*,modernize-use-override' %s.nonexistent.cpp -- 2>&1 | FileCheck -check-prefix=CHECK1 -implicit-check-not='{{warning:|error:}}' %s
-// RUN: not clang-tidy -checks='-*,clang-diagnostic-*,google-explicit-constructor' %s -- -fan-unknown-option 2>&1 | FileCheck -check-prefix=CHECK2 -implicit-check-not='{{warning:|error:}}' %s
-// RUN: not clang-tidy -checks='-*,google-explicit-constructor,clang-diagnostic-literal-conversion' %s -- -fan-unknown-option 2>&1 | FileCheck -check-prefix=CHECK3 -implicit-check-not='{{warning:|error:}}' %s
-// RUN: clang-tidy -checks='-*,modernize-use-override,clang-diagnostic-macro-redefined' %s -- -DMACRO_FROM_COMMAND_LINE 2>&1 | FileCheck -check-prefix=CHECK4 -implicit-check-not='{{warning:|error:}}' %s
-// RUN: not clang-tidy -checks='-*,modernize-use-override' %s -- -DCOMPILATION_ERROR 2>&1 | FileCheck -check-prefix=CHECK6 -implicit-check-not='{{warning:|error:}}' %s
-//
-// Now create a directory with a compilation database file and ensure we don't
-// use it after failing to parse commands from the command line:
-//
-// RUN: mkdir -p %T/diagnostics/
-// RUN: echo '[{"directory": "%/T/diagnostics/","command": "clang++ -fan-option-from-compilation-database -c %/T/diagnostics/input.cpp", "file": "%/T/diagnostics/input.cpp"}]' > %T/diagnostics/compile_commands.json
-// RUN: cat %s > %T/diagnostics/input.cpp
-// RUN: not clang-tidy -checks='-*,modernize-use-override' %T/diagnostics/nonexistent.cpp -- 2>&1 | FileCheck -check-prefix=CHECK1 -implicit-check-not='{{warning:|error:}}' %s
-// RUN: not clang-tidy -checks='-*,clang-diagnostic-*,google-explicit-constructor' %T/diagnostics/input.cpp -- -fan-unknown-option 2>&1 | FileCheck -check-prefix=CHECK2 -implicit-check-not='{{warning:|error:}}' %s
-// RUN: not clang-tidy -checks='-*,google-explicit-constructor,clang-diagnostic-literal-conversion' %T/diagnostics/input.cpp -- -fan-unknown-option 2>&1 | FileCheck -check-prefix=CHECK3 -implicit-check-not='{{warning:|error:}}' %s
-// RUN: clang-tidy -checks='-*,modernize-use-override,clang-diagnostic-macro-redefined' %T/diagnostics/input.cpp -- -DMACRO_FROM_COMMAND_LINE 2>&1 | FileCheck -check-prefix=CHECK4 -implicit-check-not='{{warning:|error:}}' %s
-// RUN: not clang-tidy -checks='-*,clang-diagnostic-*,google-explicit-constructor' %T/diagnostics/input.cpp 2>&1 | FileCheck -check-prefix=CHECK5 -implicit-check-not='{{warning:|error:}}' %s
-// RUN: not clang-tidy -checks='-*,modernize-use-override' %T/diagnostics/input.cpp -- -DCOMPILATION_ERROR 2>&1 | FileCheck -check-prefix=CHECK6 -implicit-check-not='{{warning:|error:}}' %s
-
-// CHECK1: error: no input files [clang-diagnostic-error]
-// CHECK1: error: no such file or directory: '{{.*}}nonexistent.cpp' [clang-diagnostic-error]
-// CHECK1: error: unable to handle compilation{{.*}} [clang-diagnostic-error]
-// CHECK2: error: unknown argument: '-fan-unknown-option' [clang-diagnostic-error]
-// CHECK3: error: unknown argument: '-fan-unknown-option' [clang-diagnostic-error]
-// CHECK5: error: unknown argument: '-fan-option-from-compilation-database' [clang-diagnostic-error]
-
-// CHECK2: :[[@LINE+3]]:9: warning: implicit conversion from 'double' to 'int' changes value from 1.5 to 1 [clang-diagnostic-literal-conversion]
-// CHECK3: :[[@LINE+2]]:9: warning: implicit conversion from 'double' to 'int' changes value
-// CHECK5: :[[@LINE+1]]:9: warning: implicit conversion from 'double' to 'int' changes value
-int a = 1.5;
-
-// CHECK2: :[[@LINE+3]]:11: warning: single-argument constructors must be marked explicit
-// CHECK3: :[[@LINE+2]]:11: warning: single-argument constructors must be marked explicit
-// CHECK5: :[[@LINE+1]]:11: warning: single-argument constructors must be marked explicit
-class A { A(int) {} };
-
-#define MACRO_FROM_COMMAND_LINE
-// CHECK4: :[[@LINE-1]]:9: warning: 'MACRO_FROM_COMMAND_LINE' macro redefined
-
-#ifdef COMPILATION_ERROR
-void f(int a) {
- &(a + 1);
- // CHECK6: :[[@LINE-1]]:3: error: cannot take the address of an rvalue of type 'int' [clang-diagnostic-error]
-}
-#endif
Removed: clang-tools-extra/trunk/test/clang-tidy/duplicate-reports.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/duplicate-reports.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/duplicate-reports.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/duplicate-reports.cpp (removed)
@@ -1,15 +0,0 @@
-// RUN: %check_clang_tidy %s cert-err09-cpp,cert-err61-cpp %t -- -- -fexceptions
-
-void alwaysThrows() {
- int ex = 42;
- // CHECK-MESSAGES: warning: throw expression should throw anonymous temporary values instead [cert-err09-cpp]
- // CHECK-MESSAGES: warning: throw expression should throw anonymous temporary values instead [cert-err61-cpp]
- throw ex;
-}
-
-void doTheJob() {
- try {
- alwaysThrows();
- } catch (int&) {
- }
-}
Removed: clang-tools-extra/trunk/test/clang-tidy/empty-database.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/empty-database.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/empty-database.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/empty-database.cpp (removed)
@@ -1,5 +0,0 @@
-// UNSUPPORTED: system-windows
-
-// RUN: not clang-tidy -p %S/Inputs/empty-database %s 2>&1 | FileCheck %s
-
-// CHECK: LLVM ERROR: Cannot chdir into ""!
Removed: clang-tools-extra/trunk/test/clang-tidy/enable-alpha-checks.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/enable-alpha-checks.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/enable-alpha-checks.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/enable-alpha-checks.cpp (removed)
@@ -1,8 +0,0 @@
-// REQUIRES: static-analyzer
-
-// Check if '-allow-enabling-analyzer-alpha-checkers' is visible for users.
-// RUN: clang-tidy -help | not grep 'allow-enabling-analyzer-alpha-checkers'
-
-// Check if '-allow-enabling-analyzer-alpha-checkers' enables alpha checks.
-// RUN: clang-tidy -checks=* -list-checks | not grep 'clang-analyzer-alpha'
-// RUN: clang-tidy -checks=* -list-checks -allow-enabling-analyzer-alpha-checkers | grep 'clang-analyzer-alpha'
Removed: clang-tools-extra/trunk/test/clang-tidy/expand-modular-headers-ppcallbacks.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/expand-modular-headers-ppcallbacks.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/expand-modular-headers-ppcallbacks.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/expand-modular-headers-ppcallbacks.cpp (removed)
@@ -1,57 +0,0 @@
-// Sanity-check. Run without modules:
-// RUN: rm -rf %t
-// RUN: mkdir %t
-// RUN: cp %S/Inputs/expand-modular-headers-ppcallbacks/* %t/
-// RUN: %check_clang_tidy -std=c++11 %s readability-identifier-naming %t/without-modules -- \
-// RUN: -config="CheckOptions: [{ \
-// RUN: key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE }]" \
-// RUN: -header-filter=.* \
-// RUN: -- -I %t/
-//
-// RUN: rm -rf %t
-// RUN: mkdir %t
-// RUN: cp %S/Inputs/expand-modular-headers-ppcallbacks/* %t/
-// RUN: %check_clang_tidy -std=c++17 %s readability-identifier-naming %t/without-modules -- \
-// RUN: -config="CheckOptions: [{ \
-// RUN: key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE }]" \
-// RUN: -header-filter=.* \
-// RUN: -- -I %t/
-//
-// Run clang-tidy on a file with modular includes:
-//
-// RUN: rm -rf %t
-// RUN: mkdir %t
-// RUN: cp %S/Inputs/expand-modular-headers-ppcallbacks/* %t/
-// RUN: %check_clang_tidy -std=c++11 %s readability-identifier-naming %t/with-modules -- \
-// RUN: -config="CheckOptions: [{ \
-// RUN: key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE }]" \
-// RUN: -header-filter=.* \
-// RUN: -- -I %t/ \
-// RUN: -fmodules -fimplicit-modules -fno-implicit-module-maps \
-// RUN: -fmodule-map-file=%t/module.modulemap \
-// RUN: -fmodules-cache-path=%t/module-cache/
-//
-// RUN: rm -rf %t
-// RUN: mkdir %t
-// RUN: cp %S/Inputs/expand-modular-headers-ppcallbacks/* %t/
-// RUN: %check_clang_tidy -std=c++17 %s readability-identifier-naming %t/with-modules -- \
-// RUN: -config="CheckOptions: [{ \
-// RUN: key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE }]" \
-// RUN: -header-filter=.* \
-// RUN: -- -I %t/ \
-// RUN: -fmodules -fimplicit-modules -fno-implicit-module-maps \
-// RUN: -fmodule-map-file=%t/module.modulemap \
-// RUN: -fmodules-cache-path=%t/module-cache/
-// FIXME: Make the test work in all language modes.
-#include "c.h"
-
-// CHECK-MESSAGES: a.h:1:9: warning: invalid case style for macro definition 'a' [readability-identifier-naming]
-// CHECK-MESSAGES: a.h:1:9: note: FIX-IT applied suggested code changes
-// CHECK-MESSAGES: b.h:2:9: warning: invalid case style for macro definition 'b'
-// CHECK-MESSAGES: b.h:2:9: note: FIX-IT applied suggested code changes
-// CHECK-MESSAGES: c.h:2:9: warning: invalid case style for macro definition 'c'
-// CHECK-MESSAGES: c.h:2:9: note: FIX-IT applied suggested code changes
-
-#define m
-// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for macro definition 'm'
-// CHECK-MESSAGES: :[[@LINE-2]]:9: note: FIX-IT applied suggested code changes
Removed: clang-tools-extra/trunk/test/clang-tidy/explain-checks.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/explain-checks.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/explain-checks.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/explain-checks.cpp (removed)
@@ -1,12 +0,0 @@
-// RUN: clang-tidy -checks=-*,modernize-use-nullptr -explain-config | FileCheck --check-prefix=CHECK-MESSAGE1 %s
-// RUN: clang-tidy -config="{Checks: '-*,modernize-use-nullptr'}" -explain-config | FileCheck --check-prefix=CHECK-MESSAGE2 %s
-// RUN: clang-tidy -checks=modernize-use-nullptr -config="{Checks: '-*,modernize-use-nullptr'}" -explain-config | FileCheck --check-prefix=CHECK-MESSAGE3 %s
-// RUN: clang-tidy -checks=modernize-use-nullptr -config="{Checks: '-*,-modernize-use-nullptr'}" %S/Inputs/explain-config/a.cc -explain-config -- | FileCheck --check-prefix=CHECK-MESSAGE4 %s
-// RUN: clang-tidy -checks=modernize-use-nullptr -config="{Checks: '-*,modernize-*'}" -explain-config | FileCheck --check-prefix=CHECK-MESSAGE5 %s
-// RUN: clang-tidy -explain-config %S/Inputs/explain-config/a.cc -- | grep "'modernize-use-nullptr' is enabled in the .*[/\\]Inputs[/\\]explain-config[/\\].clang-tidy."
-
-// CHECK-MESSAGE1: 'modernize-use-nullptr' is enabled in the command-line option '-checks'.
-// CHECK-MESSAGE2: 'modernize-use-nullptr' is enabled in the command-line option '-config'.
-// CHECK-MESSAGE3: 'modernize-use-nullptr' is enabled in the command-line option '-checks'.
-// CHECK-MESSAGE4: 'modernize-use-nullptr' is enabled in the command-line option '-checks'.
-// CHECK-MESSAGE5: 'modernize-use-nullptr' is enabled in the command-line option '-checks'.
Removed: clang-tools-extra/trunk/test/clang-tidy/export-diagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/export-diagnostics.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/export-diagnostics.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/export-diagnostics.cpp (removed)
@@ -1,45 +0,0 @@
-// RUN: grep -Ev "// *[A-Z-]+:" %s > %t-input.cpp
-// RUN: clang-tidy %t-input.cpp -checks='-*,google-explicit-constructor,clang-diagnostic-missing-prototypes' -export-fixes=%t.yaml -- -Wmissing-prototypes > %t.msg 2>&1
-// RUN: FileCheck -input-file=%t.msg -check-prefix=CHECK-MESSAGES %s -implicit-check-not='{{warning|error|note}}:'
-// RUN: FileCheck -input-file=%t.yaml -check-prefix=CHECK-YAML %s
-#define X(n) void n ## n() {}
-X(f)
-
-// CHECK-MESSAGES: -input.cpp:2:1: warning: no previous prototype for function 'ff' [clang-diagnostic-missing-prototypes]
-// CHECK-MESSAGES: -input.cpp:1:19: note: expanded from macro 'X'
-// CHECK-MESSAGES: {{^}}note: expanded from here{{$}}
-// CHECK-MESSAGES: -input.cpp:2:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
-// CHECK-MESSAGES: -input.cpp:1:14: note: expanded from macro 'X'
-
-// CHECK-YAML: ---
-// CHECK-YAML-NEXT: MainSourceFile: '{{.*}}-input.cpp'
-// CHECK-YAML-NEXT: Diagnostics:
-// CHECK-YAML-NEXT: - DiagnosticName: clang-diagnostic-missing-prototypes
-// CHECK-YAML-NEXT: DiagnosticMessage:
-// CHECK-YAML-NEXT: Message: 'no previous prototype for function
-// ''ff'''
-// CHECK-YAML-NEXT: FilePath: '{{.*}}-input.cpp'
-// CHECK-YAML-NEXT: FileOffset: 30
-// CHECK-YAML-NEXT: Replacements: []
-// CHECK-YAML-NEXT: Notes:
-// CHECK-YAML-NEXT: - Message: 'expanded from macro ''X'''
-// CHECK-YAML-NEXT: FilePath: '{{.*}}-input.cpp'
-// CHECK-YAML-NEXT: FileOffset: 18
-// CHECK-YAML-NEXT: Replacements: []
-// CHECK-YAML-NEXT: - Message: expanded from here
-// CHECK-YAML-NEXT: FilePath: ''
-// CHECK-YAML-NEXT: FileOffset: 0
-// CHECK-YAML-NEXT: Replacements: []
-// CHECK-YAML-NEXT: - Message: 'declare ''static'' if the function is not intended to be used outside of this translation unit'
-// CHECK-YAML-NEXT: FilePath: '{{.*}}-input.cpp'
-// CHECK-YAML-NEXT: FileOffset: 30
-// CHECK-YAML-NEXT: Replacements:
-// CHECK-YAML-NEXT: - FilePath: '{{.*}}-input.cpp'
-// CHECK-YAML-NEXT: Offset: 30
-// CHECK-YAML-NEXT: Length: 0
-// CHECK-YAML-NEXT: ReplacementText: 'static '
-// CHECK-YAML-NEXT: - Message: 'expanded from macro ''X'''
-// CHECK-YAML-NEXT: FilePath: '{{.*}}-input.cpp'
-// CHECK-YAML-NEXT: FileOffset: 13
-// CHECK-YAML-NEXT: Replacements: []
-// CHECK-YAML-NEXT: ...
Removed: clang-tools-extra/trunk/test/clang-tidy/export-relpath.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/export-relpath.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/export-relpath.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/export-relpath.cpp (removed)
@@ -1,19 +0,0 @@
-// RUN: rm -rf %T/clang-tidy/export-relpath
-// RUN: mkdir -p %T/clang-tidy/export-relpath/subdir
-// RUN: cp %s %T/clang-tidy/export-relpath/subdir/source.cpp
-// RUN: echo '[{ "directory": "%/T/clang-tidy/export-relpath/subdir", "command": "clang++ source.cpp", "file": "%/T/clang-tidy/export-relpath/subdir/source.cpp"}]' > %T/clang-tidy/export-relpath/subdir/compile_commands.json
-//
-// Check that running clang-tidy in './subdir' and storing results
-// in './fixes.yaml' works as expected.
-//
-// RUN: cd %T/clang-tidy/export-relpath
-// RUN: clang-tidy -p subdir subdir/source.cpp -checks='-*,google-explicit-constructor,llvm-namespace-comment' -export-fixes=./fixes.yaml
-// RUN: FileCheck -input-file=%T/clang-tidy/export-relpath/fixes.yaml -check-prefix=CHECK-YAML %s
-
-namespace i {
-void f(); // So that the namespace isn't empty.
-}
-// CHECK-YAML: ReplacementText: ' // namespace i'
-
-class A { A(int i); };
-// CHECK-YAML: ReplacementText: 'explicit '
Removed: clang-tools-extra/trunk/test/clang-tidy/extra-args.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/extra-args.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/extra-args.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/extra-args.cpp (removed)
@@ -1,7 +0,0 @@
-// RUN: clang-tidy -checks='-*,modernize-use-override' \
-// RUN: -config='{ExtraArgs: ["-DTEST4"], ExtraArgsBefore: ["-DTEST1"]}' \
-// RUN: -extra-arg=-DTEST3 -extra-arg-before=-DTEST2 %s -- -v 2>&1 \
-// RUN: | FileCheck -implicit-check-not='{{warning:|error:}}' %s
-
-// CHECK: {{^}}clang Invocation:{{$}}
-// CHECK-NEXT: {{"-D" "TEST1" .*"-D" "TEST2" .*"-D" "TEST3" .*"-D" "TEST4"}}
Removed: clang-tools-extra/trunk/test/clang-tidy/file-filter-symlinks.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/file-filter-symlinks.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/file-filter-symlinks.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/file-filter-symlinks.cpp (removed)
@@ -1,19 +0,0 @@
-// REQUIRES: shell
-
-// RUN: rm -rf %t
-// RUN: mkdir -p %t/dir1/dir2
-// RUN: echo 'class A { A(int); };' > %t/dir1/header.h
-// RUN: ln -s %t/dir1/header.h %t/dir1/header_alias.h
-//
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='dir1/dir2/\.\./header_alias\.h' %s -- -I %t 2>&1 | FileCheck --check-prefix=CHECK_HEADER_ALIAS %s
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='dir1/dir2/\.\./header_alias\.h' -quiet %s -- -I %t 2>&1 | FileCheck --check-prefix=CHECK_HEADER_ALIAS %s
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='header_alias\.h' %s -- -I %t 2>&1 | FileCheck --check-prefix=CHECK_HEADER_ALIAS %s
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='header_alias\.h' -quiet %s -- -I %t 2>&1 | FileCheck --check-prefix=CHECK_HEADER_ALIAS %s
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='header\.h' %s -- -I %t 2>&1 | FileCheck --check-prefix=CHECK_HEADER %s
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='header\.h' -quiet %s -- -I %t 2>&1 | FileCheck --check-prefix=CHECK_HEADER %s
-
-// Check that `-header-filter` operates on the same file paths as paths in
-// diagnostics printed by ClangTidy.
-#include "dir1/dir2/../header_alias.h"
-// CHECK_HEADER_ALIAS: dir1/dir2/../header_alias.h:1:11: warning: single-argument constructors
-// CHECK_HEADER-NOT: warning:
Removed: clang-tools-extra/trunk/test/clang-tidy/file-filter.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/file-filter.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/file-filter.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/file-filter.cpp (removed)
@@ -1,73 +0,0 @@
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='' %s -- -I %S/Inputs/file-filter -isystem %S/Inputs/file-filter/system 2>&1 | FileCheck %s
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='' -quiet %s -- -I %S/Inputs/file-filter -isystem %S/Inputs/file-filter/system 2>&1 | FileCheck --check-prefix=CHECK-QUIET %s
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='.*' %s -- -I %S/Inputs/file-filter -isystem %S/Inputs/file-filter/system 2>&1 | FileCheck --check-prefix=CHECK2 %s
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='.*' -quiet %s -- -I %S/Inputs/file-filter -isystem %S/Inputs/file-filter/system 2>&1 | FileCheck --check-prefix=CHECK2-QUIET %s
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='header2\.h' %s -- -I %S/Inputs/file-filter -isystem %S/Inputs/file-filter/system 2>&1 | FileCheck --check-prefix=CHECK3 %s
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='header2\.h' -quiet %s -- -I %S/Inputs/file-filter -isystem %S/Inputs/file-filter/system 2>&1 | FileCheck --check-prefix=CHECK3-QUIET %s
-// FIXME: "-I %S/Inputs/file-filter/system/.." must be redundant.
-// On Win32, file-filter/system\system-header1.h precedes
-// file-filter\header*.h due to code order between '/' and '\\'.
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='.*' -system-headers %s -- -I %S/Inputs/file-filter/system/.. -isystem %S/Inputs/file-filter/system 2>&1 | FileCheck --check-prefix=CHECK4 %s
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='.*' -system-headers -quiet %s -- -I %S/Inputs/file-filter/system/.. -isystem %S/Inputs/file-filter/system 2>&1 | FileCheck --check-prefix=CHECK4-QUIET %s
-
-#include "header1.h"
-// CHECK-NOT: warning:
-// CHECK-QUIET-NOT: warning:
-// CHECK2: header1.h:1:12: warning: single-argument constructors must be marked explicit
-// CHECK2-QUIET: header1.h:1:12: warning: single-argument constructors must be marked explicit
-// CHECK3-NOT: warning:
-// CHECK3-QUIET-NOT: warning:
-// CHECK4: header1.h:1:12: warning: single-argument constructors
-// CHECK4-QUIET: header1.h:1:12: warning: single-argument constructors
-
-#include "header2.h"
-// CHECK-NOT: warning:
-// CHECK-QUIET-NOT: warning:
-// CHECK2: header2.h:1:12: warning: single-argument constructors
-// CHECK2-QUIET: header2.h:1:12: warning: single-argument constructors
-// CHECK3: header2.h:1:12: warning: single-argument constructors
-// CHECK3-QUIET: header2.h:1:12: warning: single-argument constructors
-// CHECK4: header2.h:1:12: warning: single-argument constructors
-// CHECK4-QUIET: header2.h:1:12: warning: single-argument constructors
-
-#include <system-header.h>
-// CHECK-NOT: warning:
-// CHECK-QUIET-NOT: warning:
-// CHECK2-NOT: warning:
-// CHECK2-QUIET-NOT: warning:
-// CHECK3-NOT: warning:
-// CHECK3-QUIET-NOT: warning:
-// CHECK4: system-header.h:1:12: warning: single-argument constructors
-// CHECK4-QUIET: system-header.h:1:12: warning: single-argument constructors
-
-class A { A(int); };
-// CHECK: :[[@LINE-1]]:11: warning: single-argument constructors
-// CHECK-QUIET: :[[@LINE-2]]:11: warning: single-argument constructors
-// CHECK2: :[[@LINE-3]]:11: warning: single-argument constructors
-// CHECK2-QUIET: :[[@LINE-4]]:11: warning: single-argument constructors
-// CHECK3: :[[@LINE-5]]:11: warning: single-argument constructors
-// CHECK3-QUIET: :[[@LINE-6]]:11: warning: single-argument constructors
-// CHECK4: :[[@LINE-7]]:11: warning: single-argument constructors
-// CHECK4-QUIET: :[[@LINE-8]]:11: warning: single-argument constructors
-
-// CHECK-NOT: warning:
-// CHECK-QUIET-NOT: warning:
-// CHECK2-NOT: warning:
-// CHECK2-QUIET-NOT: warning:
-// CHECK3-NOT: warning:
-// CHECK3-QUIET-NOT: warning:
-// CHECK4-NOT: warning:
-// CHECK4-QUIET-NOT: warning:
-
-// CHECK: Suppressed 3 warnings (3 in non-user code)
-// CHECK: Use -header-filter=.* to display errors from all non-system headers.
-// CHECK-QUIET-NOT: Suppressed
-// CHECK2: Suppressed 1 warnings (1 in non-user code)
-// CHECK2: Use -header-filter=.* {{.*}}
-// CHECK2-QUIET-NOT: Suppressed
-// CHECK3: Suppressed 2 warnings (2 in non-user code)
-// CHECK3: Use -header-filter=.* {{.*}}
-// CHECK3-QUIET-NOT: Suppressed
-// CHECK4-NOT: Suppressed {{.*}} warnings
-// CHECK4-NOT: Use -header-filter=.* {{.*}}
-// CHECK4-QUIET-NOT: Suppressed
Removed: clang-tools-extra/trunk/test/clang-tidy/fix-errors.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/fix-errors.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/fix-errors.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/fix-errors.cpp (removed)
@@ -1,15 +0,0 @@
-// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
-// RUN: not clang-tidy %t.cpp -checks='-*,google-explicit-constructor' -fix -- > %t.msg 2>&1
-// RUN: FileCheck -input-file=%t.cpp -check-prefix=CHECK-FIX %s
-// RUN: FileCheck -input-file=%t.msg -check-prefix=CHECK-MESSAGES %s
-// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
-// RUN: clang-tidy %t.cpp -checks='-*,google-explicit-constructor' -fix-errors -- > %t.msg 2>&1
-// RUN: FileCheck -input-file=%t.cpp -check-prefix=CHECK-FIX2 %s
-// RUN: FileCheck -input-file=%t.msg -check-prefix=CHECK-MESSAGES2 %s
-
-class A { A(int i); }
-// CHECK-FIX: class A { A(int i); }{{$}}
-// CHECK-MESSAGES: Fixes have NOT been applied.
-// CHECK-FIX2: class A { explicit A(int i); };
-// CHECK-MESSAGES2: note: FIX-IT applied suggested code changes
-// CHECK-MESSAGES2: clang-tidy applied 2 of 2 suggested fixes.
Removed: clang-tools-extra/trunk/test/clang-tidy/fix.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/fix.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/fix.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/fix.cpp (removed)
@@ -1,18 +0,0 @@
-// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
-// RUN: clang-tidy %t.cpp -checks='-*,google-explicit-constructor,llvm-namespace-comment' -fix -export-fixes=%t.yaml -- > %t.msg 2>&1
-// RUN: FileCheck -input-file=%t.cpp %s
-// RUN: FileCheck -input-file=%t.msg -check-prefix=CHECK-MESSAGES %s
-// RUN: FileCheck -input-file=%t.yaml -check-prefix=CHECK-YAML %s
-
-namespace i {
-void f(); // So that the namespace isn't empty.
-}
-// CHECK: } // namespace i
-// CHECK-MESSAGES: note: FIX-IT applied suggested code changes
-// CHECK-YAML: ReplacementText: ' // namespace i'
-
-class A { A(int i); };
-// CHECK: class A { explicit A(int i); };
-// CHECK-MESSAGES: note: FIX-IT applied suggested code changes
-// CHECK-MESSAGES: clang-tidy applied 2 of 2 suggested fixes.
-// CHECK-YAML: ReplacementText: 'explicit '
Removed: clang-tools-extra/trunk/test/clang-tidy/fuchsia-default-arguments-calls.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/fuchsia-default-arguments-calls.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/fuchsia-default-arguments-calls.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/fuchsia-default-arguments-calls.cpp (removed)
@@ -1,36 +0,0 @@
-// RUN: %check_clang_tidy %s fuchsia-default-arguments-calls %t
-
-int foo(int value = 5) { return value; }
-
-int f() {
- foo();
- // CHECK-NOTES: [[@LINE-1]]:3: warning: calling a function that uses a default argument is disallowed [fuchsia-default-arguments-calls]
- // CHECK-NOTES: [[@LINE-5]]:9: note: default parameter was declared here
-}
-
-int bar(int value) { return value; }
-
-int n() {
- foo(0);
- bar(0);
-}
-
-void x(int i = 12);
-
-struct S {
- void x(int i);
-};
-
-void S::x(int i = 12) {}
-
-int main() {
- S s;
- s.x();
- // CHECK-NOTES: [[@LINE-1]]:3: warning: calling a function that uses a default argument is disallowed [fuchsia-default-arguments-calls]
- // CHECK-NOTES: [[@LINE-6]]:11: note: default parameter was declared here
- // CHECK-NEXT: void S::x(int i = 12) {}
- x();
- // CHECK-NOTES: [[@LINE-1]]:3: warning: calling a function that uses a default argument is disallowed [fuchsia-default-arguments-calls]
- // CHECK-NOTES: [[@LINE-16]]:8: note: default parameter was declared here
- // CHECK-NEXT: void x(int i = 12);
-}
Removed: clang-tools-extra/trunk/test/clang-tidy/fuchsia-default-arguments-declarations.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/fuchsia-default-arguments-declarations.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/fuchsia-default-arguments-declarations.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/fuchsia-default-arguments-declarations.cpp (removed)
@@ -1,57 +0,0 @@
-// RUN: %check_clang_tidy %s fuchsia-default-arguments-declarations %t
-
-int foo(int value = 5) { return value; }
-// CHECK-NOTES: [[@LINE-1]]:9: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments-declarations]
-// CHECK-FIXES: int foo(int value) { return value; }
-
-int bar(int value) { return value; }
-
-class Baz {
-public:
- int a(int value = 5) { return value; }
- // CHECK-NOTES: [[@LINE-1]]:9: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments-declarations]
- // CHECK-FIXES: int a(int value) { return value; }
-
- int b(int value) { return value; }
-};
-
-class Foo {
- // Fix should be suggested in declaration
- int a(int value = 53);
- // CHECK-NOTES: [[@LINE-1]]:9: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments-declarations]
- // CHECK-FIXES: int a(int value);
-};
-
-// Fix shouldn't be suggested in implementation
-int Foo::a(int value) {
- return value;
-}
-
-// Elided functions
-void f(int = 5) {};
-// CHECK-NOTES: [[@LINE-1]]:8: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments-declarations]
-// CHECK-FIXES: void f(int) {};
-
-void g(int) {};
-
-// Should not suggest fix for macro-defined parameters
-#define D(val) = val
-
-void h(int i D(5));
-// CHECK-NOTES: [[@LINE-1]]:8: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments-declarations]
-// CHECK-FIXES-NOT: void h(int i);
-
-void x(int i);
-void x(int i = 12);
-// CHECK-NOTES: [[@LINE-1]]:8: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments-declarations]
-// CHECK-FIXES: void x(int i);
-
-void x(int i) {}
-
-struct S {
- void x(int i);
-};
-
-void S::x(int i = 12) {}
-// CHECK-NOTES: [[@LINE-1]]:11: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments-declarations]
-// CHECK-FIXES: void S::x(int i) {}
Removed: clang-tools-extra/trunk/test/clang-tidy/fuchsia-multiple-inheritance.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/fuchsia-multiple-inheritance.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/fuchsia-multiple-inheritance.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/fuchsia-multiple-inheritance.cpp (removed)
@@ -1,150 +0,0 @@
-// RUN: %check_clang_tidy %s fuchsia-multiple-inheritance %t
-
-class Base_A {
-public:
- virtual int foo() { return 0; }
-};
-
-class Base_B {
-public:
- virtual int bar() { return 0; }
-};
-
-class Base_A_child : public Base_A {
-public:
- virtual int baz() { return 0; }
-};
-
-class Interface_A {
-public:
- virtual int foo() = 0;
-};
-
-class Interface_B {
-public:
- virtual int bar() = 0;
-};
-
-class Interface_C {
-public:
- virtual int blat() = 0;
-};
-
-class Interface_A_with_member {
-public:
- virtual int foo() = 0;
- int val = 0;
-};
-
-class Interface_with_A_Parent : public Base_A {
-public:
- virtual int baz() = 0;
-};
-
-// Shouldn't warn on forward declarations.
-class Bad_Child1;
-
-// Inherits from multiple concrete classes.
-// CHECK-MESSAGES: [[@LINE+2]]:1: warning: inheriting mulitple classes that aren't pure virtual is discouraged [fuchsia-multiple-inheritance]
-// CHECK-NEXT: class Bad_Child1 : public Base_A, Base_B {};
-class Bad_Child1 : public Base_A, Base_B {};
-
-// CHECK-MESSAGES: [[@LINE+1]]:1: warning: inheriting mulitple classes that aren't pure virtual is discouraged [fuchsia-multiple-inheritance]
-class Bad_Child2 : public Base_A, Interface_A_with_member {
- virtual int foo() override { return 0; }
-};
-
-// CHECK-MESSAGES: [[@LINE+2]]:1: warning: inheriting mulitple classes that aren't pure virtual is discouraged [fuchsia-multiple-inheritance]
-// CHECK-NEXT: class Bad_Child3 : public Interface_with_A_Parent, Base_B {
-class Bad_Child3 : public Interface_with_A_Parent, Base_B {
- virtual int baz() override { return 0; }
-};
-
-// Easy cases of single inheritance
-class Simple_Child1 : public Base_A {};
-class Simple_Child2 : public Interface_A {
- virtual int foo() override { return 0; }
-};
-
-// Valid uses of multiple inheritance
-class Good_Child1 : public Interface_A, Interface_B {
- virtual int foo() override { return 0; }
- virtual int bar() override { return 0; }
-};
-
-class Good_Child2 : public Base_A, Interface_B {
- virtual int bar() override { return 0; }
-};
-
-class Good_Child3 : public Base_A_child, Interface_C, Interface_B {
- virtual int bar() override { return 0; }
- virtual int blat() override { return 0; }
-};
-
-struct B1 { int x; };
-struct B2 { int x;};
-// CHECK-MESSAGES: [[@LINE+2]]:1: warning: inheriting mulitple classes that aren't pure virtual is discouraged [fuchsia-multiple-inheritance]
-// CHECK-NEXT: struct D : B1, B2 {};
-struct D1 : B1, B2 {};
-
-struct Base1 { virtual void foo() = 0; };
-struct V1 : virtual Base1 {};
-struct V2 : virtual Base1 {};
-struct D2 : V1, V2 {};
-
-struct Base2 { virtual void foo(); };
-struct V3 : virtual Base2 {};
-struct V4 : virtual Base2 {};
-struct D3 : V3, V4 {};
-
-struct Base3 {};
-struct V5 : virtual Base3 { virtual void f(); };
-struct V6 : virtual Base3 { virtual void g(); };
-// CHECK-MESSAGES: [[@LINE+2]]:1: warning: inheriting mulitple classes that aren't pure virtual is discouraged [fuchsia-multiple-inheritance]
-// CHECK-NEXT: struct D4 : V5, V6 {};
-struct D4 : V5, V6 {};
-
-struct Base4 {};
-struct V7 : virtual Base4 { virtual void f() = 0; };
-struct V8 : virtual Base4 { virtual void g() = 0; };
-struct D5 : V7, V8 {};
-
-struct Base5 { virtual void f() = 0; };
-struct V9 : virtual Base5 { virtual void f(); };
-struct V10 : virtual Base5 { virtual void g() = 0; };
-struct D6 : V9, V10 {};
-
-struct Base6 { virtual void f(); };
-struct Base7 { virtual void g(); };
-struct V15 : virtual Base6 { virtual void f() = 0; };
-struct V16 : virtual Base7 { virtual void g() = 0; };
-// CHECK-MESSAGES: [[@LINE+2]]:1: warning: inheriting mulitple classes that aren't pure virtual is discouraged [fuchsia-multiple-inheritance]
-// CHECK-NEXT: struct D9 : V15, V16 {};
-struct D9 : V15, V16 {};
-
-struct Static_Base { static void foo(); };
-struct V11 : virtual Static_Base {};
-struct V12 : virtual Static_Base {};
-struct D7 : V11, V12 {};
-
-struct Static_Base_2 {};
-struct V13 : virtual Static_Base_2 { static void f(); };
-struct V14 : virtual Static_Base_2 { static void g(); };
-struct D8 : V13, V14 {};
-
-template<typename T> struct A : T {};
-template<typename T> struct B : virtual T {};
-
-template<typename> struct C {};
-template<typename T> struct D : C<T> {};
-
-// Check clang_tidy does not crash on this code.
-template <class T>
-struct WithTemplBase : T {
- WithTemplBase();
-};
-
-int test_no_crash() {
- auto foo = []() {};
- WithTemplBase<decltype(foo)>();
-}
Removed: clang-tools-extra/trunk/test/clang-tidy/fuchsia-overloaded-operator.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/fuchsia-overloaded-operator.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/fuchsia-overloaded-operator.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/fuchsia-overloaded-operator.cpp (removed)
@@ -1,23 +0,0 @@
-// RUN: %check_clang_tidy %s fuchsia-overloaded-operator %t
-
-class A {
-public:
- int operator+(int);
- // CHECK-MESSAGES: [[@LINE-1]]:3: warning: overloading 'operator+' is disallowed
-};
-
-class B {
-public:
- B &operator=(const B &Other);
- // CHECK-MESSAGES-NOT: [[@LINE-1]]:3: warning: overloading 'operator=' is disallowed
- B &operator=(B &&Other);
- // CHECK-MESSAGES-NOT: [[@LINE-1]]:3: warning: overloading 'operator=' is disallowed
-};
-
-A operator-(const A &A1, const A &A2);
-// CHECK-MESSAGES: [[@LINE-1]]:1: warning: overloading 'operator-' is disallowed
-
-void operator delete(void*, void*) throw();
-// CHECK-MESSAGES: [[@LINE-1]]:1: warning: overloading 'operator delete' is disallowed
-
-auto x = []{};
Removed: clang-tools-extra/trunk/test/clang-tidy/fuchsia-restrict-system-includes-all.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/fuchsia-restrict-system-includes-all.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/fuchsia-restrict-system-includes-all.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/fuchsia-restrict-system-includes-all.cpp (removed)
@@ -1,10 +0,0 @@
-// RUN: %check_clang_tidy %s fuchsia-restrict-system-includes %t \
-// RUN: -- -config="{CheckOptions: [{key: fuchsia-restrict-system-includes.Includes, value: ''}]}" \
-// RUN: -- -I %S/Inputs/fuchsia-restrict-system-includes -isystem %S/Inputs/fuchsia-restrict-system-includes/system
-
-#include <cstdlib.h>
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include cstdlib.h not allowed
-#include <cstdarg.h>
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include cstdarg.h not allowed
-#include <t.h>
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include t.h not allowed
Removed: clang-tools-extra/trunk/test/clang-tidy/fuchsia-restrict-system-includes-glob.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/fuchsia-restrict-system-includes-glob.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/fuchsia-restrict-system-includes-glob.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/fuchsia-restrict-system-includes-glob.cpp (removed)
@@ -1,9 +0,0 @@
-// RUN: %check_clang_tidy %s fuchsia-restrict-system-includes %t \
-// RUN: -- -config="{CheckOptions: [{key: fuchsia-restrict-system-includes.Includes, value: 'cstd*'}]}" \
-// RUN: -- -I %S/Inputs/fuchsia-restrict-system-includes -isystem %S/Inputs/fuchsia-restrict-system-includes/system
-
-#include <cstdlib.h>
-#include <cstdarg.h>
-#include <t.h>
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include t.h not allowed
-// CHECK-FIXES-NOT: #include <t.h>
Removed: clang-tools-extra/trunk/test/clang-tidy/fuchsia-restrict-system-includes-headers.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/fuchsia-restrict-system-includes-headers.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/fuchsia-restrict-system-includes-headers.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/fuchsia-restrict-system-includes-headers.cpp (removed)
@@ -1,24 +0,0 @@
-// RUN: rm -rf %T/Headers
-// RUN: mkdir %T/Headers
-// RUN: cp -r %S/Inputs/fuchsia-restrict-system-includes %T/Headers/fuchsia-restrict-system-includes
-// RUN: %check_clang_tidy -std=c++11 %s fuchsia-restrict-system-includes %t \
-// RUN: -- -config="{CheckOptions: [{key: fuchsia-restrict-system-includes.Includes, value: 'transitive.h,s.h'}]}" \
-// RUN: -system-headers -header-filter=.* \
-// RUN: -- -I %T/Headers/fuchsia-restrict-system-includes -isystem %T/Headers/fuchsia-restrict-system-includes/system
-// RUN: FileCheck -input-file=%T/Headers/fuchsia-restrict-system-includes/transitive2.h %s -check-prefix=CHECK-FIXES
-// RUN: rm -rf %T/Headers
-// FIXME: Make the test work in all language modes.
-
-// transitive.h includes <r.h> and <t.h>
-#include <transitive.h>
-// CHECK-MESSAGES: :1:1: warning: system include r.h not allowed, transitively included from {{.*}}
-// CHECK-MESSAGES: :2:1: warning: system include t.h not allowed, transitively included from {{.*}}
-
-// transitive.h includes <s.h> and <t.h>
-#include "transitive2.h"
-// CHECK-MESSAGES: :2:1: warning: system include t.h not allowed, transitively included from {{.*}}
-// CHECK-FIXES-NOT: #include <t.h>
-
-int main() {
- // f() is declared in r.h
-}
Removed: clang-tools-extra/trunk/test/clang-tidy/fuchsia-restrict-system-includes.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/fuchsia-restrict-system-includes.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/fuchsia-restrict-system-includes.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/fuchsia-restrict-system-includes.cpp (removed)
@@ -1,25 +0,0 @@
-// RUN: %check_clang_tidy %s fuchsia-restrict-system-includes %t \
-// RUN: -- -config="{CheckOptions: [{key: fuchsia-restrict-system-includes.Includes, value: 's.h'}]}" \
-// RUN: -- -I %S/Inputs/fuchsia-restrict-system-includes -isystem %S/Inputs/fuchsia-restrict-system-includes/system
-
-#include "a.h"
-
-#include <s.h>
-#include <t.h>
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include t.h not allowed
-// CHECK-FIXES-NOT: #include <t.h>
-
-#include "s.h"
-#include "t.h"
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include t.h not allowed
-// CHECK-FIXES-NOT: #include "t.h"
-
-#define foo <j.h>
-
-#include foo
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include j.h not allowed
-// CHECK-FIXES-NOT: #include foo
-
-#/* comment */ include /* comment */ foo
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include j.h not allowed
-// CHECK-FIXES-NOT: # /* comment */ include /* comment */ foo
Removed: clang-tools-extra/trunk/test/clang-tidy/fuchsia-statically-constructed-objects.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/fuchsia-statically-constructed-objects.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/fuchsia-statically-constructed-objects.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/fuchsia-statically-constructed-objects.cpp (removed)
@@ -1,91 +0,0 @@
-// RUN: %check_clang_tidy %s fuchsia-statically-constructed-objects %t
-
-// Trivial static is fine
-static int i;
-
-class ClassWithNoCtor {};
-
-class ClassWithCtor {
-public:
- ClassWithCtor(int Val) : Val(Val) {}
-private:
- int Val;
-};
-
-class ClassWithConstexpr {
-public:
- ClassWithConstexpr(int Val1, int Val2) : Val(Val1) {}
- constexpr ClassWithConstexpr(int Val) : Val(Val) {}
-
-private:
- int Val;
-};
-
-ClassWithNoCtor A;
-ClassWithConstexpr C(0);
-ClassWithConstexpr E(0, 1);
-// CHECK-MESSAGES: [[@LINE-1]]:1: warning: static objects are disallowed; if possible, use a constexpr constructor instead [fuchsia-statically-constructed-objects]
-// CHECK-MESSAGES-NEXT: ClassWithConstexpr E(0, 1);
-ClassWithCtor G(0);
-// CHECK-MESSAGES: [[@LINE-1]]:1: warning: static objects are disallowed; if possible, use a constexpr constructor instead [fuchsia-statically-constructed-objects]
-// CHECK-MESSAGES-NEXT: ClassWithCtor G(0);
-
-static ClassWithNoCtor A2;
-static ClassWithConstexpr C2(0);
-static ClassWithConstexpr E2(0, 1);
-// CHECK-MESSAGES: [[@LINE-1]]:1: warning: static objects are disallowed; if possible, use a constexpr constructor instead [fuchsia-statically-constructed-objects]
-// CHECK-MESSAGES-NEXT: static ClassWithConstexpr E2(0, 1);
-static ClassWithCtor G2(0);
-// CHECK-MESSAGES: [[@LINE-1]]:1: warning: static objects are disallowed; if possible, use a constexpr constructor instead [fuchsia-statically-constructed-objects]
-// CHECK-MESSAGES-NEXT: static ClassWithCtor G2(0);
-
-struct StructWithConstexpr { constexpr StructWithConstexpr(int Val) {} };
-struct StructWithNoCtor {};
-struct StructWithCtor { StructWithCtor(); };
-
-StructWithNoCtor SNoCtor;
-StructWithConstexpr SConstexpr(0);
-StructWithCtor SCtor;
-// CHECK-MESSAGES: [[@LINE-1]]:1: warning: static objects are disallowed; if possible, use a constexpr constructor instead [fuchsia-statically-constructed-objects]
-// CHECK-MESSAGES-NEXT: StructWithCtor SCtor;
-
-static StructWithConstexpr SConstexpr2(0);
-static StructWithNoCtor SNoCtor2;
-static StructWithCtor SCtor2;
-// CHECK-MESSAGES: [[@LINE-1]]:1: warning: static objects are disallowed; if possible, use a constexpr constructor instead [fuchsia-statically-constructed-objects]
-// CHECK-MESSAGES-NEXT: static StructWithCtor SCtor2;
-
-extern StructWithCtor SCtor3;
-
-class ClassWithStaticMember {
-private:
- static StructWithNoCtor S;
-};
-
-ClassWithStaticMember Z();
-
-class S {
- int Val;
-public:
- constexpr S(int i) : Val(100 / i) {}
- int getVal() const { return Val; }
-};
-
-static S s1(1);
-static S s2(0);
-// CHECK-MESSAGES: [[@LINE-1]]:1: warning: static objects are disallowed; if possible, use a constexpr constructor instead [fuchsia-statically-constructed-objects]
-// CHECK-MESSAGES-NEXT: static S s2(0);
-
-extern int get_i();
-static S s3(get_i());
-// CHECK-MESSAGES: [[@LINE-1]]:1: warning: static objects are disallowed; if possible, use a constexpr constructor instead [fuchsia-statically-constructed-objects]
-// CHECK-MESSAGES-NEXT: static S s3(get_i());
-
-void f() {
- // Locally static is fine
- static int i;
- static ClassWithNoCtor A2;
- static ClassWithConstexpr C2(0);
- static ClassWithConstexpr E2(0, 1);
- static ClassWithCtor G2(0);
-}
Removed: clang-tools-extra/trunk/test/clang-tidy/fuchsia-trailing-return.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/fuchsia-trailing-return.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/fuchsia-trailing-return.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/fuchsia-trailing-return.cpp (removed)
@@ -1,23 +0,0 @@
-// RUN: %check_clang_tidy %s fuchsia-trailing-return %t
-
-int add_one(const int arg) { return arg; }
-
-auto get_add_one() -> int (*)(const int) {
- // CHECK-MESSAGES: [[@LINE-1]]:1: warning: a trailing return type is disallowed for this type of declaration
- // CHECK-NEXT: auto get_add_one() -> int (*)(const int) {
- return add_one;
-}
-
-auto lambda = [](double x, double y) {return x + y;};
-
-auto lambda2 = [](double x, double y) -> double {return x + y;};
-
-int main() {
- get_add_one()(5);
- return 0;
-}
-
-template <typename T1, typename T2>
-auto fn(const T1 &lhs, const T2 &rhs) -> decltype(lhs + rhs) {
- return lhs + rhs;
-}
Removed: clang-tools-extra/trunk/test/clang-tidy/fuchsia-virtual-inheritance.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/fuchsia-virtual-inheritance.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/fuchsia-virtual-inheritance.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/fuchsia-virtual-inheritance.cpp (removed)
@@ -1,42 +0,0 @@
-// RUN: %check_clang_tidy %s fuchsia-virtual-inheritance %t
-
-class A {
-public:
- A(int value) : val(value) {}
-
- int do_A() { return val; }
-
-private:
- int val;
-};
-
-class B : public virtual A {
- // CHECK-MESSAGES: [[@LINE-1]]:1: warning: direct virtual inheritance is disallowed [fuchsia-virtual-inheritance]
- // CHECK-NEXT: class B : public virtual A {
-public:
- B() : A(0) {}
- int do_B() { return 1 + do_A(); }
-};
-
-class C : public virtual A {
- // CHECK-MESSAGES: [[@LINE-1]]:1: warning: direct virtual inheritance is disallowed [fuchsia-virtual-inheritance]
- // CHECK-NEXT: class C : public virtual A {
-public:
- C() : A(0) {}
- int do_C() { return 2 + do_A(); }
-};
-
-class D : public B, public C {
-public:
- D(int value) : A(value), B(), C() {}
-
- int do_D() { return do_A() + do_B() + do_C(); }
-};
-
-int main() {
- A *a = new A(0);
- B *b = new B();
- C *c = new C();
- D *d = new D(0);
- return 0;
-}
Removed: clang-tools-extra/trunk/test/clang-tidy/google-build-explicit-make-pair.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/google-build-explicit-make-pair.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/google-build-explicit-make-pair.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/google-build-explicit-make-pair.cpp (removed)
@@ -1,51 +0,0 @@
-// RUN: %check_clang_tidy %s google-build-explicit-make-pair %t
-
-namespace std {
-template <class T1, class T2>
-struct pair {
- pair(T1 x, T2 y) {}
-};
-
-template <class T1, class T2>
-pair<T1, T2> make_pair(T1 x, T2 y) {
- return pair<T1, T2>(x, y);
-}
-}
-
-template <typename T>
-void templ(T a, T b) {
- std::make_pair<T, unsigned>(a, b);
- std::make_pair<int, int>(1, 2);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: for C++11-compatibility, omit template arguments from make_pair
-// CHECK-FIXES: std::make_pair(1, 2)
-}
-
-template <typename T>
-int t();
-
-void test(int i) {
- std::make_pair<int, int>(i, i);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: for C++11-compatibility, omit template arguments from make_pair
-// CHECK-FIXES: std::make_pair(i, i)
-
- std::make_pair<unsigned, int>(i, i);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: for C++11-compatibility, use pair directly
-// CHECK-FIXES: std::pair<unsigned, int>(i, i)
-
- std::make_pair<int, unsigned>(i, i);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: for C++11-compatibility, use pair directly
-// CHECK-FIXES: std::pair<int, unsigned>(i, i)
-
-#define M std::make_pair<int, unsigned>(i, i);
-M
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: for C++11-compatibility, use pair directly
-// Can't fix in macros.
-// CHECK-FIXES: #define M std::make_pair<int, unsigned>(i, i);
-// CHECK-FIXES-NEXT: M
-
- templ(i, i);
- templ(1U, 2U);
-
- std::make_pair(i, 1); // no-warning
- std::make_pair(t<int>, 1);
-}
Removed: clang-tools-extra/trunk/test/clang-tidy/google-default-arguments.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/google-default-arguments.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/google-default-arguments.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/google-default-arguments.cpp (removed)
@@ -1,29 +0,0 @@
-// RUN: %check_clang_tidy %s google-default-arguments %t
-
-struct A {
- virtual void f(int I, int J = 3);
- // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: default arguments on virtual or override methods are prohibited [google-default-arguments]
-};
-
-struct B : public A {
- void f(int I, int J = 5);
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: default arguments on virtual or override methods are prohibited
-};
-
-struct C : public B {
- void f(int I, int J = 5) override;
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: default arguments on virtual or override methods are prohibited
-};
-
-// Negatives.
-struct D : public B {
- void f(int I, int J) override;
-};
-
-struct X {
- void f(int I, int J = 3);
-};
-
-struct Y : public X {
- void f(int I, int J = 5);
-};
Removed: clang-tools-extra/trunk/test/clang-tidy/google-explicit-constructor.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/google-explicit-constructor.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/google-explicit-constructor.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/google-explicit-constructor.cpp (removed)
@@ -1,188 +0,0 @@
-// RUN: %check_clang_tidy %s google-explicit-constructor %t
-
-namespace std {
- typedef decltype(sizeof(int)) size_t;
-
- // libc++'s implementation
- template <class _E>
- class initializer_list
- {
- const _E* __begin_;
- size_t __size_;
-
- initializer_list(const _E* __b, size_t __s)
- : __begin_(__b),
- __size_(__s)
- {}
-
- public:
- typedef _E value_type;
- typedef const _E& reference;
- typedef const _E& const_reference;
- typedef size_t size_type;
-
- typedef const _E* iterator;
- typedef const _E* const_iterator;
-
- initializer_list() : __begin_(nullptr), __size_(0) {}
-
- size_t size() const {return __size_;}
- const _E* begin() const {return __begin_;}
- const _E* end() const {return __begin_ + __size_;}
- };
-}
-
-struct A {
- A() {}
- A(int x, int y) {}
-
- explicit A(void *x) {}
- explicit A(void *x, void *y) {}
- explicit operator bool() const { return true; }
-
- operator double() const = delete;
-
- explicit A(const A& a) {}
- // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: copy constructor should not be declared explicit [google-explicit-constructor]
- // CHECK-FIXES: {{^ }}A(const A& a) {}
-
- A(int x1);
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: single-argument constructors must be marked explicit to avoid unintentional implicit conversions [google-explicit-constructor]
- // CHECK-FIXES: {{^ }}explicit A(int x1);
-
- A(double x2, double y = 3.14) {}
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructors that are callable with a single argument must be marked explicit to avoid unintentional implicit conversions [google-explicit-constructor]
- // CHECK-FIXES: {{^ }}explicit A(double x2, double y = 3.14) {}
-
- template <typename... T>
- A(T&&... args);
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructors that are callable with a single argument
- // CHECK-FIXES: {{^ }}explicit A(T&&... args);
-};
-
-inline A::A(int x1) {}
-
-struct B {
- B(std::initializer_list<int> list1) {}
- B(const std::initializer_list<unsigned> &list2) {}
- B(std::initializer_list<unsigned> &&list3) {}
-
- operator bool() const { return true; }
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'operator bool' must be marked explicit to avoid unintentional implicit conversions [google-explicit-constructor]
- // CHECK-FIXES: {{^ }}explicit operator bool() const { return true; }
-
- operator double() const;
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'operator double' must be marked explicit to avoid unintentional implicit conversions [google-explicit-constructor]
- // CHECK-FIXES: {{^ }}explicit operator double() const;
-
- explicit B(::std::initializer_list<double> list4) {}
- // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: initializer-list constructor should not be declared explicit [google-explicit-constructor]
- // CHECK-FIXES: {{^ }}B(::std::initializer_list<double> list4) {}
-
- explicit B(const ::std::initializer_list<char> &list5) {}
- // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: initializer-list constructor
- // CHECK-FIXES: {{^ }}B(const ::std::initializer_list<char> &list5) {}
-
- explicit B(::std::initializer_list<char> &&list6) {}
- // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: initializer-list constructor
- // CHECK-FIXES: {{^ }}B(::std::initializer_list<char> &&list6) {}
-};
-
-inline B::operator double() const { return 0.0; }
-
-struct StructWithFnPointer {
- void (*f)();
-} struct_with_fn_pointer = {[] {}};
-
-using namespace std;
-
-struct C {
- C(initializer_list<int> list1) {}
- C(const initializer_list<unsigned> &list2) {}
- C(initializer_list<unsigned> &&list3) {}
-};
-
-template <typename T>
-struct C2 {
- C2(initializer_list<int> list1) {}
- C2(const initializer_list<unsigned> &list2) {}
- C2(initializer_list<unsigned> &&list3) {}
-
- explicit C2(initializer_list<double> list4) {}
- // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: initializer-list constructor
- // CHECK-FIXES: {{^ }}C2(initializer_list<double> list4) {}
-};
-
-template <typename T>
-struct C3 {
- C3(initializer_list<T> list1) {}
- C3(const std::initializer_list<T*> &list2) {}
- C3(::std::initializer_list<T**> &&list3) {}
-
- template <typename U>
- C3(initializer_list<U> list3) {}
-};
-
-struct D {
- template <typename T>
- explicit D(T t) {}
-};
-
-template <typename T>
-struct E {
- E(T *pt) {}
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: single-argument constructors
- // CHECK-FIXES: {{^ }}explicit E(T *pt) {}
- template <typename U>
- E(U *pu) {}
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: single-argument constructors
- // CHECK-FIXES: {{^ }}explicit E(U *pu) {}
-
- explicit E(T t) {}
- template <typename U>
- explicit E(U u) {}
-};
-
-void f(std::initializer_list<int> list) {
- D d(list);
- E<decltype(list)> e(list);
- E<int> e2(list);
-}
-
-template <typename T>
-struct F {};
-
-template<typename T>
-struct G {
- operator bool() const;
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'operator bool' must be marked
- // CHECK-FIXES: {{^}} explicit operator bool() const;
- operator F<T>() const;
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'operator F<type-parameter-0-0>' must be marked
- // CHECK-FIXES: {{^}} explicit operator F<T>() const;
- template<typename U>
- operator F<U>*() const;
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'operator F<type-parameter-1-0> *' must be marked
- // CHECK-FIXES: {{^}} explicit operator F<U>*() const;
-};
-
-void f2() {
- G<int> a;
- (void)(F<int>)a;
- if (a) {}
- (void)(F<int>*)a;
- (void)(F<int*>*)a;
-
- G<double> b;
- (void)(F<double>)b;
- if (b) {}
- (void)(F<double>*)b;
- (void)(F<double*>*)b;
-}
-
-#define DEFINE_STRUCT_WITH_OPERATOR_BOOL(name) \
- struct name { \
- operator bool() const; \
- }
-
-DEFINE_STRUCT_WITH_OPERATOR_BOOL(H);
Removed: clang-tools-extra/trunk/test/clang-tidy/google-module.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/google-module.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/google-module.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/google-module.cpp (removed)
@@ -1,10 +0,0 @@
-// RUN: clang-tidy -checks='-*,google*' -config='{}' -dump-config - -- | FileCheck %s
-// CHECK: CheckOptions:
-// CHECK: {{- key: *google-readability-braces-around-statements.ShortStatementLines}}
-// CHECK-NEXT: {{value: *'1'}}
-// CHECK: {{- key: *google-readability-function-size.StatementThreshold}}
-// CHECK-NEXT: {{value: *'800'}}
-// CHECK: {{- key: *google-readability-namespace-comments.ShortNamespaceLines}}
-// CHECK-NEXT: {{value: *'10'}}
-// CHECK: {{- key: *google-readability-namespace-comments.SpacesBeforeComments}}
-// CHECK-NEXT: {{value: *'2'}}
Removed: clang-tools-extra/trunk/test/clang-tidy/google-namespaces.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/google-namespaces.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/google-namespaces.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/google-namespaces.cpp (removed)
@@ -1,52 +0,0 @@
-// RUN: clang-tidy %s -checks='-*,google-build-namespaces,google-build-using-namespace' -header-filter='.*' -- | FileCheck %s -implicit-check-not="{{warning|error}}:"
-#include "Inputs/google-namespaces.h"
-// CHECK: warning: do not use unnamed namespaces in header files [google-build-namespaces]
-
-using namespace spaaaace;
-// CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace]
-
-using spaaaace::core; // no-warning
-
-namespace std {
-inline namespace literals {
-inline namespace chrono_literals {
-}
-inline namespace complex_literals {
-}
-inline namespace string_literals {
-}
-}
-}
-
-using namespace std::chrono_literals; // no-warning
-using namespace std::complex_literals; // no-warning
-using namespace std::literals; // no-warning
-using namespace std::literals::chrono_literals; // no-warning
-using namespace std::literals::complex_literals; // no-warning
-using namespace std::literals::string_literals; // no-warning
-using namespace std::string_literals; // no-warning
-
-namespace literals {}
-
-using namespace literals;
-// CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace]
-
-namespace foo {
-inline namespace literals {
-inline namespace bar_literals {}
-}
-}
-
-using namespace foo::literals;
-// CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace]
-
-using namespace foo::bar_literals;
-// CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace]
-
-using namespace foo::literals::bar_literals;
-// CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace]
-
-namespace foo_literals {}
-
-using namespace foo_literals;
-// CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace]
Removed: clang-tools-extra/trunk/test/clang-tidy/google-objc-avoid-nsobject-new.m
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/google-objc-avoid-nsobject-new.m?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/google-objc-avoid-nsobject-new.m (original)
+++ clang-tools-extra/trunk/test/clang-tidy/google-objc-avoid-nsobject-new.m (removed)
@@ -1,80 +0,0 @@
-// RUN: %check_clang_tidy %s google-objc-avoid-nsobject-new %t
-
- at interface NSObject
-+ (instancetype)new;
-+ (instancetype)alloc;
-- (instancetype)init;
- at end
-
- at interface NSProxy // Root class with no -init method.
- at end
-
-// NSDate provides a specific factory method.
- at interface NSDate : NSObject
-+ (instancetype)date;
- at end
-
-// For testing behavior with Objective-C Generics.
- at interface NSMutableDictionary<__covariant KeyType, __covariant ObjectType> : NSObject
- at end
-
- at class NSString;
-
-#define ALLOCATE_OBJECT(_Type) [_Type new]
-
-void CheckSpecificInitRecommendations(void) {
- NSObject *object = [NSObject new];
- // CHECK-MESSAGES: [[@LINE-1]]:22: warning: do not create objects with +new [google-objc-avoid-nsobject-new]
- // CHECK-FIXES: [NSObject alloc] init];
-
- NSDate *correctDate = [NSDate date];
- NSDate *incorrectDate = [NSDate new];
- // CHECK-MESSAGES: [[@LINE-1]]:27: warning: do not create objects with +new [google-objc-avoid-nsobject-new]
- // CHECK-FIXES: [NSDate date];
-
- NSObject *macroCreated = ALLOCATE_OBJECT(NSObject); // Shouldn't warn on macros.
-
- NSMutableDictionary *dict = [NSMutableDictionary<NSString *, NSString *> new];
- // CHECK-MESSAGES: [[@LINE-1]]:31: warning: do not create objects with +new [google-objc-avoid-nsobject-new]
- // CHECK-FIXES: [NSMutableDictionary<NSString *, NSString *> alloc] init];
-}
-
- at interface Foo : NSObject
-+ (instancetype)new; // Declare again to suppress warning.
-- (instancetype)initWithInt:(int)anInt;
-- (instancetype)init __attribute__((unavailable));
-
-- (id)new;
- at end
-
- at interface Baz : Foo // Check unavailable -init through inheritance.
- at end
-
- at interface ProxyFoo : NSProxy
-+ (instancetype)new;
- at end
-
-void CallNewWhenInitUnavailable(void) {
- Foo *foo = [Foo new];
- // CHECK-MESSAGES: [[@LINE-1]]:14: warning: do not create objects with +new [google-objc-avoid-nsobject-new]
-
- Baz *baz = [Baz new];
- // CHECK-MESSAGES: [[@LINE-1]]:14: warning: do not create objects with +new [google-objc-avoid-nsobject-new]
-
- // Instance method -new calls may be weird, but are not strictly forbidden.
- Foo *bar = [[Foo alloc] initWithInt:4];
- [bar new];
-
- ProxyFoo *proxy = [ProxyFoo new];
- // CHECK-MESSAGES: [[@LINE-1]]:21: warning: do not create objects with +new [google-objc-avoid-nsobject-new]
-}
-
- at interface HasNewOverride : NSObject
- at end
-
- at implementation HasNewOverride
-+ (instancetype)new {
- return [[self alloc] init];
-}
-// CHECK-MESSAGES: [[@LINE-3]]:1: warning: classes should not override +new [google-objc-avoid-nsobject-new]
- at end
Removed: clang-tools-extra/trunk/test/clang-tidy/google-objc-avoid-throwing-exception.m
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/google-objc-avoid-throwing-exception.m?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/google-objc-avoid-throwing-exception.m (original)
+++ clang-tools-extra/trunk/test/clang-tidy/google-objc-avoid-throwing-exception.m (removed)
@@ -1,32 +0,0 @@
-// RUN: %check_clang_tidy %s google-objc-avoid-throwing-exception %t
- at class NSString;
-
- at interface NSException
-
-+ (void)raise:(NSString *)name format:(NSString *)format;
-+ (void)raise:(NSString *)name format:(NSString *)format arguments:(NSString *)args; // using NSString type since va_list cannot be recognized here
-
- at end
-
- at interface NotException
-
-+ (void)raise:(NSString *)name format:(NSString *)format;
-
- at end
-
- at implementation Foo
-- (void)f {
- NSString *foo = @"foo";
- @throw foo;
- // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: pass in NSError ** instead of throwing exception to indicate Objective-C errors [google-objc-avoid-throwing-exception]
-}
-
-- (void)f2 {
- [NSException raise:@"TestException" format:@"Test"];
- // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: pass in NSError ** instead of throwing exception to indicate Objective-C errors [google-objc-avoid-throwing-exception]
- [NSException raise:@"TestException" format:@"Test %@" arguments:@"bar"];
- // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: pass in NSError ** instead of throwing exception to indicate Objective-C errors [google-objc-avoid-throwing-exception]
- [NotException raise:@"NotException" format:@"Test"];
-}
- at end
-
Removed: clang-tools-extra/trunk/test/clang-tidy/google-objc-function-naming.m
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/google-objc-function-naming.m?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/google-objc-function-naming.m (original)
+++ clang-tools-extra/trunk/test/clang-tidy/google-objc-function-naming.m (removed)
@@ -1,71 +0,0 @@
-// RUN: %check_clang_tidy %s google-objc-function-naming %t -- -- -isystem %S/Inputs/Headers
-
-#include <stdio.h>
-
-static void TestImplicitFunctionDeclaration(int a) {
- // Call a builtin function so that the compiler generates an implicit
- // function declaration.
- printf("%d", a);
-}
-
-typedef _Bool bool;
-
-static bool ispositive(int a) { return a > 0; }
-// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: static function named 'ispositive'
-// must be in Pascal case as required by Google Objective-C style guide
-// CHECK-FIXES: static bool Ispositive(int a) { return a > 0; }
-
-static bool is_positive(int a) { return a > 0; }
-// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: static function named 'is_positive'
-// must be in Pascal case as required by Google Objective-C style guide
-// CHECK-FIXES: static bool IsPositive(int a) { return a > 0; }
-
-static bool isPositive(int a) { return a > 0; }
-// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: static function named 'isPositive'
-// must be in Pascal case as required by Google Objective-C style guide
-// CHECK-FIXES: static bool IsPositive(int a) { return a > 0; }
-
-static bool Is_Positive(int a) { return a > 0; }
-// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: static function named 'Is_Positive'
-// must be in Pascal case as required by Google Objective-C style guide
-// CHECK-FIXES: static bool IsPositive(int a) { return a > 0; }
-
-static bool IsPositive(int a) { return a > 0; }
-
-bool ispalindrome(const char *str);
-// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function in global namespace named
-// 'ispalindrome' must have an appropriate prefix followed by Pascal case as
-// required by Google Objective-C style guide
-
-static const char *md5(const char *str) { return 0; }
-// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: static function named 'md5' must be
-// in Pascal case as required by Google Objective-C style guide
-// CHECK-FIXES: static const char *Md5(const char *str) { return 0; }
-
-static const char *MD5(const char *str) { return 0; }
-
-static const char *URL(void) { return "https://clang.llvm.org/"; }
-
-static const char *DEFURL(void) { return "https://clang.llvm.org/"; }
-
-static const char *DEFFooURL(void) { return "https://clang.llvm.org/"; }
-
-static const char *StringFromNSString(id str) { return ""; }
-
-void ABLog_String(const char *str);
-// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function in global namespace named
-// 'ABLog_String' must have an appropriate prefix followed by Pascal case as
-// required by Google Objective-C style guide
-
-void ABLogString(const char *str);
-
-bool IsPrime(int a);
-// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function in global namespace named
-// 'IsPrime' must have an appropriate prefix followed by Pascal case as required
-// by Google Objective-C style guide
-
-const char *ABURL(void) { return "https://clang.llvm.org/"; }
-
-const char *ABFooURL(void) { return "https://clang.llvm.org/"; }
-
-int main(int argc, const char **argv) { return 0; }
Removed: clang-tools-extra/trunk/test/clang-tidy/google-objc-function-naming.mm
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/google-objc-function-naming.mm?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/google-objc-function-naming.mm (original)
+++ clang-tools-extra/trunk/test/clang-tidy/google-objc-function-naming.mm (removed)
@@ -1,33 +0,0 @@
-// RUN: %check_clang_tidy %s google-objc-function-naming %t
-
-void printSomething() {}
-// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function in global namespace named
-// 'printSomething' must have an appropriate prefix followed by Pascal case as
-// required by Google Objective-C style guide
-
-void PrintSomething() {}
-// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function in global namespace named
-// 'PrintSomething' must have an appropriate prefix followed by Pascal case as
-// required by Google Objective-C style guide
-
-void ABCBad_Name() {}
-// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function in global namespace named
-// 'ABCBad_Name' must have an appropriate prefix followed by Pascal case as
-// required by Google Objective-C style guide
-
-namespace {
-
-int foo() { return 0; }
-
-}
-
-namespace bar {
-
-int convert() { return 0; }
-
-}
-
-class Baz {
-public:
- int value() { return 0; }
-};
Removed: clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.m
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.m?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.m (original)
+++ clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.m (removed)
@@ -1,66 +0,0 @@
-// RUN: %check_clang_tidy %s google-objc-global-variable-declaration %t
-
- at class NSString;
-
-static NSString* const myConstString = @"hello";
-// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'myConstString' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
-// CHECK-FIXES: static NSString* const kMyConstString = @"hello";
-
-extern NSString* const GlobalConstant = @"hey";
-// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'GlobalConstant' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
-
-static NSString* MyString = @"hi";
-// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: non-const global variable 'MyString' must have a name which starts with 'g[A-Z]' [google-objc-global-variable-declaration]
-// CHECK-FIXES: static NSString* gMyString = @"hi";
-
-NSString* globalString = @"test";
-// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: non-const global variable 'globalString' must have a name which starts with 'g[A-Z]' [google-objc-global-variable-declaration]
-// CHECK-FIXES: NSString* gGlobalString = @"test";
-
-static NSString* a = @"too simple";
-// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: non-const global variable 'a' must have a name which starts with 'g[A-Z]' [google-objc-global-variable-declaration]
-// CHECK-FIXES: static NSString* a = @"too simple";
-
-static NSString* noDef;
-// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: non-const global variable 'noDef' must have a name which starts with 'g[A-Z]' [google-objc-global-variable-declaration]
-// CHECK-FIXES: static NSString* gNoDef;
-
-static NSString* const _notAlpha = @"NotBeginWithAlpha";
-// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable '_notAlpha' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
-// CHECK-FIXES: static NSString* const _notAlpha = @"NotBeginWithAlpha";
-
-static NSString* const notCap = @"NotBeginWithCap";
-// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'notCap' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
-// CHECK-FIXES: static NSString* const kNotCap = @"NotBeginWithCap";
-
-static NSString* const k_Alpha = @"SecondNotAlpha";
-// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'k_Alpha' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
-// CHECK-FIXES: static NSString* const k_Alpha = @"SecondNotAlpha";
-
-static NSString* const SecondNotCap = @"SecondNotCapOrNumber";
-// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'SecondNotCap' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
-// CHECK-FIXES: static NSString* const kSecondNotCap = @"SecondNotCapOrNumber";
-
-extern NSString* Y2Bad;
-// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: non-const global variable 'Y2Bad' must have a name which starts with 'g[A-Z]' [google-objc-global-variable-declaration]
-// CHECK-FIXES: extern NSString* gY2Bad;
-
-static NSString* const kGood = @"hello";
-static NSString* const XYGood = @"hello";
-static NSString* const X1Good = @"hello";
-static NSString* gMyIntGood = 0;
-
-extern NSString* const GTLServiceErrorDomain;
-
-enum GTLServiceError {
- GTLServiceErrorQueryResultMissing = -3000,
- GTLServiceErrorWaitTimedOut = -3001,
-};
-
- at implementation Foo
-- (void)f {
- int x = 0;
- static int bar;
- static const int baz = 42;
-}
- at end
Removed: clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.mm
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.mm?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.mm (original)
+++ clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.mm (removed)
@@ -1,10 +0,0 @@
-// RUN: %check_clang_tidy %s google-objc-global-variable-declaration %t
-
- at class NSString;
-static NSString* const myConstString = @"hello";
-// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'myConstString' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
-// CHECK-FIXES: static NSString* const kMyConstString = @"hello";
-
-class MyTest {
- static int not_objc_style;
-};
Removed: clang-tools-extra/trunk/test/clang-tidy/google-overloaded-unary-and.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/google-overloaded-unary-and.cpp?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/google-overloaded-unary-and.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/google-overloaded-unary-and.cpp (removed)
@@ -1,25 +0,0 @@
-// RUN: %check_clang_tidy %s google-runtime-operator %t
-
-struct Foo {
- void *operator&();
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not overload unary operator&, it is dangerous. [google-runtime-operator]
-};
-
-template <typename T>
-struct TFoo {
- T *operator&();
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not overload unary operator&
-};
-
-TFoo<int> tfoo;
-
-struct Bar;
-void *operator&(Bar &b);
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: do not overload unary operator&
-
-// No warnings on binary operators.
-struct Qux {
- void *operator&(Qux &q);
-};
-
-void *operator&(Qux &q, Qux &r);
Removed: clang-tools-extra/trunk/test/clang-tidy/google-readability-casting.c
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/google-readability-casting.c?rev=374539&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/google-readability-casting.c (original)
+++ clang-tools-extra/trunk/test/clang-tidy/google-readability-casting.c (removed)
@@ -1,24 +0,0 @@
-// RUN: %check_clang_tidy %s google-readability-casting %t -- -- -x c
-// The testing script always adds .cpp extension to the input file name, so we
-// need to run clang-tidy directly in order to verify handling of .c files:
-// RUN: clang-tidy --checks=-*,google-readability-casting %s -- -x c++ | FileCheck %s -check-prefix=CHECK-MESSAGES -implicit-check-not='{{warning|error}}:'
-// RUN: cp %s %t.main_file.cpp
-// RUN: clang-tidy --checks=-*,google-readability-casting -header-filter='.*' %t.main_file.cpp -- -I%S -DTEST_INCLUDE -x c++ | FileCheck %s -check-prefix=CHECK-MESSAGES -implicit-check-not='{{warning|error}}:'
-
-#ifdef TEST_INCLUDE
-
-#undef TEST_INCLUDE
-#include "google-readability-casting.c"
-
-#else
-
-void f(const char *cpc) {
- const char *cpc2 = (const char*)cpc;
- // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: redundant cast to the same type [google-readability-casting]
- // CHECK-FIXES: const char *cpc2 = cpc;
- char *pc = (char*)cpc;
- typedef const char *Typedef1;
- (Typedef1)cpc;
-}
-
-#endif
More information about the cfe-commits
mailing list