mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-18 14:36:46 +00:00
[Clang] [NFC] Fix more -Wreturn-type
warnings in tests everywhere (#123470)
With the goal of eventually being able to make `-Wreturn-type` default to an error in all language modes, this is a follow-up to #123464 and updates even more tests, mainly clang-tidy and clangd tests.
This commit is contained in:
parent
6e7da07c73
commit
b0210fee94
@ -329,7 +329,7 @@ TEST(ClangdAST, GetContainedAutoParamType) {
|
||||
auto &&d,
|
||||
auto *&e,
|
||||
auto (*f)(int)
|
||||
){};
|
||||
){ return 0; };
|
||||
|
||||
int withoutAuto(
|
||||
int a,
|
||||
@ -338,7 +338,7 @@ TEST(ClangdAST, GetContainedAutoParamType) {
|
||||
int &&d,
|
||||
int *&e,
|
||||
int (*f)(int)
|
||||
){};
|
||||
){ return 0; };
|
||||
)cpp");
|
||||
TU.ExtraArgs.push_back("-std=c++20");
|
||||
auto AST = TU.build();
|
||||
|
@ -113,7 +113,7 @@ TEST(WorkspaceSymbols, Unnamed) {
|
||||
TEST(WorkspaceSymbols, InMainFile) {
|
||||
TestTU TU;
|
||||
TU.Code = R"cpp(
|
||||
int test() {}
|
||||
int test() { return 0; }
|
||||
static void test2() {}
|
||||
)cpp";
|
||||
EXPECT_THAT(getSymbols(TU, "test"),
|
||||
@ -537,12 +537,14 @@ TEST(DocumentSymbols, InHeaderFile) {
|
||||
TestTU TU;
|
||||
TU.AdditionalFiles["bar.h"] = R"cpp(
|
||||
int foo() {
|
||||
return 0;
|
||||
}
|
||||
)cpp";
|
||||
TU.Code = R"cpp(
|
||||
int i; // declaration to finish preamble
|
||||
#include "bar.h"
|
||||
int test() {
|
||||
return 0;
|
||||
}
|
||||
)cpp";
|
||||
EXPECT_THAT(getSymbols(TU.build()),
|
||||
@ -780,7 +782,7 @@ TEST(DocumentSymbols, FuncTemplates) {
|
||||
TestTU TU;
|
||||
Annotations Source(R"cpp(
|
||||
template <class T>
|
||||
T foo() {}
|
||||
T foo() { return T{}; }
|
||||
|
||||
auto x = foo<int>();
|
||||
auto y = foo<double>();
|
||||
|
@ -251,7 +251,7 @@ TEST(ParsedASTTest, NoCrashOnTokensWithTidyCheck) {
|
||||
// this check runs the preprocessor, we need to make sure it does not break
|
||||
// our recording logic.
|
||||
TU.ClangTidyProvider = addTidyChecks("modernize-use-trailing-return-type");
|
||||
TU.Code = "inline int foo() {}";
|
||||
TU.Code = "inline int foo() { return 0; }";
|
||||
|
||||
auto AST = TU.build();
|
||||
const syntax::TokenBuffer &T = AST.getTokens();
|
||||
|
@ -108,7 +108,7 @@ TEST(QualityTests, SymbolRelevanceSignalExtraction) {
|
||||
|
||||
using flags::FLAGS_FOO;
|
||||
|
||||
int ::header_main() {}
|
||||
int ::header_main() { return 0; }
|
||||
int main();
|
||||
|
||||
[[deprecated]]
|
||||
|
@ -214,7 +214,7 @@ TEST(RenameTest, WithinFileRename) {
|
||||
template<typename T>
|
||||
class Foo {
|
||||
public:
|
||||
static T [[f^oo]]() {}
|
||||
static T [[f^oo]]() { return T(); }
|
||||
};
|
||||
|
||||
void bar() {
|
||||
@ -225,7 +225,7 @@ TEST(RenameTest, WithinFileRename) {
|
||||
template<typename T>
|
||||
class Foo {
|
||||
public:
|
||||
T [[f^oo]]() {}
|
||||
T [[f^oo]]() { return T(); }
|
||||
};
|
||||
|
||||
void bar() {
|
||||
@ -827,7 +827,7 @@ TEST(RenameTest, WithinFileRename) {
|
||||
|
||||
// Issue 170: Rename symbol introduced by UsingDecl
|
||||
R"cpp(
|
||||
namespace ns { void [[f^oo]](); }
|
||||
namespace ns { void [[f^oo]](); }
|
||||
|
||||
using ns::[[f^oo]];
|
||||
|
||||
@ -1307,7 +1307,7 @@ TEST(RenameTest, Renameable) {
|
||||
"no symbol", false},
|
||||
|
||||
{R"cpp(// FIXME we probably want to rename both overloads here,
|
||||
// but renaming currently assumes there's only a
|
||||
// but renaming currently assumes there's only a
|
||||
// single canonical declaration.
|
||||
namespace ns { int foo(int); char foo(char); }
|
||||
using ns::^foo;
|
||||
@ -1776,7 +1776,7 @@ TEST(CrossFileRenameTests, WithUpToDateIndex) {
|
||||
void [[foo]]() override {};
|
||||
};
|
||||
|
||||
void func(Base* b, Derived1* d1,
|
||||
void func(Base* b, Derived1* d1,
|
||||
Derived2* d2, NotDerived* nd) {
|
||||
b->[[foo]]();
|
||||
d1->[[foo]]();
|
||||
|
@ -741,6 +741,7 @@ sizeof...($TemplateParameter[[Elements]]);
|
||||
$Class[[Foo]].$Field_static[[sharedInstance]].$Field[[someProperty]] $Operator[[=]] 1;
|
||||
self.$Field[[someProperty]] $Operator[[=]] self.$Field[[someProperty]] $Operator[[+]] self.$Field[[otherMethod]] $Operator[[+]] 1;
|
||||
self->$Field[[_someProperty]] $Operator[[=]] $Field[[_someProperty]] $Operator[[+]] 1;
|
||||
return 0;
|
||||
}
|
||||
@end
|
||||
)cpp",
|
||||
|
@ -201,6 +201,7 @@ TEST(FoldingRanges, ASTAll) {
|
||||
R"cpp(
|
||||
#define FOO int foo() {\
|
||||
int Variable = 42; \
|
||||
return 0; \
|
||||
}
|
||||
|
||||
// Do not generate folding range for braces within macro expansion.
|
||||
@ -336,18 +337,18 @@ TEST(FoldingRanges, PseudoParserWithoutLineFoldings) {
|
||||
]]};
|
||||
)cpp",
|
||||
R"cpp(
|
||||
/*[[ Multi
|
||||
/*[[ Multi
|
||||
* line
|
||||
* comment
|
||||
* comment
|
||||
]]*/
|
||||
)cpp",
|
||||
R"cpp(
|
||||
//[[ Comment
|
||||
// 1]]
|
||||
|
||||
|
||||
//[[ Comment
|
||||
// 2]]
|
||||
|
||||
|
||||
// No folding for single line comment.
|
||||
|
||||
/*[[ comment 3
|
||||
|
@ -36,6 +36,7 @@ TEST(SymbolInfoTests, All) {
|
||||
void $decl[[foo]]();
|
||||
int bar() {
|
||||
fo^o();
|
||||
return 0;
|
||||
}
|
||||
)cpp",
|
||||
{ExpectedSymbolDetails{"foo", "", "c:@F@foo#", "decl"}}},
|
||||
@ -44,6 +45,7 @@ TEST(SymbolInfoTests, All) {
|
||||
void $def[[foo]]() {}
|
||||
int bar() {
|
||||
fo^o();
|
||||
return 0;
|
||||
}
|
||||
)cpp",
|
||||
{ExpectedSymbolDetails{"foo", "", "c:@F@foo#", "def", "def"}}},
|
||||
@ -53,6 +55,7 @@ TEST(SymbolInfoTests, All) {
|
||||
void $def[[foo]]() {}
|
||||
int bar() {
|
||||
fo^o();
|
||||
return 0;
|
||||
}
|
||||
)cpp",
|
||||
{ExpectedSymbolDetails{"foo", "", "c:@F@foo#", "decl", "def"}}},
|
||||
@ -83,6 +86,7 @@ TEST(SymbolInfoTests, All) {
|
||||
void $decl[[foo]]();
|
||||
int baz() {
|
||||
fo^o();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
)cpp",
|
||||
@ -96,6 +100,7 @@ TEST(SymbolInfoTests, All) {
|
||||
namespace barbar {
|
||||
int baz() {
|
||||
bar::fo^o();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
)cpp",
|
||||
@ -108,6 +113,7 @@ TEST(SymbolInfoTests, All) {
|
||||
namespace Nbaz {
|
||||
int baz() {
|
||||
::fo^o();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -121,6 +127,7 @@ TEST(SymbolInfoTests, All) {
|
||||
namespace barbar {
|
||||
int baz() {
|
||||
fo^o();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
)cpp",
|
||||
@ -136,6 +143,7 @@ TEST(SymbolInfoTests, All) {
|
||||
int baz() {
|
||||
bar::BarType b;
|
||||
fo^o(b);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
)cpp",
|
||||
|
@ -95,7 +95,7 @@ TEST(HighlightsTest, All) {
|
||||
)cpp",
|
||||
|
||||
R"cpp(// Function
|
||||
int [[^foo]](int) {}
|
||||
int [[^foo]](int) { return 0; }
|
||||
int main() {
|
||||
[[foo]]([[foo]](42));
|
||||
auto *X = &[[foo]];
|
||||
@ -2140,7 +2140,7 @@ TEST(FindReferences, WithinAST) {
|
||||
)cpp",
|
||||
|
||||
R"cpp(// Function
|
||||
int $def[[foo]](int) {}
|
||||
int $def[[foo]](int) { return 0; }
|
||||
int main() {
|
||||
auto *X = &$(main)[[^foo]];
|
||||
$(main)[[foo]](42);
|
||||
@ -2160,7 +2160,7 @@ TEST(FindReferences, WithinAST) {
|
||||
|
||||
R"cpp(// Method call
|
||||
struct Foo { int $decl(Foo)[[foo]](); };
|
||||
int Foo::$def(Foo)[[foo]]() {}
|
||||
int Foo::$def(Foo)[[foo]]() { return 0; }
|
||||
int main() {
|
||||
Foo f;
|
||||
f.$(main)[[^foo]]();
|
||||
@ -2258,7 +2258,7 @@ TEST(FindReferences, WithinAST) {
|
||||
)cpp",
|
||||
R"cpp(// Dependent code
|
||||
template <typename T> void $decl[[foo]](T t);
|
||||
template <typename T> void bar(T t) { $(bar)[[foo]](t); } // foo in bar is uninstantiated.
|
||||
template <typename T> void bar(T t) { $(bar)[[foo]](t); } // foo in bar is uninstantiated.
|
||||
void baz(int x) { $(baz)[[f^oo]](x); }
|
||||
)cpp",
|
||||
R"cpp(
|
||||
@ -2508,6 +2508,7 @@ TEST(FindReferences, ExplicitSymbols) {
|
||||
X $def(test)[[a]];
|
||||
$(test)[[a]].operator bool();
|
||||
if ($(test)[[a^]]) {} // ignore implicit conversion-operator AST node
|
||||
return 0;
|
||||
}
|
||||
)cpp",
|
||||
};
|
||||
@ -2543,7 +2544,7 @@ TEST(FindReferences, UsedSymbolsFromInclude) {
|
||||
#define BAR 5
|
||||
int bar1();
|
||||
int bar2();
|
||||
class Bar {};
|
||||
class Bar {};
|
||||
)cpp");
|
||||
TU.AdditionalFiles["system/vector"] = guard(R"cpp(
|
||||
namespace std {
|
||||
@ -2560,7 +2561,7 @@ TEST(FindReferences, UsedSymbolsFromInclude) {
|
||||
std::vector<Matcher<ReferencesResult::Reference>> ExpectedLocations;
|
||||
for (const auto &R : T.ranges())
|
||||
ExpectedLocations.push_back(AllOf(rangeIs(R), attrsAre(0u)));
|
||||
for (const auto &P : T.points())
|
||||
for (const auto &P : T.points())
|
||||
EXPECT_THAT(findReferences(AST, P, 0).References,
|
||||
UnorderedElementsAreArray(ExpectedLocations))
|
||||
<< "Failed for Refs at " << P << "\n"
|
||||
@ -2635,6 +2636,7 @@ TEST(FindReferences, NeedsIndexForMacro) {
|
||||
Annotations IndexedMain(R"cpp(
|
||||
int indexed_main() {
|
||||
int a = [[MACRO]](1);
|
||||
return 0;
|
||||
}
|
||||
)cpp");
|
||||
|
||||
|
@ -935,10 +935,11 @@ TEST_F(DefineInlineTest, AddInline) {
|
||||
// Check we put inline before cv-qualifiers.
|
||||
ExtraFiles["a.h"] = "const int foo();";
|
||||
apply(R"cpp(#include "a.h"
|
||||
const int fo^o() {})cpp",
|
||||
const int fo^o() { return 0; })cpp",
|
||||
&EditedFiles);
|
||||
EXPECT_THAT(EditedFiles, testing::ElementsAre(FileWithContents(
|
||||
testPath("a.h"), "inline const int foo(){}")));
|
||||
EXPECT_THAT(EditedFiles,
|
||||
testing::ElementsAre(FileWithContents(
|
||||
testPath("a.h"), "inline const int foo(){ return 0; }")));
|
||||
|
||||
// No double inline.
|
||||
ExtraFiles["a.h"] = "inline void foo();";
|
||||
|
@ -69,8 +69,8 @@ TEST_F(ExpandDeducedTypeTest, Test) {
|
||||
EXPECT_THAT(apply(R"cpp(au^to s = &"foobar";)cpp"),
|
||||
StartsWith("fail: Could not expand type"));
|
||||
|
||||
EXPECT_EQ(apply("ns::Class * foo() { au^to c = foo(); }"),
|
||||
"ns::Class * foo() { ns::Class * c = foo(); }");
|
||||
EXPECT_EQ(apply("ns::Class * foo() { au^to c = foo(); return nullptr; }"),
|
||||
"ns::Class * foo() { ns::Class * c = foo(); return nullptr; }");
|
||||
EXPECT_EQ(
|
||||
apply("void ns::Func() { au^to x = new ns::Class::Nested{}; }"),
|
||||
"void ns::Func() { ns::Class::Nested * x = new ns::Class::Nested{}; }");
|
||||
|
@ -116,6 +116,7 @@ TEST_F(ExtractVariableTest, Test) {
|
||||
struct T {
|
||||
int bar(int a = [[1]]) {
|
||||
int b = [[z]];
|
||||
return 0;
|
||||
}
|
||||
int z = [[1]];
|
||||
} t;
|
||||
|
@ -10,7 +10,7 @@ std::string StringsFunction(std::string s1) { return s1; }
|
||||
class SomeContainer {};
|
||||
namespace strings_internal {
|
||||
void InternalFunction() {}
|
||||
template <class P> P InternalTemplateFunction(P a) {}
|
||||
template <class P> void InternalTemplateFunction(P a) { int; }
|
||||
} // namespace strings_internal
|
||||
|
||||
namespace container_internal {
|
||||
|
@ -18,7 +18,7 @@ T lexical_cast(const V &) {
|
||||
|
||||
struct my_weird_type {};
|
||||
|
||||
std::string fun(const std::string &) {}
|
||||
std::string fun(const std::string &) { return {}; }
|
||||
|
||||
void test_to_string1() {
|
||||
|
||||
@ -75,7 +75,7 @@ void test_to_string2() {
|
||||
fun(boost::lexical_cast<std::string>(j));
|
||||
}
|
||||
|
||||
std::string fun(const std::wstring &) {}
|
||||
std::string fun(const std::wstring &);
|
||||
|
||||
void test_to_wstring() {
|
||||
int a;
|
||||
|
@ -1,5 +1,5 @@
|
||||
// RUN: %check_clang_tidy -std=c++20 %s bugprone-exception-escape %t -- \
|
||||
// RUN: -- -fexceptions
|
||||
// RUN: -- -fexceptions -Wno-error=return-type
|
||||
|
||||
namespace std {
|
||||
|
||||
|
@ -20,6 +20,7 @@ int throwsAndCallsRethrower() noexcept {
|
||||
} catch(...) {
|
||||
rethrower();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int throwsAndCallsCallsRethrower() noexcept {
|
||||
@ -29,6 +30,7 @@ int throwsAndCallsCallsRethrower() noexcept {
|
||||
} catch(...) {
|
||||
callsRethrower();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void rethrowerNoexcept() noexcept {
|
||||
|
@ -665,6 +665,7 @@ int indirectly_recursive(int n) noexcept;
|
||||
|
||||
int recursion_helper(int n) {
|
||||
indirectly_recursive(n);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int indirectly_recursive(int n) noexcept {
|
||||
|
@ -8,24 +8,25 @@ T accumulate(InputIt first, InputIt last, T init) {
|
||||
// is instantiated. In practice this happens somewhere in the implementation
|
||||
// of `accumulate`. For tests, do it here.
|
||||
(void)*first;
|
||||
return init;
|
||||
}
|
||||
|
||||
template <class InputIt, class T>
|
||||
T reduce(InputIt first, InputIt last, T init) { (void)*first; }
|
||||
T reduce(InputIt first, InputIt last, T init) { (void)*first; return init; }
|
||||
template <class ExecutionPolicy, class InputIt, class T>
|
||||
T reduce(ExecutionPolicy &&policy,
|
||||
InputIt first, InputIt last, T init) { (void)*first; }
|
||||
InputIt first, InputIt last, T init) { (void)*first; return init; }
|
||||
|
||||
struct parallel_execution_policy {};
|
||||
constexpr parallel_execution_policy par{};
|
||||
|
||||
template <class InputIt1, class InputIt2, class T>
|
||||
T inner_product(InputIt1 first1, InputIt1 last1,
|
||||
InputIt2 first2, T value) { (void)*first1; (void)*first2; }
|
||||
InputIt2 first2, T value) { (void)*first1; (void)*first2; return value; }
|
||||
|
||||
template <class ExecutionPolicy, class InputIt1, class InputIt2, class T>
|
||||
T inner_product(ExecutionPolicy &&policy, InputIt1 first1, InputIt1 last1,
|
||||
InputIt2 first2, T value) { (void)*first1; (void)*first2; }
|
||||
InputIt2 first2, T value) { (void)*first1; (void)*first2; return value; }
|
||||
|
||||
} // namespace std
|
||||
|
||||
|
@ -5,5 +5,6 @@ _BitInt(8) v_401_0() {
|
||||
_BitInt(5) y = 0;
|
||||
16777215wb ?: ++y;
|
||||
});
|
||||
return 0;
|
||||
}
|
||||
// CHECK-MESSAGES: warning
|
||||
// CHECK-MESSAGES: warning
|
||||
|
@ -12,9 +12,9 @@ typedef struct cnd_t {
|
||||
} cnd_t;
|
||||
struct timespec {};
|
||||
|
||||
int cnd_wait(cnd_t *cond, mtx_t *mutex){};
|
||||
int cnd_wait(cnd_t *cond, mtx_t *mutex){ return 0; };
|
||||
int cnd_timedwait(cnd_t *cond, mtx_t *mutex,
|
||||
const struct timespec *time_point){};
|
||||
const struct timespec *time_point){ return 0; };
|
||||
|
||||
struct Node1 list_c;
|
||||
static mtx_t lock;
|
||||
|
@ -90,18 +90,18 @@ public:
|
||||
void wait(unique_lock<mutex> &lock, Predicate pred);
|
||||
template <class Clock, class Duration>
|
||||
cv_status wait_until(unique_lock<mutex> &lock,
|
||||
const chrono::time_point<Clock, Duration> &abs_time){};
|
||||
const chrono::time_point<Clock, Duration> &abs_time){ return cv_status::no_timeout; };
|
||||
template <class Clock, class Duration, class Predicate>
|
||||
bool wait_until(unique_lock<mutex> &lock,
|
||||
const chrono::time_point<Clock, Duration> &abs_time,
|
||||
Predicate pred){};
|
||||
Predicate pred){ return false; };
|
||||
template <class Rep, class Period>
|
||||
cv_status wait_for(unique_lock<mutex> &lock,
|
||||
const chrono::duration<Rep, Period> &rel_time){};
|
||||
const chrono::duration<Rep, Period> &rel_time){ return cv_status::no_timeout; };
|
||||
template <class Rep, class Period, class Predicate>
|
||||
bool wait_for(unique_lock<mutex> &lock,
|
||||
const chrono::duration<Rep, Period> &rel_time,
|
||||
Predicate pred){};
|
||||
Predicate pred){ return false; };
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
|
@ -27,7 +27,7 @@ public:
|
||||
|
||||
constexpr basic_string_view(const basic_string_view &) {}
|
||||
|
||||
constexpr basic_string_view &operator=(const basic_string_view &) {}
|
||||
constexpr basic_string_view &operator=(const basic_string_view &) { return *this; }
|
||||
};
|
||||
|
||||
template <typename CharT>
|
||||
|
@ -89,6 +89,8 @@ int test_warning_patterns() {
|
||||
if (strcmp(A, "a") < 0.)
|
||||
return 0;
|
||||
// CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'strcmp' has suspicious implicit cast
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int test_valid_patterns() {
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
int foo(int value = 5) { return value; }
|
||||
|
||||
int f() {
|
||||
void 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
|
||||
@ -10,7 +10,7 @@ int f() {
|
||||
|
||||
int bar(int value) { return value; }
|
||||
|
||||
int n() {
|
||||
void n() {
|
||||
foo(0);
|
||||
bar(0);
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ struct WithTemplBase : T {
|
||||
WithTemplBase();
|
||||
};
|
||||
|
||||
int test_no_crash() {
|
||||
void test_no_crash() {
|
||||
auto foo = []() {};
|
||||
WithTemplBase<decltype(foo)>();
|
||||
}
|
||||
|
@ -54,4 +54,5 @@ short bar(const short, unsigned short) {
|
||||
|
||||
tmpl<short>();
|
||||
// CHECK-MESSAGES: [[@LINE-1]]:8: warning: consider replacing 'short' with 'std::int16_t'
|
||||
return 0;
|
||||
}
|
||||
|
@ -221,9 +221,9 @@ public:
|
||||
// CHECK-FIXES: const char *test_suite_name() const;
|
||||
};
|
||||
|
||||
const char *FooTestInfo::test_case_name() const {}
|
||||
const char *FooTestInfo::test_case_name() const { return nullptr; }
|
||||
// CHECK-MESSAGES: [[@LINE-1]]:26: warning: Google Test APIs named with 'case'
|
||||
// CHECK-FIXES: const char *FooTestInfo::test_suite_name() const {}
|
||||
// CHECK-FIXES: const char *FooTestInfo::test_suite_name() const { return nullptr; }
|
||||
|
||||
class BarTestInfo : public testing::TestInfo {
|
||||
public:
|
||||
@ -491,26 +491,26 @@ public:
|
||||
// CHECK-FIXES: const testing::TestSuite *GetTestSuite(int) const;
|
||||
};
|
||||
|
||||
testing::TestCase *FooUnitTest::current_test_case() const {}
|
||||
testing::TestCase *FooUnitTest::current_test_case() const { return nullptr; }
|
||||
// CHECK-MESSAGES: [[@LINE-1]]:10: warning: Google Test APIs named with 'case'
|
||||
// CHECK-MESSAGES: [[@LINE-2]]:33: warning: Google Test APIs named with 'case'
|
||||
// CHECK-FIXES: testing::TestSuite *FooUnitTest::current_test_suite() const {}
|
||||
int FooUnitTest::successful_test_case_count() const {}
|
||||
// CHECK-FIXES: testing::TestSuite *FooUnitTest::current_test_suite() const { return nullptr; }
|
||||
int FooUnitTest::successful_test_case_count() const { return 0; }
|
||||
// CHECK-MESSAGES: [[@LINE-1]]:18: warning: Google Test APIs named with 'case'
|
||||
// CHECK-FIXES: int FooUnitTest::successful_test_suite_count() const {}
|
||||
int FooUnitTest::failed_test_case_count() const {}
|
||||
// CHECK-FIXES: int FooUnitTest::successful_test_suite_count() const { return 0; }
|
||||
int FooUnitTest::failed_test_case_count() const { return 0; }
|
||||
// CHECK-MESSAGES: [[@LINE-1]]:18: warning: Google Test APIs named with 'case'
|
||||
// CHECK-FIXES: int FooUnitTest::failed_test_suite_count() const {}
|
||||
int FooUnitTest::total_test_case_count() const {}
|
||||
// CHECK-FIXES: int FooUnitTest::failed_test_suite_count() const { return 0; }
|
||||
int FooUnitTest::total_test_case_count() const { return 0; }
|
||||
// CHECK-MESSAGES: [[@LINE-1]]:18: warning: Google Test APIs named with 'case'
|
||||
// CHECK-FIXES: int FooUnitTest::total_test_suite_count() const {}
|
||||
int FooUnitTest::test_case_to_run_count() const {}
|
||||
// CHECK-FIXES: int FooUnitTest::total_test_suite_count() const { return 0; }
|
||||
int FooUnitTest::test_case_to_run_count() const { return 0; }
|
||||
// CHECK-MESSAGES: [[@LINE-1]]:18: warning: Google Test APIs named with 'case'
|
||||
// CHECK-FIXES: int FooUnitTest::test_suite_to_run_count() const {}
|
||||
const testing::TestCase *FooUnitTest::GetTestCase(int) const {}
|
||||
// CHECK-FIXES: int FooUnitTest::test_suite_to_run_count() const { return 0; }
|
||||
const testing::TestCase *FooUnitTest::GetTestCase(int) const { return 0; }
|
||||
// CHECK-MESSAGES: [[@LINE-1]]:16: warning: Google Test APIs named with 'case'
|
||||
// CHECK-MESSAGES: [[@LINE-2]]:39: warning: Google Test APIs named with 'case'
|
||||
// CHECK-FIXES: const testing::TestSuite *FooUnitTest::GetTestSuite(int) const {}
|
||||
// CHECK-FIXES: const testing::TestSuite *FooUnitTest::GetTestSuite(int) const { return 0; }
|
||||
|
||||
// Type derived from testing::TestCase
|
||||
class BarUnitTest : public testing::UnitTest {
|
||||
|
@ -54,8 +54,8 @@ void template_instantiation() {
|
||||
struct ConstNonConstClass {
|
||||
ConstNonConstClass();
|
||||
ConstNonConstClass(double &np_local0);
|
||||
double nonConstMethod() {}
|
||||
double constMethod() const {}
|
||||
double nonConstMethod() { return 0; }
|
||||
double constMethod() const { return 0; }
|
||||
double modifyingMethod(double &np_arg0) const;
|
||||
|
||||
double NonConstMember;
|
||||
|
@ -283,8 +283,8 @@ void template_instantiation() {
|
||||
struct ConstNonConstClass {
|
||||
ConstNonConstClass();
|
||||
ConstNonConstClass(double &np_local0);
|
||||
double nonConstMethod() {}
|
||||
double constMethod() const {}
|
||||
double nonConstMethod() { return 0; }
|
||||
double constMethod() const { return 0; }
|
||||
double modifyingMethod(double &np_arg0) const;
|
||||
|
||||
double NonConstMember;
|
||||
|
@ -33,9 +33,9 @@ void f(void (*fn)()) {;}
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: parameter 'fn' is unused [misc-unused-parameters]
|
||||
// CHECK-FIXES: {{^}}void f(void (* /*fn*/)()) {;}{{$}}
|
||||
|
||||
int *k([[clang::lifetimebound]] int *i) {;}
|
||||
int *k([[clang::lifetimebound]] int *i) { return nullptr; }
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:38: warning: parameter 'i' is unused [misc-unused-parameters]
|
||||
// CHECK-FIXES: {{^}}int *k({{\[\[clang::lifetimebound\]\]}} int * /*i*/) {;}{{$}}
|
||||
// CHECK-FIXES: {{^}}int *k({{\[\[clang::lifetimebound\]\]}} int * /*i*/) { return nullptr; }{{$}}
|
||||
|
||||
#define ATTR_BEFORE(x) [[clang::lifetimebound]] x
|
||||
int* m(ATTR_BEFORE(const int *i)) { return nullptr; }
|
||||
|
@ -17,25 +17,25 @@ void func_cpp_inc() {}
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'func_cpp_inc'
|
||||
// CHECK-FIXES: static void func_cpp_inc() {}
|
||||
|
||||
int* func_cpp_inc_return_ptr() {}
|
||||
int* func_cpp_inc_return_ptr() { return nullptr; }
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'func_cpp_inc_return_ptr'
|
||||
// CHECK-FIXES: static int* func_cpp_inc_return_ptr() {}
|
||||
// CHECK-FIXES: static int* func_cpp_inc_return_ptr() { return nullptr; }
|
||||
|
||||
const int* func_cpp_inc_return_const_ptr() {}
|
||||
const int* func_cpp_inc_return_const_ptr() { return nullptr; }
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: function 'func_cpp_inc_return_const_ptr'
|
||||
// CHECK-FIXES: static const int* func_cpp_inc_return_const_ptr() {}
|
||||
// CHECK-FIXES: static const int* func_cpp_inc_return_const_ptr() { return nullptr; }
|
||||
|
||||
int const* func_cpp_inc_return_ptr_const() {}
|
||||
int const* func_cpp_inc_return_ptr_const() { return nullptr; }
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: function 'func_cpp_inc_return_ptr_const'
|
||||
// CHECK-FIXES: static int const* func_cpp_inc_return_ptr_const() {}
|
||||
// CHECK-FIXES: static int const* func_cpp_inc_return_ptr_const() { return nullptr; }
|
||||
|
||||
int * const func_cpp_inc_return_const() {}
|
||||
int * const func_cpp_inc_return_const() { return nullptr; }
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: function 'func_cpp_inc_return_const'
|
||||
// CHECK-FIXES: static int * const func_cpp_inc_return_const() {}
|
||||
// CHECK-FIXES: static int * const func_cpp_inc_return_const() { return nullptr; }
|
||||
|
||||
volatile const int* func_cpp_inc_return_volatile_const_ptr() {}
|
||||
volatile const int* func_cpp_inc_return_volatile_const_ptr() { return nullptr; }
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: function 'func_cpp_inc_return_volatile_const_ptr'
|
||||
// CHECK-FIXES: static volatile const int* func_cpp_inc_return_volatile_const_ptr() {}
|
||||
// CHECK-FIXES: static volatile const int* func_cpp_inc_return_volatile_const_ptr() { return nullptr; }
|
||||
|
||||
[[nodiscard]] void func_nodiscard() {}
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: function 'func_nodiscard'
|
||||
|
@ -214,8 +214,8 @@ class map : public bidirectional_iterable<iterator<pair<key, value>>> {
|
||||
public:
|
||||
map() {}
|
||||
|
||||
iterator<pair<key, value>> find(const key &) {}
|
||||
const_iterator<iterator<pair<key, value>>> find(const key &) const {}
|
||||
iterator<pair<key, value>> find(const key &);
|
||||
const_iterator<iterator<pair<key, value>>> find(const key &) const;
|
||||
};
|
||||
|
||||
template <typename key, typename value>
|
||||
|
@ -46,7 +46,7 @@ struct D {
|
||||
operator bool() const { return true; }
|
||||
|
||||
void MemberFunction(int x) {}
|
||||
int MemberFunctionWithReturn(int x) {}
|
||||
int MemberFunctionWithReturn(int x) { return 0; }
|
||||
|
||||
static D *create();
|
||||
};
|
||||
@ -342,7 +342,7 @@ void testCapturedSubexpressions() {
|
||||
|
||||
struct E {
|
||||
void MemberFunction(int x) {}
|
||||
int MemberFunctionWithReturn(int x) {}
|
||||
int MemberFunctionWithReturn(int x) { return 0; }
|
||||
int operator()(int x, int y) const { return x + y; }
|
||||
|
||||
void testMemberFunctions() {
|
||||
|
@ -1,11 +1,11 @@
|
||||
// RUN: %check_clang_tidy -std=c++20 %s modernize-avoid-c-arrays %t
|
||||
|
||||
int f1(int data[], int size) {
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: do not declare C-style arrays, use 'std::span' instead
|
||||
void f1(int data[], int size) {
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: do not declare C-style arrays, use 'std::span' instead
|
||||
int f4[] = {1, 2};
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use 'std::array' instead
|
||||
}
|
||||
|
||||
int f2(int data[100]) {
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: do not declare C-style arrays, use 'std::array' instead
|
||||
void f2(int data[100]) {
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: do not declare C-style arrays, use 'std::array' instead
|
||||
}
|
||||
|
@ -1,9 +1,13 @@
|
||||
// RUN: %check_clang_tidy -std=c++17 %s modernize-avoid-c-arrays %t
|
||||
|
||||
int not_main(int argc, char *argv[]) {
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: do not declare C-style arrays, use 'std::array' or 'std::vector' instead
|
||||
namespace X {
|
||||
// Not main
|
||||
int main(int argc, char *argv[]) {
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: do not declare C-style arrays, use 'std::array' or 'std::vector' instead
|
||||
int f4[] = {1, 2};
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use 'std::array' instead
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
@ -1,19 +1,23 @@
|
||||
// RUN: %check_clang_tidy -std=c++17 %s modernize-avoid-c-arrays %t
|
||||
|
||||
int not_main(int argc, char *argv[], char *argw[]) {
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: do not declare C-style arrays, use 'std::array' or 'std::vector' instead
|
||||
// CHECK-MESSAGES: :[[@LINE-2]]:38: warning: do not declare C-style arrays, use 'std::array' or 'std::vector' instead
|
||||
namespace X {
|
||||
// Not main.
|
||||
int main(int argc, char *argv[], char *argw[]) {
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: do not declare C-style arrays, use 'std::array' or 'std::vector' instead
|
||||
// CHECK-MESSAGES: :[[@LINE-2]]:34: warning: do not declare C-style arrays, use 'std::array' or 'std::vector' instead
|
||||
int f4[] = {1, 2};
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use 'std::array' instead
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[], char *argw[]) {
|
||||
int f5[] = {1, 2};
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use 'std::array' instead
|
||||
|
||||
auto not_main = [](int argc, char *argv[], char *argw[]) {
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: do not declare C-style arrays, use 'std::array' or 'std::vector' instead
|
||||
// CHECK-MESSAGES: :[[@LINE-2]]:46: warning: do not declare C-style arrays, use 'std::array' or 'std::vector' instead
|
||||
auto main = [](int argc, char *argv[], char *argw[]) {
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:28: warning: do not declare C-style arrays, use 'std::array' or 'std::vector' instead
|
||||
// CHECK-MESSAGES: :[[@LINE-2]]:42: warning: do not declare C-style arrays, use 'std::array' or 'std::vector' instead
|
||||
int f6[] = {1, 2};
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not declare C-style arrays, use 'std::array' instead
|
||||
};
|
||||
|
@ -170,6 +170,8 @@ const int *constArray() {
|
||||
// CHECK-FIXES: for (const int & I : ConstArr)
|
||||
// CHECK-FIXES-NEXT: if (Something)
|
||||
// CHECK-FIXES-NEXT: return &I;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
struct HasArr {
|
||||
|
@ -49,7 +49,7 @@ public:
|
||||
template <typename... Args>
|
||||
void emplace_back(Args &&... args){};
|
||||
template <typename... Args>
|
||||
iterator emplace(const_iterator pos, Args &&...args){};
|
||||
iterator emplace(const_iterator pos, Args &&...args);
|
||||
~vector();
|
||||
};
|
||||
|
||||
@ -69,7 +69,7 @@ public:
|
||||
void push_back(T &&) {}
|
||||
|
||||
template <typename... Args>
|
||||
iterator emplace(const_iterator pos, Args &&...args){};
|
||||
iterator emplace(const_iterator pos, Args &&...args);
|
||||
template <typename... Args>
|
||||
void emplace_back(Args &&... args){};
|
||||
template <typename... Args>
|
||||
@ -93,7 +93,7 @@ public:
|
||||
void push_front(T &&) {}
|
||||
|
||||
template <typename... Args>
|
||||
iterator emplace(const_iterator pos, Args &&...args){};
|
||||
iterator emplace(const_iterator pos, Args &&...args);
|
||||
template <typename... Args>
|
||||
void emplace_back(Args &&... args){};
|
||||
template <typename... Args>
|
||||
@ -116,7 +116,7 @@ public:
|
||||
template <typename... Args>
|
||||
void emplace_front(Args &&...args){};
|
||||
template <typename... Args>
|
||||
iterator emplace_after(const_iterator pos, Args &&...args){};
|
||||
iterator emplace_after(const_iterator pos, Args &&...args);
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
@ -131,7 +131,7 @@ public:
|
||||
template <typename... Args>
|
||||
void emplace(Args &&...args){};
|
||||
template <typename... Args>
|
||||
iterator emplace_hint(const_iterator pos, Args &&...args){};
|
||||
iterator emplace_hint(const_iterator pos, Args &&...args);
|
||||
};
|
||||
|
||||
template <typename Key, typename T>
|
||||
@ -146,7 +146,7 @@ public:
|
||||
template <typename... Args>
|
||||
void emplace(Args &&...args){};
|
||||
template <typename... Args>
|
||||
iterator emplace_hint(const_iterator pos, Args &&...args){};
|
||||
iterator emplace_hint(const_iterator pos, Args &&...args);
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
@ -161,7 +161,7 @@ public:
|
||||
template <typename... Args>
|
||||
void emplace(Args &&...args){};
|
||||
template <typename... Args>
|
||||
iterator emplace_hint(const_iterator pos, Args &&...args){};
|
||||
iterator emplace_hint(const_iterator pos, Args &&...args);
|
||||
};
|
||||
|
||||
template <typename Key, typename T>
|
||||
@ -176,7 +176,7 @@ public:
|
||||
template <typename... Args>
|
||||
void emplace(Args &&...args){};
|
||||
template <typename... Args>
|
||||
iterator emplace_hint(const_iterator pos, Args &&...args){};
|
||||
iterator emplace_hint(const_iterator pos, Args &&...args);
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
@ -191,7 +191,7 @@ public:
|
||||
template <typename... Args>
|
||||
void emplace(Args &&...args){};
|
||||
template <typename... Args>
|
||||
iterator emplace_hint(const_iterator pos, Args &&...args){};
|
||||
iterator emplace_hint(const_iterator pos, Args &&...args);
|
||||
};
|
||||
|
||||
template <typename Key, typename T>
|
||||
@ -206,7 +206,7 @@ public:
|
||||
template <typename... Args>
|
||||
void emplace(Args &&...args){};
|
||||
template <typename... Args>
|
||||
iterator emplace_hint(const_iterator pos, Args &&...args){};
|
||||
iterator emplace_hint(const_iterator pos, Args &&...args);
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
@ -221,7 +221,7 @@ public:
|
||||
template <typename... Args>
|
||||
void emplace(Args &&...args){};
|
||||
template <typename... Args>
|
||||
iterator emplace_hint(const_iterator pos, Args &&...args){};
|
||||
iterator emplace_hint(const_iterator pos, Args &&...args);
|
||||
};
|
||||
|
||||
template <typename Key, typename T>
|
||||
@ -236,7 +236,7 @@ public:
|
||||
template <typename... Args>
|
||||
void emplace(Args &&...args){};
|
||||
template <typename... Args>
|
||||
iterator emplace_hint(const_iterator pos, Args &&...args){};
|
||||
iterator emplace_hint(const_iterator pos, Args &&...args);
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
|
@ -1,6 +1,6 @@
|
||||
// RUN: %check_clang_tidy %s modernize-use-equals-default %t -- \
|
||||
// RUN: -config="{CheckOptions: {modernize-use-equals-default.IgnoreMacros: false}}" \
|
||||
// RUN: -- -fno-delayed-template-parsing -fexceptions
|
||||
// RUN: -- -fno-delayed-template-parsing -fexceptions -Wno-error=return-type
|
||||
|
||||
// Out of line definition.
|
||||
struct OL {
|
||||
|
@ -203,13 +203,13 @@ public:
|
||||
// CHECK-MESSAGES: :[[@LINE-2]]:16: warning: prefer using
|
||||
// CHECK-FIXES: {{^}} void j() const override
|
||||
|
||||
virtual MustUseResultObject k() {} // Has an implicit attribute.
|
||||
virtual MustUseResultObject k(); // Has an implicit attribute.
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:31: warning: prefer using
|
||||
// CHECK-FIXES: {{^}} MustUseResultObject k() override {}
|
||||
// CHECK-FIXES: {{^}} MustUseResultObject k() override;
|
||||
|
||||
virtual bool l() MUST_USE_RESULT UNUSED {}
|
||||
virtual bool l() MUST_USE_RESULT UNUSED;
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using
|
||||
// CHECK-FIXES: {{^}} bool l() override MUST_USE_RESULT UNUSED {}
|
||||
// CHECK-FIXES: {{^}} bool l() override MUST_USE_RESULT UNUSED;
|
||||
|
||||
virtual void r() &
|
||||
{}
|
||||
|
@ -100,7 +100,7 @@ std::string StrFormat_field_width_and_precision() {
|
||||
return s1 + s2 + s3 + s4 + s5 + s6;
|
||||
}
|
||||
|
||||
std::string StrFormat_macros() {
|
||||
void StrFormat_macros() {
|
||||
// The function call is replaced even though it comes from a macro.
|
||||
#define FORMAT absl::StrFormat
|
||||
auto s1 = FORMAT("Hello %d", 42);
|
||||
|
@ -106,9 +106,9 @@ extern "C" int d2(int arg);
|
||||
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(...) { }
|
||||
inline int d4(int arg) try { return 0; } catch(...) { return 0; }
|
||||
// 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(...) { }{{$}}
|
||||
// CHECK-FIXES: {{^}}inline auto d4(int arg) -> int try { return 0; } catch(...) { return 0; }{{$}}
|
||||
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;{{$}}
|
||||
@ -167,9 +167,9 @@ namespace N {
|
||||
}
|
||||
// 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() {}
|
||||
int N::e1() { return 0; }
|
||||
// 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 {}{{$}}
|
||||
// CHECK-FIXES: {{^}}auto N::e1() -> int { return 0; }{{$}}
|
||||
|
||||
//
|
||||
// Functions with unsupported return types
|
||||
@ -260,14 +260,14 @@ 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) {}
|
||||
virtual double base2(int, bool b) { return 0; }
|
||||
// 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 {}{{$}}
|
||||
// CHECK-FIXES: {{^}} virtual auto base2(int, bool b) -> double { return 0; }{{$}}
|
||||
|
||||
virtual float base3() const = 0;
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
|
||||
@ -298,9 +298,9 @@ struct B {
|
||||
// CHECK-FIXES: {{^}} virtual auto base9() const noexcept -> const char * { return ""; }{{$}}
|
||||
};
|
||||
|
||||
double B::base1(int, bool b) {}
|
||||
double B::base1(int, bool b) { return 0; }
|
||||
// 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 {}{{$}}
|
||||
// CHECK-FIXES: {{^}}auto B::base1(int, bool b) -> double { return 0; }{{$}}
|
||||
|
||||
struct D : B {
|
||||
virtual double f1(int, bool b) final;
|
||||
@ -311,9 +311,9 @@ struct D : 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 override;{{$}}
|
||||
|
||||
virtual float base3() const override final { }
|
||||
virtual float base3() const override final { return 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 override final { }{{$}}
|
||||
// CHECK-FIXES: {{^}} virtual auto base3() const -> float override final { return 0; }{{$}}
|
||||
|
||||
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]
|
||||
@ -586,13 +586,13 @@ 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 { }
|
||||
virtual auto base3() const -> float override final { return 0; }
|
||||
|
||||
operator double();
|
||||
};
|
||||
|
||||
auto l1 = [](int arg) {};
|
||||
auto l2 = [](int arg) -> double {};
|
||||
auto l2 = [](int arg) -> double { return 0; };
|
||||
|
@ -12,4 +12,4 @@ int f1(int n, ABC v1); // line 11
|
||||
|
||||
|
||||
|
||||
int f2( int n, const ABC& v2); // line 15
|
||||
void f2( int n, const ABC& v2); // line 15
|
||||
|
@ -12,4 +12,4 @@ int f1(int n, ABC v1); // line 11
|
||||
|
||||
|
||||
|
||||
int f2( int n, ABC v2); // line 15
|
||||
void f2( int n, ABC v2); // line 15
|
||||
|
@ -6,15 +6,15 @@ 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> &) {}
|
||||
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) {}
|
||||
std::string g(std::string);
|
||||
|
||||
int main() {
|
||||
std::string mystr1, mystr2;
|
||||
|
@ -14,7 +14,7 @@ int f1(int n, ABC v1, ABC v2) {
|
||||
// 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) {
|
||||
void f2(int n, ABC v2) {
|
||||
// CHECK-MESSAGES: [[@LINE-1]]:20: 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: void f2(int n, const ABC& v2) {
|
||||
}
|
||||
|
@ -4,4 +4,4 @@ void style_first_good();
|
||||
|
||||
void styleFirstBad();
|
||||
|
||||
int thisIsMainLikeIgnored(int argc, const char *argv[]) {}
|
||||
int thisIsMainLikeIgnored(int argc, const char *argv[]) { return 0; }
|
||||
|
@ -4,4 +4,4 @@ void STYLE_SECOND_GOOD();
|
||||
|
||||
void styleSecondBad();
|
||||
|
||||
int thisIsMainLikeNotIgnored(int argc, const char *argv[]) {}
|
||||
int thisIsMainLikeNotIgnored(int argc, const char *argv[]) { return 0; }
|
||||
|
@ -6,16 +6,16 @@
|
||||
|
||||
// Regression tests involving macros
|
||||
#define CONCAT(a, b) a##b
|
||||
CONCAT(cons, t) int p22(){}
|
||||
CONCAT(cons, t) int p22(){ return 0; }
|
||||
// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const int' is 'const'-qu
|
||||
// We warn, but we can't give a fix
|
||||
|
||||
#define CONSTINT const int
|
||||
CONSTINT p23() {}
|
||||
CONSTINT p23() { return 0; }
|
||||
// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const int' is 'const'-qu
|
||||
|
||||
#define CONST const
|
||||
CONST int p24() {}
|
||||
CONST int p24() { return 0; }
|
||||
// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const int' is 'const'-qu
|
||||
|
||||
#define CREATE_FUNCTION() \
|
||||
|
@ -1,4 +1,4 @@
|
||||
// RUN: %check_clang_tidy -std=c++14-or-later %s readability-const-return-type %t
|
||||
// RUN: %check_clang_tidy -std=c++14-or-later %s readability-const-return-type %t -- -- -Wno-error=return-type
|
||||
|
||||
// p# = positive test
|
||||
// n# = negative test
|
||||
|
@ -32,6 +32,7 @@ class A {
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: method 'call_static_member' can be made static
|
||||
// CHECK-FIXES: {{^}} static int call_static_member() {
|
||||
already_static();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int read_static() {
|
||||
|
@ -547,6 +547,7 @@ 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;
|
||||
return {};
|
||||
}
|
||||
|
||||
using my_struct_type = THIS___Structure;
|
||||
@ -777,8 +778,8 @@ STATIC_MACRO void someFunc(ValueType a_v1, const ValueType& a_v2) {}
|
||||
// CHECK-FIXES: {{^}}STATIC_MACRO void someFunc(value_type_t a_v1, const value_type_t& a_v2) {}
|
||||
STATIC_MACRO void someFunc(const ValueType** p_a_v1, ValueType (*p_a_v2)()) {}
|
||||
// CHECK-FIXES: {{^}}STATIC_MACRO void someFunc(const value_type_t** p_a_v1, value_type_t (*p_a_v2)()) {}
|
||||
STATIC_MACRO ValueType someFunc() {}
|
||||
// CHECK-FIXES: {{^}}STATIC_MACRO value_type_t someFunc() {}
|
||||
STATIC_MACRO ValueType someFunc() { return {}; }
|
||||
// CHECK-FIXES: {{^}}STATIC_MACRO value_type_t someFunc() { return {}; }
|
||||
STATIC_MACRO void someFunc(MyFunPtr, const MyFunPtr****) {}
|
||||
// CHECK-FIXES: {{^}}STATIC_MACRO void someFunc(my_fun_ptr_t, const my_fun_ptr_t****) {}
|
||||
#undef STATIC_MACRO
|
||||
|
@ -465,7 +465,7 @@ struct S {
|
||||
// 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) {
|
||||
void f(S& s) {
|
||||
functionTaking<bool>(s.a);
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'int' -> 'bool'
|
||||
// CHECK-FIXES: functionTaking<bool>(s.a != 0);
|
||||
|
@ -37,8 +37,8 @@ void operator delete[](void *x) throw();
|
||||
void operator delete[](void * /*x*/) throw();
|
||||
|
||||
struct X {
|
||||
X operator++(int) {}
|
||||
X operator--(int) {}
|
||||
X operator++(int) { throw 0; }
|
||||
X operator--(int) { throw 0; }
|
||||
|
||||
X(X&) = delete;
|
||||
X &operator=(X&) = default;
|
||||
@ -86,22 +86,23 @@ void FDef2(int n, int) {}
|
||||
void FNoDef(int);
|
||||
|
||||
class Z {};
|
||||
Z the_z;
|
||||
|
||||
Z &operator++(Z&) {}
|
||||
Z &operator++(Z&) { return the_z; }
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: all parameters should be named in a function
|
||||
// CHECK-FIXES: Z &operator++(Z& /*unused*/) {}
|
||||
// CHECK-FIXES: Z &operator++(Z& /*unused*/) { return the_z; }
|
||||
|
||||
Z &operator++(Z&, int) {}
|
||||
Z &operator++(Z&, int) { return the_z; }
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: all parameters should be named in a function
|
||||
// CHECK-FIXES: Z &operator++(Z& /*unused*/, int) {}
|
||||
// CHECK-FIXES: Z &operator++(Z& /*unused*/, int) { return the_z; }
|
||||
|
||||
Z &operator--(Z&) {}
|
||||
Z &operator--(Z&) { return the_z; }
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: all parameters should be named in a function
|
||||
// CHECK-FIXES: Z &operator--(Z& /*unused*/) {}
|
||||
// CHECK-FIXES: Z &operator--(Z& /*unused*/) { return the_z; }
|
||||
|
||||
Z &operator--(Z&, int) {}
|
||||
Z &operator--(Z&, int) { return the_z; }
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: all parameters should be named in a function
|
||||
// CHECK-FIXES: Z &operator--(Z& /*unused*/, int) {}
|
||||
// CHECK-FIXES: Z &operator--(Z& /*unused*/, int) { return the_z; }
|
||||
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
|
@ -20,7 +20,7 @@ static int f(void);
|
||||
static int f(void); // f
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: redundant 'f' declaration
|
||||
// CHECK-FIXES: {{^}}// f{{$}}
|
||||
static int f(void) {}
|
||||
static int f(void) { return 0; }
|
||||
|
||||
inline void g(void) {}
|
||||
|
||||
|
@ -38,7 +38,7 @@ static int f();
|
||||
static int f(); // f
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: redundant 'f' declaration
|
||||
// CHECK-FIXES: {{^}}// f{{$}}
|
||||
static int f() {}
|
||||
static int f() { return 0; }
|
||||
|
||||
// Original check crashed for the code below.
|
||||
namespace std {
|
||||
|
@ -264,7 +264,7 @@ struct Qptr {
|
||||
}
|
||||
};
|
||||
|
||||
int func(Qptr qp) {
|
||||
void func(Qptr qp) {
|
||||
qp->y = 10;
|
||||
qp->K = 10;
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member accessed through instance [readability-static-accessed-through-instance]
|
||||
|
@ -382,7 +382,7 @@ enum opcode { Foo,
|
||||
Bar };
|
||||
static value *SimplifyRightShift(
|
||||
opcode Opcode, value *Op0, value *Op1, bool isExact,
|
||||
const type1 &Q, unsigned MaxRecurse) {}
|
||||
const type1 &Q, unsigned MaxRecurse) { return nullptr; }
|
||||
static value *SimplifyLShrInst(value *Op0, value *Op1, bool isExact,
|
||||
const type1 &Q, unsigned MaxRecurse) {
|
||||
if (value *V = SimplifyRightShift(Foo, Op0, Op1, isExact, Q, MaxRecurse))
|
||||
|
@ -31,7 +31,7 @@ private:
|
||||
// CHECK-FIXES: _num2{};
|
||||
};
|
||||
|
||||
int should_use_emplace(std::vector<Foo> &v) {
|
||||
void should_use_emplace(std::vector<Foo> &v) {
|
||||
v.push_back(Foo());
|
||||
// CHECK-FIXES: v.emplace_back();
|
||||
// CHECK-MESSAGES: warning: use emplace_back instead of push_back [hicpp-use-emplace,modernize-use-emplace]
|
||||
|
@ -16,7 +16,7 @@ typedef struct {
|
||||
void simple_hfa(HFA h) {}
|
||||
|
||||
// CHECK: define{{.*}} %struct.HFA @return_simple_hfa
|
||||
HFA return_simple_hfa() {}
|
||||
HFA return_simple_hfa() { return (HFA){0}; }
|
||||
|
||||
typedef struct {
|
||||
double arr[4];
|
||||
@ -43,7 +43,7 @@ typedef struct {
|
||||
void big_struct_indirect(BigStruct b) {}
|
||||
|
||||
// CHECK: define{{.*}} void @return_big_struct_indirect(ptr dead_on_unwind noalias writable sret
|
||||
BigStruct return_big_struct_indirect() {}
|
||||
BigStruct return_big_struct_indirect() { return (BigStruct){0}; }
|
||||
|
||||
// Structs smaller than 16 bytes should be passed directly, and coerced to
|
||||
// either [N x i32] or [N x i64] depending on alignment requirements.
|
||||
@ -58,7 +58,7 @@ typedef struct {
|
||||
void small_struct_direct(SmallStruct s) {}
|
||||
|
||||
// CHECK: define{{.*}} [4 x i32] @return_small_struct_direct()
|
||||
SmallStruct return_small_struct_direct() {}
|
||||
SmallStruct return_small_struct_direct() { return (SmallStruct){0}; }
|
||||
|
||||
typedef struct {
|
||||
float x;
|
||||
@ -75,14 +75,14 @@ typedef struct {
|
||||
} PaddedSmallStruct;
|
||||
|
||||
// CHECK: define{{.*}} i32 @return_padded_small_struct()
|
||||
PaddedSmallStruct return_padded_small_struct() {}
|
||||
PaddedSmallStruct return_padded_small_struct() { return (PaddedSmallStruct){0}; }
|
||||
|
||||
typedef struct {
|
||||
char arr[7];
|
||||
} OddlySizedStruct;
|
||||
|
||||
// CHECK: define{{.*}} [2 x i32] @return_oddly_sized_struct()
|
||||
OddlySizedStruct return_oddly_sized_struct() {}
|
||||
OddlySizedStruct return_oddly_sized_struct() { return (OddlySizedStruct){0}; }
|
||||
|
||||
// CHECK: define{{.*}} <4 x float> @test_va_arg_vec(ptr noundef %l)
|
||||
|
||||
|
@ -36,7 +36,7 @@ typedef enum memory_scope {
|
||||
// GFX90A-CAS: atomicrmw fadd ptr addrspace(1) {{.*}} syncscope("agent-one-as") monotonic
|
||||
// GFX90A-CAS: atomicrmw fadd ptr addrspace(1) {{.*}} syncscope("one-as") monotonic
|
||||
// GFX90A-CAS: atomicrmw fadd ptr addrspace(1) {{.*}} syncscope("wavefront-one-as") monotonic
|
||||
float atomic_cas(__global atomic_float *d, float a) {
|
||||
void atomic_cas(__global atomic_float *d, float a) {
|
||||
float ret1 = __opencl_atomic_fetch_add(d, a, memory_order_relaxed, memory_scope_work_group);
|
||||
float ret2 = __opencl_atomic_fetch_add(d, a, memory_order_relaxed, memory_scope_device);
|
||||
float ret3 = __opencl_atomic_fetch_add(d, a, memory_order_relaxed, memory_scope_all_svm_devices);
|
||||
|
@ -11,6 +11,7 @@ void *ThreadFn(void *) {
|
||||
__hwasan_enable_allocator_tagging();
|
||||
// This will trigger memory deallocation in __strerror_thread_freeres,
|
||||
// at a point when HwasanThread is already gone.
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
@ -2,10 +2,10 @@
|
||||
// UNSUPPORTED: target=thumb{{.*}}
|
||||
// UNSUPPORTED: android
|
||||
|
||||
// RUN: %clangxx -fsanitize=return %gmlt -O2 -fno-omit-frame-pointer -fasynchronous-unwind-tables %s -o %t
|
||||
// RUN: %clangxx -Wno-error=return-type -fsanitize=return %gmlt -O2 -fno-omit-frame-pointer -fasynchronous-unwind-tables %s -o %t
|
||||
// RUN: %env_ubsan_opts=print_stacktrace=1:fast_unwind_on_fatal=0 not %run %t 2>&1 | FileCheck %s
|
||||
// RUN: %env_ubsan_opts=print_stacktrace=1:fast_unwind_on_fatal=1 not %run %t 2>&1 | FileCheck %s
|
||||
// RUN: %clangxx -fsanitize=return %gmlt -O2 -fno-omit-frame-pointer -fno-exceptions -fno-asynchronous-unwind-tables %s -o %t
|
||||
// RUN: %clangxx -Wno-error=return-type -fsanitize=return %gmlt -O2 -fno-omit-frame-pointer -fno-exceptions -fno-asynchronous-unwind-tables %s -o %t
|
||||
// RUN: %env_ubsan_opts=print_stacktrace=1:fast_unwind_on_fatal=0 not %run %t 2>&1 | FileCheck %s
|
||||
// RUN: %env_ubsan_opts=print_stacktrace=1:fast_unwind_on_fatal=1 not %run %t 2>&1 | FileCheck %s
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
// RUN: %clangxx -fsanitize=return %gmlt %s -O3 -o %t
|
||||
// RUN: %clangxx -Wno-error=return-type -fsanitize=return %gmlt %s -O3 -o %t
|
||||
// RUN: not %run %t 2>&1 | FileCheck %s
|
||||
// RUN: %env_ubsan_opts=print_stacktrace=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-STACKTRACE
|
||||
// Error message does not exact what expected
|
||||
|
Loading…
x
Reference in New Issue
Block a user