Skip to content

Commit b8df409

Browse files
[clang, clang-tools-extra] Don't use Optional::{hasValue,getValue} (NFC)
1 parent 7d101e4 commit b8df409

26 files changed

+42
-50
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class LSPTest : public ::testing::Test {
4646
}
4747

4848
LSPClient &start() {
49-
EXPECT_FALSE(Server.hasValue()) << "Already initialized";
49+
EXPECT_FALSE(Server) << "Already initialized";
5050
Server.emplace(Client.transport(), FS, Opts);
5151
ServerThread.emplace([&] { EXPECT_TRUE(Server->run()); });
5252
Client.call("initialize", llvm::json::Object{});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Matcher<const std::vector<CodeCompletion> &> has(std::string Name,
9292
CompletionItemKind K) {
9393
return Contains(AllOf(named(std::move(Name)), kind(K)));
9494
}
95-
MATCHER(isDocumented, "") { return arg.Documentation.hasValue(); }
95+
MATCHER(isDocumented, "") { return arg.Documentation.has_value(); }
9696
MATCHER(deprecated, "") { return arg.Deprecated; }
9797

9898
std::unique_ptr<SymbolIndex> memIndex(std::vector<Symbol> Symbols) {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -892,8 +892,7 @@ void bar(int *Y);
892892
ASSERT_TRUE(X->getOriginalType()->getNullability(X->getASTContext()) ==
893893
NullabilityKind::NonNull);
894894
const auto *Y = cast<FunctionDecl>(findDecl(AST, "bar")).getParamDecl(0);
895-
ASSERT_FALSE(
896-
Y->getOriginalType()->getNullability(X->getASTContext()).hasValue());
895+
ASSERT_FALSE(Y->getOriginalType()->getNullability(X->getASTContext()));
897896
}
898897

899898
TEST(DiagnosticsTest, InsideMacros) {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,7 @@ TEST(DumpASTTests, NoRange) {
172172
ASSERT_THAT(Node.children, Contains(withDetail("varFromSource")));
173173
ASSERT_THAT(Node.children, Not(Contains(withDetail("funcFromHeader"))));
174174
EXPECT_THAT(Node.arcana, testing::StartsWith("TranslationUnitDecl "));
175-
ASSERT_FALSE(Node.range.hasValue())
176-
<< "Expected no range for translation unit";
175+
ASSERT_FALSE(Node.range) << "Expected no range for translation unit";
177176
}
178177

179178
TEST(DumpASTTests, Arcana) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ TEST(FileShardedIndexTest, Sharding) {
650650
Relation{Sym3.ID, RelationKind::BaseOf, Sym1.ID}));
651651
ASSERT_THAT(Shard->Sources->keys(), UnorderedElementsAre(AHeaderUri));
652652
EXPECT_THAT(Shard->Sources->lookup(AHeaderUri).DirectIncludes, IsEmpty());
653-
EXPECT_TRUE(Shard->Cmd.hasValue());
653+
EXPECT_TRUE(Shard->Cmd);
654654
}
655655
{
656656
auto Shard = ShardedIndex.getShard(BHeaderUri);
@@ -665,7 +665,7 @@ TEST(FileShardedIndexTest, Sharding) {
665665
UnorderedElementsAre(BHeaderUri, AHeaderUri));
666666
EXPECT_THAT(Shard->Sources->lookup(BHeaderUri).DirectIncludes,
667667
UnorderedElementsAre(AHeaderUri));
668-
EXPECT_TRUE(Shard->Cmd.hasValue());
668+
EXPECT_TRUE(Shard->Cmd);
669669
}
670670
{
671671
auto Shard = ShardedIndex.getShard(BSourceUri);
@@ -677,7 +677,7 @@ TEST(FileShardedIndexTest, Sharding) {
677677
UnorderedElementsAre(BSourceUri, BHeaderUri));
678678
EXPECT_THAT(Shard->Sources->lookup(BSourceUri).DirectIncludes,
679679
UnorderedElementsAre(BHeaderUri));
680-
EXPECT_TRUE(Shard->Cmd.hasValue());
680+
EXPECT_TRUE(Shard->Cmd);
681681
}
682682
}
683683

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ TEST_F(OverlayCDBTest, Adjustments) {
145145
return Ret;
146146
});
147147
// Command from underlying gets adjusted.
148-
auto Cmd = CDB.getCompileCommand(testPath("foo.cc")).getValue();
148+
auto Cmd = *CDB.getCompileCommand(testPath("foo.cc"));
149149
EXPECT_THAT(Cmd.CommandLine, ElementsAre("clang", "-DA=1", testPath("foo.cc"),
150150
"-DAdjust_foo.cc"));
151151

@@ -154,7 +154,7 @@ TEST_F(OverlayCDBTest, Adjustments) {
154154
BarCommand.Filename = testPath("bar.cc");
155155
BarCommand.CommandLine = {"clang++", "-DB=1", testPath("bar.cc")};
156156
CDB.setCompileCommand(testPath("bar.cc"), BarCommand);
157-
Cmd = CDB.getCompileCommand(testPath("bar.cc")).getValue();
157+
Cmd = *CDB.getCompileCommand(testPath("bar.cc"));
158158
EXPECT_THAT(
159159
Cmd.CommandLine,
160160
ElementsAre("clang++", "-DB=1", testPath("bar.cc"), "-DAdjust_bar.cc"));
@@ -253,7 +253,7 @@ TEST(GlobalCompilationDatabaseTest, DiscoveryWithNestedCDBs) {
253253

254254
// Does not use the root CDB, so no broadcast.
255255
auto Cmd = DB.getCompileCommand(testPath("build/../a.cc"));
256-
ASSERT_TRUE(Cmd.hasValue());
256+
ASSERT_TRUE(Cmd);
257257
EXPECT_THAT(Cmd->CommandLine, Contains("-DFOO")) << "a.cc uses foo/ CDB";
258258
ASSERT_TRUE(DB.blockUntilIdle(timeoutSeconds(10)));
259259
EXPECT_THAT(DiscoveredFiles, IsEmpty()) << "Root CDB not discovered yet";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ TEST_F(HeadersTest, DontInsertDuplicateResolved) {
329329

330330
TEST_F(HeadersTest, PreferInserted) {
331331
auto Edit = insert("<y>");
332-
EXPECT_TRUE(Edit.hasValue());
332+
EXPECT_TRUE(Edit);
333333
EXPECT_TRUE(StringRef(Edit->newText).contains("<y>"));
334334
}
335335

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace clangd {
2424
llvm::Expected<llvm::json::Value> clang::clangd::LSPClient::CallResult::take() {
2525
std::unique_lock<std::mutex> Lock(Mu);
2626
if (!clangd::wait(Lock, CV, timeoutSeconds(10),
27-
[this] { return Value.hasValue(); })) {
27+
[this] { return Value.has_value(); })) {
2828
ADD_FAILURE() << "No result from call after 10 seconds!";
2929
return llvm::json::Value(nullptr);
3030
}

clang-tools-extra/clangd/unittests/Matchers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ template <typename InnerMatcher> class OptionalMatcher {
173173
virtual bool
174174
MatchAndExplain(Optional optional,
175175
::testing::MatchResultListener *listener) const {
176-
if (!optional.hasValue())
176+
if (!optional)
177177
return false;
178178

179179
*listener << "which has a value ";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ TEST(SerializationTest, CmdlTest) {
297297
ASSERT_TRUE(bool(In)) << In.takeError();
298298
ASSERT_TRUE(In->Cmd);
299299

300-
const tooling::CompileCommand &SerializedCmd = In->Cmd.getValue();
300+
const tooling::CompileCommand &SerializedCmd = *In->Cmd;
301301
EXPECT_EQ(SerializedCmd.CommandLine, Cmd.CommandLine);
302302
EXPECT_EQ(SerializedCmd.Directory, Cmd.Directory);
303303
EXPECT_NE(SerializedCmd.Filename, Cmd.Filename);

0 commit comments

Comments
 (0)