Skip to content

[Clang] [NFC] Fix more -Wreturn-type warnings in tests everywhere #123470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clang-tools-extra/clangd/unittests/ASTTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ TEST(ClangdAST, GetContainedAutoParamType) {
auto &&d,
auto *&e,
auto (*f)(int)
){};
){ return 0; };

int withoutAuto(
int a,
Expand All @@ -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();
Expand Down
6 changes: 4 additions & 2 deletions clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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()),
Expand Down Expand Up @@ -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>();
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/unittests/QualityTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ TEST(QualityTests, SymbolRelevanceSignalExtraction) {

using flags::FLAGS_FOO;

int ::header_main() {}
int ::header_main() { return 0; }
int main();

[[deprecated]]
Expand Down
10 changes: 5 additions & 5 deletions clang-tools-extra/clangd/unittests/RenameTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -225,7 +225,7 @@ TEST(RenameTest, WithinFileRename) {
template<typename T>
class Foo {
public:
T [[f^oo]]() {}
T [[f^oo]]() { return T(); }
};

void bar() {
Expand Down Expand Up @@ -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]];

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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]]();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 5 additions & 4 deletions clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions clang-tools-extra/clangd/unittests/SymbolInfoTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ TEST(SymbolInfoTests, All) {
void $decl[[foo]]();
int bar() {
fo^o();
return 0;
}
)cpp",
{ExpectedSymbolDetails{"foo", "", "c:@F@foo#", "decl"}}},
Expand All @@ -44,6 +45,7 @@ TEST(SymbolInfoTests, All) {
void $def[[foo]]() {}
int bar() {
fo^o();
return 0;
}
)cpp",
{ExpectedSymbolDetails{"foo", "", "c:@F@foo#", "def", "def"}}},
Expand All @@ -53,6 +55,7 @@ TEST(SymbolInfoTests, All) {
void $def[[foo]]() {}
int bar() {
fo^o();
return 0;
}
)cpp",
{ExpectedSymbolDetails{"foo", "", "c:@F@foo#", "decl", "def"}}},
Expand Down Expand Up @@ -83,6 +86,7 @@ TEST(SymbolInfoTests, All) {
void $decl[[foo]]();
int baz() {
fo^o();
return 0;
}
}
)cpp",
Expand All @@ -96,6 +100,7 @@ TEST(SymbolInfoTests, All) {
namespace barbar {
int baz() {
bar::fo^o();
return 0;
}
}
)cpp",
Expand All @@ -108,6 +113,7 @@ TEST(SymbolInfoTests, All) {
namespace Nbaz {
int baz() {
::fo^o();
return 0;
}
}
}
Expand All @@ -121,6 +127,7 @@ TEST(SymbolInfoTests, All) {
namespace barbar {
int baz() {
fo^o();
return 0;
}
}
)cpp",
Expand All @@ -136,6 +143,7 @@ TEST(SymbolInfoTests, All) {
int baz() {
bar::BarType b;
fo^o(b);
return 0;
}
}
)cpp",
Expand Down
14 changes: 8 additions & 6 deletions clang-tools-extra/clangd/unittests/XRefsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]];
Expand Down Expand Up @@ -2025,7 +2025,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);
Expand All @@ -2045,7 +2045,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]]();
Expand Down Expand Up @@ -2143,7 +2143,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(
Expand Down Expand Up @@ -2353,6 +2353,7 @@ TEST(FindReferences, ExplicitSymbols) {
X $def(test)[[a]];
$(test)[[a]].operator bool();
if ($(test)[[a^]]) {} // ignore implicit conversion-operator AST node
return 0;
}
)cpp",
};
Expand Down Expand Up @@ -2388,7 +2389,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 {
Expand All @@ -2405,7 +2406,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"
Expand Down Expand Up @@ -2480,6 +2481,7 @@ TEST(FindReferences, NeedsIndexForMacro) {
Annotations IndexedMain(R"cpp(
int indexed_main() {
int a = [[MACRO]](1);
return 0;
}
)cpp");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{}; }");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ TEST_F(ExtractVariableTest, Test) {
struct T {
int bar(int a = [[1]]) {
int b = [[z]];
return 0;
}
int z = [[1]];
} t;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ int throwsAndCallsRethrower() noexcept {
} catch(...) {
rethrower();
}
return 1;
}

int throwsAndCallsCallsRethrower() noexcept {
Expand All @@ -29,6 +30,7 @@ int throwsAndCallsCallsRethrower() noexcept {
} catch(...) {
callsRethrower();
}
return 1;
}

void rethrowerNoexcept() noexcept {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading