Skip to content

Commit fc5de0a

Browse files
authored
[clang-tools-extra] Use {} instead of std::nullopt to initialize empty ArrayRef (#109400)
Follow up to #109133.
1 parent f5a65d8 commit fc5de0a

8 files changed

+67
-76
lines changed

clang-tools-extra/clang-query/Query.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ bool MatchQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const {
146146
TD.emitDiagnostic(
147147
FullSourceLoc(R.getBegin(), AST->getSourceManager()),
148148
DiagnosticsEngine::Note, "\"" + BI->first + "\" binds here",
149-
CharSourceRange::getTokenRange(R), std::nullopt);
149+
CharSourceRange::getTokenRange(R), {});
150150
}
151151
}
152152
if (QS.PrintOutput) {

clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ template <typename... CheckTypes>
8686
std::string
8787
runCheckOnCode(StringRef Code, std::vector<ClangTidyError> *Errors = nullptr,
8888
const Twine &Filename = "input.cc",
89-
ArrayRef<std::string> ExtraArgs = std::nullopt,
89+
ArrayRef<std::string> ExtraArgs = {},
9090
const ClangTidyOptions &ExtraOptions = ClangTidyOptions(),
9191
std::map<StringRef, StringRef> PathsToContent =
9292
std::map<StringRef, StringRef>()) {

clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ TEST(IncludeCleanerCheckTest, BasicUnusedIncludes) {
4949
std::vector<ClangTidyError> Errors;
5050
EXPECT_EQ(PostCode,
5151
runCheckOnCode<IncludeCleanerCheck>(
52-
PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
52+
PreCode, &Errors, "file.cpp", {}, ClangTidyOptions(),
5353
{{"bar.h", "#pragma once"}, {"vector", "#pragma once"}}));
5454
}
5555

@@ -78,7 +78,7 @@ TEST(IncludeCleanerCheckTest, SuppressUnusedIncludes) {
7878
EXPECT_EQ(
7979
PostCode,
8080
runCheckOnCode<IncludeCleanerCheck>(
81-
PreCode, &Errors, "file.cpp", std::nullopt, Opts,
81+
PreCode, &Errors, "file.cpp", {}, Opts,
8282
{{"bar.h", "#pragma once"},
8383
{"vector", "#pragma once"},
8484
{"list", "#pragma once"},
@@ -103,14 +103,13 @@ int BazResult = baz();
103103
)";
104104

105105
std::vector<ClangTidyError> Errors;
106-
EXPECT_EQ(PostCode,
107-
runCheckOnCode<IncludeCleanerCheck>(
108-
PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
109-
{{"bar.h", R"(#pragma once
106+
EXPECT_EQ(PostCode, runCheckOnCode<IncludeCleanerCheck>(
107+
PreCode, &Errors, "file.cpp", {}, ClangTidyOptions(),
108+
{{"bar.h", R"(#pragma once
110109
#include "baz.h"
111110
int bar();
112111
)"},
113-
{"baz.h", R"(#pragma once
112+
{"baz.h", R"(#pragma once
114113
int baz();
115114
)"}}));
116115
}
@@ -124,8 +123,8 @@ int BarResult2 = $diag2^bar();)");
124123

125124
{
126125
std::vector<ClangTidyError> Errors;
127-
runCheckOnCode<IncludeCleanerCheck>(Code.code(), &Errors, "file.cpp",
128-
std::nullopt, ClangTidyOptions(),
126+
runCheckOnCode<IncludeCleanerCheck>(Code.code(), &Errors, "file.cpp", {},
127+
ClangTidyOptions(),
129128
{{"baz.h", R"(#pragma once
130129
#include "bar.h"
131130
)"},
@@ -141,8 +140,8 @@ int BarResult2 = $diag2^bar();)");
141140
std::vector<ClangTidyError> Errors;
142141
ClangTidyOptions Opts;
143142
Opts.CheckOptions.insert({"DeduplicateFindings", "false"});
144-
runCheckOnCode<IncludeCleanerCheck>(Code.code(), &Errors, "file.cpp",
145-
std::nullopt, Opts,
143+
runCheckOnCode<IncludeCleanerCheck>(Code.code(), &Errors, "file.cpp", {},
144+
Opts,
146145
{{"baz.h", R"(#pragma once
147146
#include "bar.h"
148147
)"},
@@ -176,7 +175,7 @@ std::vector x;
176175
llvm::Regex::escape(appendPathFileSystemIndependent({"foo", "qux.h"}))};
177176
std::vector<ClangTidyError> Errors;
178177
EXPECT_EQ(PreCode, runCheckOnCode<IncludeCleanerCheck>(
179-
PreCode, &Errors, "file.cpp", std::nullopt, Opts,
178+
PreCode, &Errors, "file.cpp", {}, Opts,
180179
{{"bar.h", R"(#pragma once
181180
#include "baz.h"
182181
#include "foo/qux.h"
@@ -215,14 +214,13 @@ int BazResult_1 = baz_1();
215214
)";
216215

217216
std::vector<ClangTidyError> Errors;
218-
EXPECT_EQ(PostCode,
219-
runCheckOnCode<IncludeCleanerCheck>(
220-
PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
221-
{{"bar.h", R"(#pragma once
217+
EXPECT_EQ(PostCode, runCheckOnCode<IncludeCleanerCheck>(
218+
PreCode, &Errors, "file.cpp", {}, ClangTidyOptions(),
219+
{{"bar.h", R"(#pragma once
222220
#include "baz.h"
223221
int bar();
224222
)"},
225-
{"baz.h", R"(#pragma once
223+
{"baz.h", R"(#pragma once
226224
int baz_0();
227225
int baz_1();
228226
)"}}));
@@ -244,13 +242,12 @@ std::vector Vec;
244242
)";
245243

246244
std::vector<ClangTidyError> Errors;
247-
EXPECT_EQ(PostCode,
248-
runCheckOnCode<IncludeCleanerCheck>(
249-
PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
250-
{{"string", R"(#pragma once
245+
EXPECT_EQ(PostCode, runCheckOnCode<IncludeCleanerCheck>(
246+
PreCode, &Errors, "file.cpp", {}, ClangTidyOptions(),
247+
{{"string", R"(#pragma once
251248
namespace std { class string {}; }
252249
)"},
253-
{"vector", R"(#pragma once
250+
{"vector", R"(#pragma once
254251
#include <string>
255252
namespace std { class vector {}; }
256253
)"}}));
@@ -272,14 +269,13 @@ int FooBarResult = foobar();
272269
)";
273270

274271
std::vector<ClangTidyError> Errors;
275-
EXPECT_EQ(PostCode,
276-
runCheckOnCode<IncludeCleanerCheck>(
277-
PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
278-
{{"bar.h", R"(#pragma once
272+
EXPECT_EQ(PostCode, runCheckOnCode<IncludeCleanerCheck>(
273+
PreCode, &Errors, "file.cpp", {}, ClangTidyOptions(),
274+
{{"bar.h", R"(#pragma once
279275
#include "private.h"
280276
int bar();
281277
)"},
282-
{"private.h", R"(#pragma once
278+
{"private.h", R"(#pragma once
283279
// IWYU pragma: private, include "public.h"
284280
int foobar();
285281
)"}}));
@@ -295,11 +291,10 @@ DECLARE(myfunc) {
295291
)";
296292

297293
std::vector<ClangTidyError> Errors;
298-
EXPECT_EQ(PreCode,
299-
runCheckOnCode<IncludeCleanerCheck>(
300-
PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
301-
{{"foo.h",
302-
R"(#pragma once
294+
EXPECT_EQ(PreCode, runCheckOnCode<IncludeCleanerCheck>(
295+
PreCode, &Errors, "file.cpp", {}, ClangTidyOptions(),
296+
{{"foo.h",
297+
R"(#pragma once
303298
#define DECLARE(X) void X()
304299
)"}}));
305300

@@ -311,11 +306,10 @@ DECLARE {
311306
}
312307
)";
313308

314-
EXPECT_EQ(PreCode,
315-
runCheckOnCode<IncludeCleanerCheck>(
316-
PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
317-
{{"foo.h",
318-
R"(#pragma once
309+
EXPECT_EQ(PreCode, runCheckOnCode<IncludeCleanerCheck>(
310+
PreCode, &Errors, "file.cpp", {}, ClangTidyOptions(),
311+
{{"foo.h",
312+
R"(#pragma once
319313
#define DECLARE void myfunc()
320314
)"}}));
321315
}

clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class ObjCGeneratedHeaderInserterCheck : public IncludeInserterCheckBase {
167167
template <typename Check>
168168
std::string runCheckOnCode(StringRef Code, StringRef Filename) {
169169
std::vector<ClangTidyError> Errors;
170-
return test::runCheckOnCode<Check>(Code, &Errors, Filename, std::nullopt,
170+
return test::runCheckOnCode<Check>(Code, &Errors, Filename, {},
171171
ClangTidyOptions(),
172172
{// Main file include
173173
{"clang_tidy/tests/"

clang-tools-extra/unittests/clang-tidy/NamespaceAliaserTest.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,8 @@ std::string runChecker(StringRef Code, unsigned ExpectedWarningCount) {
5656
"}"}};
5757
std::vector<ClangTidyError> errors;
5858

59-
std::string result =
60-
test::runCheckOnCode<Check>(Code, &errors, "foo.cc", std::nullopt,
61-
ClangTidyOptions(), AdditionalFileContents);
59+
std::string result = test::runCheckOnCode<Check>(
60+
Code, &errors, "foo.cc", {}, ClangTidyOptions(), AdditionalFileContents);
6261

6362
EXPECT_EQ(ExpectedWarningCount, errors.size());
6463
return result;

clang-tools-extra/unittests/clang-tidy/ReadabilityModuleTest.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ TEST(BracesAroundStatementsCheckTest, IfElseWithShortStatements) {
256256
" else if (1 == 2) return -2;\n"
257257
" else return -3;\n"
258258
"}",
259-
nullptr, "input.cc", std::nullopt, Options));
259+
nullptr, "input.cc", {}, Options));
260260

261261
// If the last else is an else-if, we also force it.
262262
EXPECT_EQ("int main() {\n"
@@ -269,7 +269,7 @@ TEST(BracesAroundStatementsCheckTest, IfElseWithShortStatements) {
269269
" if (false) return -1;\n"
270270
" else if (1 == 2) return -2;\n"
271271
"}",
272-
nullptr, "input.cc", std::nullopt, Options));
272+
nullptr, "input.cc", {}, Options));
273273
}
274274

275275
TEST(BracesAroundStatementsCheckTest, For) {
@@ -484,8 +484,7 @@ TEST(BracesAroundStatementsCheckTest, Macros) {
484484
}
485485

486486
#define EXPECT_NO_CHANGES_WITH_OPTS(Check, Opts, Code) \
487-
EXPECT_EQ(Code, runCheckOnCode<Check>(Code, nullptr, "input.cc", \
488-
std::nullopt, Opts))
487+
EXPECT_EQ(Code, runCheckOnCode<Check>(Code, nullptr, "input.cc", {}, Opts))
489488
TEST(BracesAroundStatementsCheckTest, ImplicitCastInReturn) {
490489
ClangTidyOptions Opts;
491490
Opts.CheckOptions["test-check-0.ShortStatementLines"] = "1";

clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,11 @@ TEST(TransformerClangTidyCheckTest, DisableByConfig) {
260260

261261
Options.CheckOptions["test-check-0.Skip"] = "true";
262262
EXPECT_EQ(Input, test::runCheckOnCode<ConfigurableCheck>(
263-
Input, nullptr, "input.cc", std::nullopt, Options));
263+
Input, nullptr, "input.cc", {}, Options));
264264

265265
Options.CheckOptions["test-check-0.Skip"] = "false";
266266
EXPECT_EQ(Expected, test::runCheckOnCode<ConfigurableCheck>(
267-
Input, nullptr, "input.cc", std::nullopt, Options));
267+
Input, nullptr, "input.cc", {}, Options));
268268
}
269269

270270
RewriteRuleWith<std::string> replaceCall(IncludeFormat Format) {
@@ -346,20 +346,20 @@ int h(int x) { return 5; })cc";
346346
ClangTidyOptions Options;
347347
std::map<StringRef, StringRef> PathsToContent = {{"input.h", "\n"}};
348348
Options.CheckOptions["test-check-0.IncludeStyle"] = "llvm";
349-
EXPECT_EQ(TreatsAsLibraryHeader, test::runCheckOnCode<IncludeOrderCheck>(
350-
Input, nullptr, "inputTest.cpp",
351-
std::nullopt, Options, PathsToContent));
352-
EXPECT_EQ(TreatsAsNormalHeader, test::runCheckOnCode<IncludeOrderCheck>(
353-
Input, nullptr, "input_test.cpp",
354-
std::nullopt, Options, PathsToContent));
349+
EXPECT_EQ(TreatsAsLibraryHeader,
350+
test::runCheckOnCode<IncludeOrderCheck>(
351+
Input, nullptr, "inputTest.cpp", {}, Options, PathsToContent));
352+
EXPECT_EQ(TreatsAsNormalHeader,
353+
test::runCheckOnCode<IncludeOrderCheck>(
354+
Input, nullptr, "input_test.cpp", {}, Options, PathsToContent));
355355

356356
Options.CheckOptions["test-check-0.IncludeStyle"] = "google";
357-
EXPECT_EQ(TreatsAsNormalHeader, test::runCheckOnCode<IncludeOrderCheck>(
358-
Input, nullptr, "inputTest.cc",
359-
std::nullopt, Options, PathsToContent));
360-
EXPECT_EQ(TreatsAsLibraryHeader, test::runCheckOnCode<IncludeOrderCheck>(
361-
Input, nullptr, "input_test.cc",
362-
std::nullopt, Options, PathsToContent));
357+
EXPECT_EQ(TreatsAsNormalHeader,
358+
test::runCheckOnCode<IncludeOrderCheck>(
359+
Input, nullptr, "inputTest.cc", {}, Options, PathsToContent));
360+
EXPECT_EQ(TreatsAsLibraryHeader,
361+
test::runCheckOnCode<IncludeOrderCheck>(
362+
Input, nullptr, "input_test.cc", {}, Options, PathsToContent));
363363
}
364364

365365
TEST(TransformerClangTidyCheckTest, AddIncludeObeysSortStyleGlobalOption) {
@@ -378,20 +378,20 @@ int h(int x) { return 5; })cc";
378378
ClangTidyOptions Options;
379379
std::map<StringRef, StringRef> PathsToContent = {{"input.h", "\n"}};
380380
Options.CheckOptions["IncludeStyle"] = "llvm";
381-
EXPECT_EQ(TreatsAsLibraryHeader, test::runCheckOnCode<IncludeOrderCheck>(
382-
Input, nullptr, "inputTest.cpp",
383-
std::nullopt, Options, PathsToContent));
384-
EXPECT_EQ(TreatsAsNormalHeader, test::runCheckOnCode<IncludeOrderCheck>(
385-
Input, nullptr, "input_test.cpp",
386-
std::nullopt, Options, PathsToContent));
381+
EXPECT_EQ(TreatsAsLibraryHeader,
382+
test::runCheckOnCode<IncludeOrderCheck>(
383+
Input, nullptr, "inputTest.cpp", {}, Options, PathsToContent));
384+
EXPECT_EQ(TreatsAsNormalHeader,
385+
test::runCheckOnCode<IncludeOrderCheck>(
386+
Input, nullptr, "input_test.cpp", {}, Options, PathsToContent));
387387

388388
Options.CheckOptions["IncludeStyle"] = "google";
389-
EXPECT_EQ(TreatsAsNormalHeader, test::runCheckOnCode<IncludeOrderCheck>(
390-
Input, nullptr, "inputTest.cc",
391-
std::nullopt, Options, PathsToContent));
392-
EXPECT_EQ(TreatsAsLibraryHeader, test::runCheckOnCode<IncludeOrderCheck>(
393-
Input, nullptr, "input_test.cc",
394-
std::nullopt, Options, PathsToContent));
389+
EXPECT_EQ(TreatsAsNormalHeader,
390+
test::runCheckOnCode<IncludeOrderCheck>(
391+
Input, nullptr, "inputTest.cc", {}, Options, PathsToContent));
392+
EXPECT_EQ(TreatsAsLibraryHeader,
393+
test::runCheckOnCode<IncludeOrderCheck>(
394+
Input, nullptr, "input_test.cc", {}, Options, PathsToContent));
395395
}
396396

397397
} // namespace

clang-tools-extra/unittests/clang-tidy/UsingInserterTest.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,8 @@ std::string runChecker(StringRef Code, unsigned ExpectedWarningCount) {
6060
"}"}};
6161
std::vector<ClangTidyError> errors;
6262

63-
std::string result =
64-
test::runCheckOnCode<Check>(Code, &errors, "foo.cc", std::nullopt,
65-
ClangTidyOptions(), AdditionalFileContents);
63+
std::string result = test::runCheckOnCode<Check>(
64+
Code, &errors, "foo.cc", {}, ClangTidyOptions(), AdditionalFileContents);
6665

6766
EXPECT_EQ(ExpectedWarningCount, errors.size());
6867
return result;

0 commit comments

Comments
 (0)