Skip to content

Commit b0210fe

Browse files
authored
[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.
1 parent 6e7da07 commit b0210fe

File tree

64 files changed

+202
-164
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+202
-164
lines changed

clang-tools-extra/clangd/unittests/ASTTests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ TEST(ClangdAST, GetContainedAutoParamType) {
329329
auto &&d,
330330
auto *&e,
331331
auto (*f)(int)
332-
){};
332+
){ return 0; };
333333
334334
int withoutAuto(
335335
int a,
@@ -338,7 +338,7 @@ TEST(ClangdAST, GetContainedAutoParamType) {
338338
int &&d,
339339
int *&e,
340340
int (*f)(int)
341-
){};
341+
){ return 0; };
342342
)cpp");
343343
TU.ExtraArgs.push_back("-std=c++20");
344344
auto AST = TU.build();

clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ TEST(WorkspaceSymbols, Unnamed) {
113113
TEST(WorkspaceSymbols, InMainFile) {
114114
TestTU TU;
115115
TU.Code = R"cpp(
116-
int test() {}
116+
int test() { return 0; }
117117
static void test2() {}
118118
)cpp";
119119
EXPECT_THAT(getSymbols(TU, "test"),
@@ -537,12 +537,14 @@ TEST(DocumentSymbols, InHeaderFile) {
537537
TestTU TU;
538538
TU.AdditionalFiles["bar.h"] = R"cpp(
539539
int foo() {
540+
return 0;
540541
}
541542
)cpp";
542543
TU.Code = R"cpp(
543544
int i; // declaration to finish preamble
544545
#include "bar.h"
545546
int test() {
547+
return 0;
546548
}
547549
)cpp";
548550
EXPECT_THAT(getSymbols(TU.build()),
@@ -780,7 +782,7 @@ TEST(DocumentSymbols, FuncTemplates) {
780782
TestTU TU;
781783
Annotations Source(R"cpp(
782784
template <class T>
783-
T foo() {}
785+
T foo() { return T{}; }
784786
785787
auto x = foo<int>();
786788
auto y = foo<double>();

clang-tools-extra/clangd/unittests/ParsedASTTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ TEST(ParsedASTTest, NoCrashOnTokensWithTidyCheck) {
251251
// this check runs the preprocessor, we need to make sure it does not break
252252
// our recording logic.
253253
TU.ClangTidyProvider = addTidyChecks("modernize-use-trailing-return-type");
254-
TU.Code = "inline int foo() {}";
254+
TU.Code = "inline int foo() { return 0; }";
255255

256256
auto AST = TU.build();
257257
const syntax::TokenBuffer &T = AST.getTokens();

clang-tools-extra/clangd/unittests/QualityTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ TEST(QualityTests, SymbolRelevanceSignalExtraction) {
108108
109109
using flags::FLAGS_FOO;
110110
111-
int ::header_main() {}
111+
int ::header_main() { return 0; }
112112
int main();
113113
114114
[[deprecated]]

clang-tools-extra/clangd/unittests/RenameTests.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ TEST(RenameTest, WithinFileRename) {
214214
template<typename T>
215215
class Foo {
216216
public:
217-
static T [[f^oo]]() {}
217+
static T [[f^oo]]() { return T(); }
218218
};
219219
220220
void bar() {
@@ -225,7 +225,7 @@ TEST(RenameTest, WithinFileRename) {
225225
template<typename T>
226226
class Foo {
227227
public:
228-
T [[f^oo]]() {}
228+
T [[f^oo]]() { return T(); }
229229
};
230230
231231
void bar() {
@@ -827,7 +827,7 @@ TEST(RenameTest, WithinFileRename) {
827827

828828
// Issue 170: Rename symbol introduced by UsingDecl
829829
R"cpp(
830-
namespace ns { void [[f^oo]](); }
830+
namespace ns { void [[f^oo]](); }
831831
832832
using ns::[[f^oo]];
833833
@@ -1307,7 +1307,7 @@ TEST(RenameTest, Renameable) {
13071307
"no symbol", false},
13081308

13091309
{R"cpp(// FIXME we probably want to rename both overloads here,
1310-
// but renaming currently assumes there's only a
1310+
// but renaming currently assumes there's only a
13111311
// single canonical declaration.
13121312
namespace ns { int foo(int); char foo(char); }
13131313
using ns::^foo;
@@ -1776,7 +1776,7 @@ TEST(CrossFileRenameTests, WithUpToDateIndex) {
17761776
void [[foo]]() override {};
17771777
};
17781778
1779-
void func(Base* b, Derived1* d1,
1779+
void func(Base* b, Derived1* d1,
17801780
Derived2* d2, NotDerived* nd) {
17811781
b->[[foo]]();
17821782
d1->[[foo]]();

clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,7 @@ sizeof...($TemplateParameter[[Elements]]);
741741
$Class[[Foo]].$Field_static[[sharedInstance]].$Field[[someProperty]] $Operator[[=]] 1;
742742
self.$Field[[someProperty]] $Operator[[=]] self.$Field[[someProperty]] $Operator[[+]] self.$Field[[otherMethod]] $Operator[[+]] 1;
743743
self->$Field[[_someProperty]] $Operator[[=]] $Field[[_someProperty]] $Operator[[+]] 1;
744+
return 0;
744745
}
745746
@end
746747
)cpp",

clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ TEST(FoldingRanges, ASTAll) {
201201
R"cpp(
202202
#define FOO int foo() {\
203203
int Variable = 42; \
204+
return 0; \
204205
}
205206
206207
// Do not generate folding range for braces within macro expansion.
@@ -336,18 +337,18 @@ TEST(FoldingRanges, PseudoParserWithoutLineFoldings) {
336337
]]};
337338
)cpp",
338339
R"cpp(
339-
/*[[ Multi
340+
/*[[ Multi
340341
* line
341-
* comment
342+
* comment
342343
]]*/
343344
)cpp",
344345
R"cpp(
345346
//[[ Comment
346347
// 1]]
347-
348+
348349
//[[ Comment
349350
// 2]]
350-
351+
351352
// No folding for single line comment.
352353
353354
/*[[ comment 3

clang-tools-extra/clangd/unittests/SymbolInfoTests.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ TEST(SymbolInfoTests, All) {
3636
void $decl[[foo]]();
3737
int bar() {
3838
fo^o();
39+
return 0;
3940
}
4041
)cpp",
4142
{ExpectedSymbolDetails{"foo", "", "c:@F@foo#", "decl"}}},
@@ -44,6 +45,7 @@ TEST(SymbolInfoTests, All) {
4445
void $def[[foo]]() {}
4546
int bar() {
4647
fo^o();
48+
return 0;
4749
}
4850
)cpp",
4951
{ExpectedSymbolDetails{"foo", "", "c:@F@foo#", "def", "def"}}},
@@ -53,6 +55,7 @@ TEST(SymbolInfoTests, All) {
5355
void $def[[foo]]() {}
5456
int bar() {
5557
fo^o();
58+
return 0;
5659
}
5760
)cpp",
5861
{ExpectedSymbolDetails{"foo", "", "c:@F@foo#", "decl", "def"}}},
@@ -83,6 +86,7 @@ TEST(SymbolInfoTests, All) {
8386
void $decl[[foo]]();
8487
int baz() {
8588
fo^o();
89+
return 0;
8690
}
8791
}
8892
)cpp",
@@ -96,6 +100,7 @@ TEST(SymbolInfoTests, All) {
96100
namespace barbar {
97101
int baz() {
98102
bar::fo^o();
103+
return 0;
99104
}
100105
}
101106
)cpp",
@@ -108,6 +113,7 @@ TEST(SymbolInfoTests, All) {
108113
namespace Nbaz {
109114
int baz() {
110115
::fo^o();
116+
return 0;
111117
}
112118
}
113119
}
@@ -121,6 +127,7 @@ TEST(SymbolInfoTests, All) {
121127
namespace barbar {
122128
int baz() {
123129
fo^o();
130+
return 0;
124131
}
125132
}
126133
)cpp",
@@ -136,6 +143,7 @@ TEST(SymbolInfoTests, All) {
136143
int baz() {
137144
bar::BarType b;
138145
fo^o(b);
146+
return 0;
139147
}
140148
}
141149
)cpp",

clang-tools-extra/clangd/unittests/XRefsTests.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ TEST(HighlightsTest, All) {
9595
)cpp",
9696

9797
R"cpp(// Function
98-
int [[^foo]](int) {}
98+
int [[^foo]](int) { return 0; }
9999
int main() {
100100
[[foo]]([[foo]](42));
101101
auto *X = &[[foo]];
@@ -2140,7 +2140,7 @@ TEST(FindReferences, WithinAST) {
21402140
)cpp",
21412141

21422142
R"cpp(// Function
2143-
int $def[[foo]](int) {}
2143+
int $def[[foo]](int) { return 0; }
21442144
int main() {
21452145
auto *X = &$(main)[[^foo]];
21462146
$(main)[[foo]](42);
@@ -2160,7 +2160,7 @@ TEST(FindReferences, WithinAST) {
21602160

21612161
R"cpp(// Method call
21622162
struct Foo { int $decl(Foo)[[foo]](); };
2163-
int Foo::$def(Foo)[[foo]]() {}
2163+
int Foo::$def(Foo)[[foo]]() { return 0; }
21642164
int main() {
21652165
Foo f;
21662166
f.$(main)[[^foo]]();
@@ -2258,7 +2258,7 @@ TEST(FindReferences, WithinAST) {
22582258
)cpp",
22592259
R"cpp(// Dependent code
22602260
template <typename T> void $decl[[foo]](T t);
2261-
template <typename T> void bar(T t) { $(bar)[[foo]](t); } // foo in bar is uninstantiated.
2261+
template <typename T> void bar(T t) { $(bar)[[foo]](t); } // foo in bar is uninstantiated.
22622262
void baz(int x) { $(baz)[[f^oo]](x); }
22632263
)cpp",
22642264
R"cpp(
@@ -2508,6 +2508,7 @@ TEST(FindReferences, ExplicitSymbols) {
25082508
X $def(test)[[a]];
25092509
$(test)[[a]].operator bool();
25102510
if ($(test)[[a^]]) {} // ignore implicit conversion-operator AST node
2511+
return 0;
25112512
}
25122513
)cpp",
25132514
};
@@ -2543,7 +2544,7 @@ TEST(FindReferences, UsedSymbolsFromInclude) {
25432544
#define BAR 5
25442545
int bar1();
25452546
int bar2();
2546-
class Bar {};
2547+
class Bar {};
25472548
)cpp");
25482549
TU.AdditionalFiles["system/vector"] = guard(R"cpp(
25492550
namespace std {
@@ -2560,7 +2561,7 @@ TEST(FindReferences, UsedSymbolsFromInclude) {
25602561
std::vector<Matcher<ReferencesResult::Reference>> ExpectedLocations;
25612562
for (const auto &R : T.ranges())
25622563
ExpectedLocations.push_back(AllOf(rangeIs(R), attrsAre(0u)));
2563-
for (const auto &P : T.points())
2564+
for (const auto &P : T.points())
25642565
EXPECT_THAT(findReferences(AST, P, 0).References,
25652566
UnorderedElementsAreArray(ExpectedLocations))
25662567
<< "Failed for Refs at " << P << "\n"
@@ -2635,6 +2636,7 @@ TEST(FindReferences, NeedsIndexForMacro) {
26352636
Annotations IndexedMain(R"cpp(
26362637
int indexed_main() {
26372638
int a = [[MACRO]](1);
2639+
return 0;
26382640
}
26392641
)cpp");
26402642

clang-tools-extra/clangd/unittests/tweaks/DefineInlineTests.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -935,10 +935,11 @@ TEST_F(DefineInlineTest, AddInline) {
935935
// Check we put inline before cv-qualifiers.
936936
ExtraFiles["a.h"] = "const int foo();";
937937
apply(R"cpp(#include "a.h"
938-
const int fo^o() {})cpp",
938+
const int fo^o() { return 0; })cpp",
939939
&EditedFiles);
940-
EXPECT_THAT(EditedFiles, testing::ElementsAre(FileWithContents(
941-
testPath("a.h"), "inline const int foo(){}")));
940+
EXPECT_THAT(EditedFiles,
941+
testing::ElementsAre(FileWithContents(
942+
testPath("a.h"), "inline const int foo(){ return 0; }")));
942943

943944
// No double inline.
944945
ExtraFiles["a.h"] = "inline void foo();";

clang-tools-extra/clangd/unittests/tweaks/ExpandDeducedTypeTests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ TEST_F(ExpandDeducedTypeTest, Test) {
6969
EXPECT_THAT(apply(R"cpp(au^to s = &"foobar";)cpp"),
7070
StartsWith("fail: Could not expand type"));
7171

72-
EXPECT_EQ(apply("ns::Class * foo() { au^to c = foo(); }"),
73-
"ns::Class * foo() { ns::Class * c = foo(); }");
72+
EXPECT_EQ(apply("ns::Class * foo() { au^to c = foo(); return nullptr; }"),
73+
"ns::Class * foo() { ns::Class * c = foo(); return nullptr; }");
7474
EXPECT_EQ(
7575
apply("void ns::Func() { au^to x = new ns::Class::Nested{}; }"),
7676
"void ns::Func() { ns::Class::Nested * x = new ns::Class::Nested{}; }");

clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ TEST_F(ExtractVariableTest, Test) {
116116
struct T {
117117
int bar(int a = [[1]]) {
118118
int b = [[z]];
119+
return 0;
119120
}
120121
int z = [[1]];
121122
} t;

clang-tools-extra/test/clang-tidy/checkers/abseil/Inputs/absl/strings/internal-file.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ std::string StringsFunction(std::string s1) { return s1; }
1010
class SomeContainer {};
1111
namespace strings_internal {
1212
void InternalFunction() {}
13-
template <class P> P InternalTemplateFunction(P a) {}
13+
template <class P> void InternalTemplateFunction(P a) { int; }
1414
} // namespace strings_internal
1515

1616
namespace container_internal {

clang-tools-extra/test/clang-tidy/checkers/boost/use-to-string.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ T lexical_cast(const V &) {
1818

1919
struct my_weird_type {};
2020

21-
std::string fun(const std::string &) {}
21+
std::string fun(const std::string &) { return {}; }
2222

2323
void test_to_string1() {
2424

@@ -75,7 +75,7 @@ void test_to_string2() {
7575
fun(boost::lexical_cast<std::string>(j));
7676
}
7777

78-
std::string fun(const std::wstring &) {}
78+
std::string fun(const std::wstring &);
7979

8080
void test_to_wstring() {
8181
int a;

clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape-coro.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %check_clang_tidy -std=c++20 %s bugprone-exception-escape %t -- \
2-
// RUN: -- -fexceptions
2+
// RUN: -- -fexceptions -Wno-error=return-type
33

44
namespace std {
55

clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape-rethrow.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ int throwsAndCallsRethrower() noexcept {
2020
} catch(...) {
2121
rethrower();
2222
}
23+
return 1;
2324
}
2425

2526
int throwsAndCallsCallsRethrower() noexcept {
@@ -29,6 +30,7 @@ int throwsAndCallsCallsRethrower() noexcept {
2930
} catch(...) {
3031
callsRethrower();
3132
}
33+
return 1;
3234
}
3335

3436
void rethrowerNoexcept() noexcept {

clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,7 @@ int indirectly_recursive(int n) noexcept;
665665

666666
int recursion_helper(int n) {
667667
indirectly_recursive(n);
668+
return 0;
668669
}
669670

670671
int indirectly_recursive(int n) noexcept {

0 commit comments

Comments
 (0)