diff --git a/clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp b/clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp --- a/clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp +++ b/clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp @@ -88,7 +88,7 @@ diag(SrcBegin, "%0 must be tagged with the LIBC_INLINE macro; the macro " "should be placed at the beginning of the declaration") - << FuncDecl; + << FuncDecl << FixItHint::CreateInsertion(Loc, "LIBC_INLINE "); } } // namespace clang::tidy::llvm_libc diff --git a/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp b/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp --- a/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp +++ b/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp @@ -17,11 +17,13 @@ constexpr long long addll(long long a, long long b) { // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: 'addll' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl] +// CHECK-FIXES: LIBC_INLINE constexpr long long addll(long long a, long long b) { return a + b; } inline unsigned long addul(unsigned long a, unsigned long b) { // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: 'addul' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl] +// CHECK-FIXES: LIBC_INLINE inline unsigned long addul(unsigned long a, unsigned long b) { return a + b; } @@ -30,11 +32,13 @@ public: MyClass() : A(123) {} // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'MyClass' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl] + // CHECK-FIXES: LIBC_INLINE MyClass() : A(123) {} LIBC_INLINE MyClass(int V) : A(V) {} constexpr operator int() const { return A; } // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'operator int' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl] + // CHECK-FIXES: LIBC_INLINE constexpr operator int() const { return A; } LIBC_INLINE bool operator==(const MyClass &RHS) { return RHS.A == A; @@ -42,6 +46,7 @@ static int getVal(const MyClass &V) { // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'getVal' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl] + // CHECK-FIXES: LIBC_INLINE static int getVal(const MyClass &V) { return V.A; } @@ -51,6 +56,7 @@ constexpr static int addInt(MyClass &V, int A) { // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'addInt' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl] + // CHECK-FIXES: LIBC_INLINE constexpr static int addInt(MyClass &V, int A) { return V.A += A; } @@ -78,6 +84,7 @@ inline void badSimpleFunction() {} // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: 'badSimpleFunction' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl] +// CHECK-FIXES: LIBC_INLINE inline void badSimpleFunction() {} void LIBC_INLINE badSimpleFunctionWrongLocation() {} // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: 'badSimpleFunctionWrongLocation' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl] @@ -93,6 +100,7 @@ template inline void badTemplateFunction() {} // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: 'badTemplateFunction' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl] +// CHECK-FIXES: template LIBC_INLINE inline void badTemplateFunction() {} template void LIBC_INLINE badTemplateFunctionWrongLocation() {} // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: 'badTemplateFunctionWrongLocation' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl] @@ -108,9 +116,11 @@ template inline void badVariadicFunction() {} // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: 'badVariadicFunction' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl] +// CHECK-FIXES: template LIBC_INLINE inline void badVariadicFunction() {} template void LIBC_INLINE badVariadicFunctionWrongLocation() {} // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: 'badVariadicFunctionWrongLocation' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl] +// CHECK-FIXES: template LIBC_INLINE void LIBC_INLINE badVariadicFunctionWrongLocation() {} struct NoTemplate { void goodNoTemplate(); @@ -137,22 +147,27 @@ inline void NoTemplate::badNoTemplate() {} // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: 'badNoTemplate' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl] +// CHECK-FIXES: LIBC_INLINE inline void NoTemplate::badNoTemplate() {} void LIBC_INLINE NoTemplate::badNoTemplateWrongLocation() {} // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: 'badNoTemplateWrongLocation' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl] +// CHECK-FIXES: LIBC_INLINE void LIBC_INLINE NoTemplate::badNoTemplateWrongLocation() {} template LIBC_INLINE void NoTemplate::goodNestedTemplate() {} template inline void NoTemplate::badNestedTemplate() {} // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: 'badNestedTemplate' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl] +// CHECK-FIXES: template LIBC_INLINE inline void NoTemplate::badNestedTemplate() {} template void LIBC_INLINE NoTemplate::badNestedTemplateWrongLocation() {} // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: 'badNestedTemplateWrongLocation' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl] +// CHECK-FIXES: template LIBC_INLINE void LIBC_INLINE NoTemplate::badNestedTemplateWrongLocation() {} template LIBC_INLINE void NoTemplate::goodVariadicTemplate() {} template void inline NoTemplate::badVariadicTemplate() {} // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: 'badVariadicTemplate' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl] +// CHECK-FIXES: template LIBC_INLINE void inline NoTemplate::badVariadicTemplate() {} template void LIBC_INLINE NoTemplate::badVariadicTemplateWrongLocation() {} // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: 'badVariadicTemplateWrongLocation' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl] @@ -182,6 +197,7 @@ template inline void SimpleTemplate::badSimpleTemplate() {} // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: 'badSimpleTemplate' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl] +// CHECK-FIXES: template LIBC_INLINE inline void SimpleTemplate::badSimpleTemplate() {} template void LIBC_INLINE SimpleTemplate::badSimpleTemplateWrongLocation() {} // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: 'badSimpleTemplateWrongLocation' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl] @@ -190,6 +206,7 @@ template template inline void SimpleTemplate::badNestedTemplate() {} // CHECK-MESSAGES: :[[@LINE-1]]:45: warning: 'badNestedTemplate' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl] +// CHECK-FIXES: template template LIBC_INLINE inline void SimpleTemplate::badNestedTemplate() {} template template void LIBC_INLINE SimpleTemplate::badNestedTemplateWrongLocation() {} // CHECK-MESSAGES: :[[@LINE-1]]:45: warning: 'badNestedTemplateWrongLocation' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl] @@ -198,6 +215,7 @@ template template inline void SimpleTemplate::badNestedVariadicTemplate() {} // CHECK-MESSAGES: :[[@LINE-1]]:49: warning: 'badNestedVariadicTemplate' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl] +// CHECK-FIXES: template template LIBC_INLINE inline void SimpleTemplate::badNestedVariadicTemplate() {} template template void LIBC_INLINE SimpleTemplate::badNestedVariadicTemplateWrongLocation() {} // CHECK-MESSAGES: :[[@LINE-1]]:49: warning: 'badNestedVariadicTemplateWrongLocation' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl] @@ -227,6 +245,7 @@ template inline void VariadicTemplate::badVariadicTemplate() {} // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: 'badVariadicTemplate' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl] +// CHECK-FIXES: template LIBC_INLINE inline void VariadicTemplate::badVariadicTemplate() {} template void LIBC_INLINE VariadicTemplate::badVariadicTemplateWrongLocation() {} // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: 'badVariadicTemplateWrongLocation' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl] @@ -235,6 +254,7 @@ template template inline void VariadicTemplate::badNestedTemplate() {} // CHECK-MESSAGES: :[[@LINE-1]]:49: warning: 'badNestedTemplate' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl] +// CHECK-FIXES: template template LIBC_INLINE inline void VariadicTemplate::badNestedTemplate() {} template template void LIBC_INLINE VariadicTemplate::badNestedTemplateWrongLocation() {} // CHECK-MESSAGES: :[[@LINE-1]]:49: warning: 'badNestedTemplateWrongLocation' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl] @@ -243,6 +263,7 @@ template template inline void VariadicTemplate::badNestedVariadicTemplate() {} // CHECK-MESSAGES: :[[@LINE-1]]:53: warning: 'badNestedVariadicTemplate' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl] +// CHECK-FIXES: template template LIBC_INLINE inline void VariadicTemplate::badNestedVariadicTemplate() {} template template void LIBC_INLINE VariadicTemplate::badNestedVariadicTemplateWrongLocation() {} // CHECK-MESSAGES: :[[@LINE-1]]:53: warning: 'badNestedVariadicTemplateWrongLocation' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]