Please use GitHub pull requests for new patches. Phabricator shutdown timeline
Changeset View
Standalone View
clang-tools-extra/test/clang-tidy/checkers/modernize-use-trailing-return-type.cpp
// RUN: %check_clang_tidy -std=c++14,c++17 %s modernize-use-trailing-return-type %t -- -- -fdeclspec -fexceptions | // RUN: %check_clang_tidy -std=c++14-or-later %s modernize-use-trailing-return-type %t -- -- -fdeclspec -fexceptions -DCOMMAND_LINE_INT=int | ||||
aaron.ballman: The change to the language standard line makes me wonder if the fixme below it is now stale, or… | |||||
I just ran the tests again using python .\check_clang_tidy.py -std=c++20 .\checkers\modernize-use-trailing-return-type.cpp modernize-use-trailing-return-type aa -- -- -DCOMMAND_LINE_INT=int and I did not see mentioning of the use of an uninitialized variable. But I run on Windows, maybe the issue just surfaces on another OS? Is there a way to trigger the CI again? I removed the FIXME in question in the hope the issue resolved itself. bernhardmgruber: I just ran the tests again using `python .\check_clang_tidy.py -std=c++20 .\checkers\modernize… | |||||
I also run on Windows so I can't easily test the behavior elsewhere for you. The CI will get triggered on new patch uploads, but I still don't always trust it. The bots are usually a more reliable source of CI truth but we have no way to speculatively trigger all the bots. aaron.ballman: > But I run on Windows, maybe the issue just surfaces on another OS? Is there a way to trigger… | |||||
I can run it for you with asan/msan. riccibruno: I can run it for you with asan/msan. | |||||
No warning with either asan or msan on x86-64 linux with clang 10. riccibruno: No warning with either asan or msan on x86-64 linux with clang 10. | |||||
Thank you @riccibruno for verifying that for me! bernhardmgruber: Thank you @riccibruno for verifying that for me! | |||||
// FIXME: Fix the checker to work in C++20 mode, it is performing a | |||||
// use-of-uninitialized-value. | |||||
namespace std { | namespace std { | ||||
template <typename T> | template <typename T> | ||||
class vector; | class vector; | ||||
template <typename T, int N> | template <typename T, int N> | ||||
class array; | class array; | ||||
class string; | class string; | ||||
class ostream; | |||||
template <typename T> | template <typename T> | ||||
auto declval() -> T; | auto declval() -> T; | ||||
} | } | ||||
// | // | ||||
// Functions | // Functions | ||||
// | // | ||||
▲ Show 20 Lines • Show All 188 Lines • ▼ Show 20 Lines | |||||
static const char* const * const * const e12(void* user_data); | 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-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;{{$}} | // CHECK-FIXES: {{^}}static auto e12(void* user_data) -> const char* const * const * const;{{$}} | ||||
struct A e13(); | struct A e13(); | ||||
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use a trailing return type for this function [modernize-use-trailing-return-type] | // 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;{{$}} | // CHECK-FIXES: {{^}}auto e13() -> struct A;{{$}} | ||||
// | // | ||||
// decltype (unsupported if top level expression) | // deduced return types | ||||
// | // | ||||
const auto ded1(); | |||||
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use a trailing return type for this function [modernize-use-trailing-return-type] | |||||
// CHECK-FIXES: {{^}}auto ded1() -> const auto;{{$}} | |||||
const auto& ded2(); | |||||
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use a trailing return type for this function [modernize-use-trailing-return-type] | |||||
// CHECK-FIXES: {{^}}auto ded2() -> const auto&;{{$}} | |||||
decltype(auto) ded3(); | |||||
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use a trailing return type for this function [modernize-use-trailing-return-type] | |||||
// CHECK-FIXES: {{^}}auto ded3() -> decltype(auto);{{$}} | |||||
decltype(1 + 2) dec1() { return 1 + 2; } | 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] | // 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 | // CHECK-FIXES: {{^}}auto dec1() -> decltype(1 + 2) { return 1 + 2; }{{$}} | ||||
// _HECK-FIXES: {{^}}auto dec1() -> decltype(1 + 2) { return 1 + 2; }{{$}} | |||||
template <typename F, typename T> | template <typename F, typename T> | ||||
decltype(std::declval<F>(std::declval<T>)) dec2(F f, T t) { return f(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] | // 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 | // CHECK-FIXES: {{^}}auto dec2(F f, T t) -> decltype(std::declval<F>(std::declval<T>)) { return f(t); }{{$}} | ||||
// _HECK-FIXES: {{^}}auto dec2(F f, T t) -> decltype(std::declval<F>(std::declval<T>)) { return f(t); }{{$}} | |||||
template <typename T> | template <typename T> | ||||
typename decltype(std::declval<T>())::value_type dec3(); | 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-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;{{$}} | // CHECK-FIXES: {{^}}auto dec3() -> typename decltype(std::declval<T>())::value_type;{{$}} | ||||
template <typename T> | template <typename T> | ||||
decltype(std::declval<T>())* dec4(); | 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-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>())*;{{$}} | // CHECK-FIXES: {{^}}auto dec4() -> decltype(std::declval<T>())*;{{$}} | ||||
▲ Show 20 Lines • Show All 220 Lines • ▼ Show 20 Lines | |||||
#define CONST_CAT con##st | #define CONST_CAT con##st | ||||
CONST_CAT int& h19(); | CONST_CAT int& h19(); | ||||
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use a trailing return type for this function [modernize-use-trailing-return-type] | // 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&;{{$}} | // CHECK-FIXES: {{^}}auto h19() -> CONST_CAT int&;{{$}} | ||||
#define CONST_F_MACRO WRAP(CONST_CAT) | #define CONST_F_MACRO WRAP(CONST_CAT) | ||||
CONST_F_MACRO int& h19(); | 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-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&;{{$}} | // CHECK-FIXES: {{^}}auto h19() -> CONST_F_MACRO int&;{{$}} | ||||
// Macro COMMAND_LINE_INT is defined on the command line via: -DCOMMAND_LINE_INT=int | |||||
const COMMAND_LINE_INT& h20(); | |||||
// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: use a trailing return type for this function [modernize-use-trailing-return-type] | |||||
// CHECK-FIXES: {{^}}auto h20() -> const COMMAND_LINE_INT&;{{$}} | |||||
decltype(COMMAND_LINE_INT{}) h21(); | |||||
// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: use a trailing return type for this function [modernize-use-trailing-return-type] | |||||
// CHECK-FIXES: {{^}}auto h21() -> decltype(COMMAND_LINE_INT{});{{$}} | |||||
// | // | ||||
// Name collisions | // Name collisions | ||||
// | // | ||||
struct Object { long long value; }; | struct Object { long long value; }; | ||||
Object j1(unsigned Object) { return {Object * 2}; } | 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-MESSAGES: :[[@LINE-1]]:8: warning: use a trailing return type for this function [modernize-use-trailing-return-type] | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | |||||
// CHECK-FIXES: {{^}} auto g() -> ::Object;{{$}} | // CHECK-FIXES: {{^}} auto g() -> ::Object;{{$}} | ||||
}; | }; | ||||
Object DD::g() { | Object DD::g() { | ||||
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use a trailing return type for this function [modernize-use-trailing-return-type] | // 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 {{{$}} | // CHECK-FIXES: {{^}}auto DD::g() -> Object {{{$}} | ||||
return {0}; | return {0}; | ||||
} | } | ||||
// | |||||
// bug 44206, no rewrite should happen due to collision with parameter name | |||||
// | |||||
using std::ostream; | |||||
How do you want to handle these tests which require C++20? I have seen other checks use a separate file for tests which require a different language version. bernhardmgruber: How do you want to handle these tests which require C++20? I have seen other checks use a… | |||||
Yes, move them into a seperate file and specify -std=c++20 in the run line njames93: Yes, move them into a seperate file and specify `-std=c++20` in the run line | |||||
Ok, done. Thx! bernhardmgruber: Ok, done. Thx! | |||||
ostream& operator<<(ostream& ostream, int i); | |||||
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use a trailing return type for this function [modernize-use-trailing-return-type] | |||||
// CHECK-FIXES: {{^}}ostream& operator<<(ostream& ostream, int i);{{$}} | |||||
// | // | ||||
// Samples which do not trigger the check | // Samples which do not trigger the check | ||||
// | // | ||||
auto f() -> int; | auto f() -> int; | ||||
auto f(int) -> int; | auto f(int) -> int; | ||||
auto f(int arg) -> int; | auto f(int arg) -> int; | ||||
auto f(int arg1, int arg2, int arg3) -> int; | auto f(int arg1, int arg2, int arg3) -> 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; | template <typename T> auto f(T t) -> int; | ||||
auto ff(); | auto ff(); | ||||
decltype(auto) fff(); | |||||
void c(); | void c(); | ||||
void c(int arg); | void c(int arg); | ||||
void c(int arg) { return; } | void c(int arg) { return; } | ||||
struct D2 : B { | struct D2 : B { | ||||
D2(); | D2(); | ||||
virtual ~D2(); | virtual ~D2(); | ||||
Show All 10 Lines |
The change to the language standard line makes me wonder if the fixme below it is now stale, or if the test will fail in C++20 mode.