[clang] b8df409 - [clang, clang-tools-extra] Don't use Optional::{hasValue,getValue} (NFC)

Kazu Hirata via cfe-commits cfe-commits at lists.llvm.org
Sat Jun 25 11:55:39 PDT 2022


Author: Kazu Hirata
Date: 2022-06-25T11:55:33-07:00
New Revision: b8df4093e4d82c67a419911a46b63482043643e5

URL: https://github.com/llvm/llvm-project/commit/b8df4093e4d82c67a419911a46b63482043643e5
DIFF: https://github.com/llvm/llvm-project/commit/b8df4093e4d82c67a419911a46b63482043643e5.diff

LOG: [clang, clang-tools-extra] Don't use Optional::{hasValue,getValue} (NFC)

Added: 
    

Modified: 
    clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
    clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
    clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
    clang-tools-extra/clangd/unittests/DumpASTTests.cpp
    clang-tools-extra/clangd/unittests/FileIndexTests.cpp
    clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
    clang-tools-extra/clangd/unittests/HeadersTests.cpp
    clang-tools-extra/clangd/unittests/LSPClient.cpp
    clang-tools-extra/clangd/unittests/Matchers.h
    clang-tools-extra/clangd/unittests/SerializationTests.cpp
    clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
    clang-tools-extra/clangd/unittests/SyncAPI.cpp
    clang-tools-extra/clangd/unittests/TestTU.cpp
    clang-tools-extra/clangd/unittests/tweaks/TweakTesting.cpp
    clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
    clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp
    clang/lib/CodeGen/CodeGenModule.cpp
    clang/unittests/ASTMatchers/ASTMatchersInternalTest.cpp
    clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
    clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp
    clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp
    clang/unittests/Analysis/FlowSensitive/TestingSupport.h
    clang/unittests/Basic/DarwinSDKInfoTest.cpp
    clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
    clang/unittests/Lex/LexerTest.cpp
    clang/unittests/Tooling/SourceCodeTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp b/clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
index 722a5fb699f61..c3ad1b8cfb666 100644
--- a/clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
+++ b/clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
@@ -46,7 +46,7 @@ class LSPTest : public ::testing::Test {
   }
 
   LSPClient &start() {
-    EXPECT_FALSE(Server.hasValue()) << "Already initialized";
+    EXPECT_FALSE(Server) << "Already initialized";
     Server.emplace(Client.transport(), FS, Opts);
     ServerThread.emplace([&] { EXPECT_TRUE(Server->run()); });
     Client.call("initialize", llvm::json::Object{});

diff  --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
index 88698d3177168..f962c3f4ff336 100644
--- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -92,7 +92,7 @@ Matcher<const std::vector<CodeCompletion> &> has(std::string Name,
                                                  CompletionItemKind K) {
   return Contains(AllOf(named(std::move(Name)), kind(K)));
 }
-MATCHER(isDocumented, "") { return arg.Documentation.hasValue(); }
+MATCHER(isDocumented, "") { return arg.Documentation.has_value(); }
 MATCHER(deprecated, "") { return arg.Deprecated; }
 
 std::unique_ptr<SymbolIndex> memIndex(std::vector<Symbol> Symbols) {

diff  --git a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
index 45ceee01ea9a1..0a24f3c0c69b2 100644
--- a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -892,8 +892,7 @@ void bar(int *Y);
   ASSERT_TRUE(X->getOriginalType()->getNullability(X->getASTContext()) ==
               NullabilityKind::NonNull);
   const auto *Y = cast<FunctionDecl>(findDecl(AST, "bar")).getParamDecl(0);
-  ASSERT_FALSE(
-      Y->getOriginalType()->getNullability(X->getASTContext()).hasValue());
+  ASSERT_FALSE(Y->getOriginalType()->getNullability(X->getASTContext()));
 }
 
 TEST(DiagnosticsTest, InsideMacros) {

diff  --git a/clang-tools-extra/clangd/unittests/DumpASTTests.cpp b/clang-tools-extra/clangd/unittests/DumpASTTests.cpp
index f316eedfbf605..e7b368fd25522 100644
--- a/clang-tools-extra/clangd/unittests/DumpASTTests.cpp
+++ b/clang-tools-extra/clangd/unittests/DumpASTTests.cpp
@@ -172,8 +172,7 @@ TEST(DumpASTTests, NoRange) {
   ASSERT_THAT(Node.children, Contains(withDetail("varFromSource")));
   ASSERT_THAT(Node.children, Not(Contains(withDetail("funcFromHeader"))));
   EXPECT_THAT(Node.arcana, testing::StartsWith("TranslationUnitDecl "));
-  ASSERT_FALSE(Node.range.hasValue())
-      << "Expected no range for translation unit";
+  ASSERT_FALSE(Node.range) << "Expected no range for translation unit";
 }
 
 TEST(DumpASTTests, Arcana) {

diff  --git a/clang-tools-extra/clangd/unittests/FileIndexTests.cpp b/clang-tools-extra/clangd/unittests/FileIndexTests.cpp
index 912d7d0e96139..4aee602c4cfcf 100644
--- a/clang-tools-extra/clangd/unittests/FileIndexTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FileIndexTests.cpp
@@ -650,7 +650,7 @@ TEST(FileShardedIndexTest, Sharding) {
                              Relation{Sym3.ID, RelationKind::BaseOf, Sym1.ID}));
     ASSERT_THAT(Shard->Sources->keys(), UnorderedElementsAre(AHeaderUri));
     EXPECT_THAT(Shard->Sources->lookup(AHeaderUri).DirectIncludes, IsEmpty());
-    EXPECT_TRUE(Shard->Cmd.hasValue());
+    EXPECT_TRUE(Shard->Cmd);
   }
   {
     auto Shard = ShardedIndex.getShard(BHeaderUri);
@@ -665,7 +665,7 @@ TEST(FileShardedIndexTest, Sharding) {
                 UnorderedElementsAre(BHeaderUri, AHeaderUri));
     EXPECT_THAT(Shard->Sources->lookup(BHeaderUri).DirectIncludes,
                 UnorderedElementsAre(AHeaderUri));
-    EXPECT_TRUE(Shard->Cmd.hasValue());
+    EXPECT_TRUE(Shard->Cmd);
   }
   {
     auto Shard = ShardedIndex.getShard(BSourceUri);
@@ -677,7 +677,7 @@ TEST(FileShardedIndexTest, Sharding) {
                 UnorderedElementsAre(BSourceUri, BHeaderUri));
     EXPECT_THAT(Shard->Sources->lookup(BSourceUri).DirectIncludes,
                 UnorderedElementsAre(BHeaderUri));
-    EXPECT_TRUE(Shard->Cmd.hasValue());
+    EXPECT_TRUE(Shard->Cmd);
   }
 }
 

diff  --git a/clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp b/clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
index 3fc45edd16dec..fbf07aad4cd1f 100644
--- a/clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
+++ b/clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
@@ -145,7 +145,7 @@ TEST_F(OverlayCDBTest, Adjustments) {
                    return Ret;
                  });
   // Command from underlying gets adjusted.
-  auto Cmd = CDB.getCompileCommand(testPath("foo.cc")).getValue();
+  auto Cmd = *CDB.getCompileCommand(testPath("foo.cc"));
   EXPECT_THAT(Cmd.CommandLine, ElementsAre("clang", "-DA=1", testPath("foo.cc"),
                                            "-DAdjust_foo.cc"));
 
@@ -154,7 +154,7 @@ TEST_F(OverlayCDBTest, Adjustments) {
   BarCommand.Filename = testPath("bar.cc");
   BarCommand.CommandLine = {"clang++", "-DB=1", testPath("bar.cc")};
   CDB.setCompileCommand(testPath("bar.cc"), BarCommand);
-  Cmd = CDB.getCompileCommand(testPath("bar.cc")).getValue();
+  Cmd = *CDB.getCompileCommand(testPath("bar.cc"));
   EXPECT_THAT(
       Cmd.CommandLine,
       ElementsAre("clang++", "-DB=1", testPath("bar.cc"), "-DAdjust_bar.cc"));
@@ -253,7 +253,7 @@ TEST(GlobalCompilationDatabaseTest, DiscoveryWithNestedCDBs) {
 
     // Does not use the root CDB, so no broadcast.
     auto Cmd = DB.getCompileCommand(testPath("build/../a.cc"));
-    ASSERT_TRUE(Cmd.hasValue());
+    ASSERT_TRUE(Cmd);
     EXPECT_THAT(Cmd->CommandLine, Contains("-DFOO")) << "a.cc uses foo/ CDB";
     ASSERT_TRUE(DB.blockUntilIdle(timeoutSeconds(10)));
     EXPECT_THAT(DiscoveredFiles, IsEmpty()) << "Root CDB not discovered yet";

diff  --git a/clang-tools-extra/clangd/unittests/HeadersTests.cpp b/clang-tools-extra/clangd/unittests/HeadersTests.cpp
index 69fcadcf0674a..32e4aea15490b 100644
--- a/clang-tools-extra/clangd/unittests/HeadersTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HeadersTests.cpp
@@ -329,7 +329,7 @@ TEST_F(HeadersTest, DontInsertDuplicateResolved) {
 
 TEST_F(HeadersTest, PreferInserted) {
   auto Edit = insert("<y>");
-  EXPECT_TRUE(Edit.hasValue());
+  EXPECT_TRUE(Edit);
   EXPECT_TRUE(StringRef(Edit->newText).contains("<y>"));
 }
 

diff  --git a/clang-tools-extra/clangd/unittests/LSPClient.cpp b/clang-tools-extra/clangd/unittests/LSPClient.cpp
index 21f64c7261910..aaadc62e68f35 100644
--- a/clang-tools-extra/clangd/unittests/LSPClient.cpp
+++ b/clang-tools-extra/clangd/unittests/LSPClient.cpp
@@ -24,7 +24,7 @@ namespace clangd {
 llvm::Expected<llvm::json::Value> clang::clangd::LSPClient::CallResult::take() {
   std::unique_lock<std::mutex> Lock(Mu);
   if (!clangd::wait(Lock, CV, timeoutSeconds(10),
-                    [this] { return Value.hasValue(); })) {
+                    [this] { return Value.has_value(); })) {
     ADD_FAILURE() << "No result from call after 10 seconds!";
     return llvm::json::Value(nullptr);
   }

diff  --git a/clang-tools-extra/clangd/unittests/Matchers.h b/clang-tools-extra/clangd/unittests/Matchers.h
index ef53e867949c9..0fbd93b2e6882 100644
--- a/clang-tools-extra/clangd/unittests/Matchers.h
+++ b/clang-tools-extra/clangd/unittests/Matchers.h
@@ -173,7 +173,7 @@ template <typename InnerMatcher> class OptionalMatcher {
     virtual bool
     MatchAndExplain(Optional optional,
                     ::testing::MatchResultListener *listener) const {
-      if (!optional.hasValue())
+      if (!optional)
         return false;
 
       *listener << "which has a value ";

diff  --git a/clang-tools-extra/clangd/unittests/SerializationTests.cpp b/clang-tools-extra/clangd/unittests/SerializationTests.cpp
index efbaed233c5b6..70873efe5776c 100644
--- a/clang-tools-extra/clangd/unittests/SerializationTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SerializationTests.cpp
@@ -297,7 +297,7 @@ TEST(SerializationTest, CmdlTest) {
     ASSERT_TRUE(bool(In)) << In.takeError();
     ASSERT_TRUE(In->Cmd);
 
-    const tooling::CompileCommand &SerializedCmd = In->Cmd.getValue();
+    const tooling::CompileCommand &SerializedCmd = *In->Cmd;
     EXPECT_EQ(SerializedCmd.CommandLine, Cmd.CommandLine);
     EXPECT_EQ(SerializedCmd.Directory, Cmd.Directory);
     EXPECT_NE(SerializedCmd.Filename, Cmd.Filename);

diff  --git a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
index 32c889876f24c..8dc7877c17849 100644
--- a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -119,7 +119,7 @@ class ShouldCollectSymbolTest : public ::testing::Test {
 
   // build() must have been called.
   bool shouldCollect(llvm::StringRef Name, bool Qualified = true) {
-    assert(AST.hasValue());
+    assert(AST);
     const NamedDecl &ND =
         Qualified ? findDecl(*AST, Name) : findUnqualifiedDecl(*AST, Name);
     const SourceManager &SM = AST->getSourceManager();

diff  --git a/clang-tools-extra/clangd/unittests/SyncAPI.cpp b/clang-tools-extra/clangd/unittests/SyncAPI.cpp
index 4e76cdf6c540d..52f47b01b4e1b 100644
--- a/clang-tools-extra/clangd/unittests/SyncAPI.cpp
+++ b/clang-tools-extra/clangd/unittests/SyncAPI.cpp
@@ -27,9 +27,7 @@ namespace {
 ///    T Result;
 ///    someAsyncFunc(Param1, Param2, /*Callback=*/capture(Result));
 template <typename T> struct CaptureProxy {
-  CaptureProxy(llvm::Optional<T> &Target) : Target(&Target) {
-    assert(!Target.hasValue());
-  }
+  CaptureProxy(llvm::Optional<T> &Target) : Target(&Target) { assert(!Target); }
 
   CaptureProxy(const CaptureProxy &) = delete;
   CaptureProxy &operator=(const CaptureProxy &) = delete;
@@ -51,7 +49,7 @@ template <typename T> struct CaptureProxy {
     if (!Target)
       return;
     assert(Future.valid() && "conversion to callback was not called");
-    assert(!Target->hasValue());
+    assert(!Target->has_value());
     Target->emplace(std::move(*Future.get()));
   }
 

diff  --git a/clang-tools-extra/clangd/unittests/TestTU.cpp b/clang-tools-extra/clangd/unittests/TestTU.cpp
index c47ed2910baa5..3da1086829605 100644
--- a/clang-tools-extra/clangd/unittests/TestTU.cpp
+++ b/clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -123,7 +123,7 @@ ParsedAST TestTU::build() const {
                                                /*PreambleCallback=*/nullptr);
   auto AST = ParsedAST::build(testPath(Filename), Inputs, std::move(CI),
                               Diags.take(), Preamble);
-  if (!AST.hasValue()) {
+  if (!AST) {
     llvm::errs() << "Failed to build code:\n" << Code;
     std::abort();
   }

diff  --git a/clang-tools-extra/clangd/unittests/tweaks/TweakTesting.cpp b/clang-tools-extra/clangd/unittests/tweaks/TweakTesting.cpp
index 3f472f26c0aa4..726e2b87d1400 100644
--- a/clang-tools-extra/clangd/unittests/tweaks/TweakTesting.cpp
+++ b/clang-tools-extra/clangd/unittests/tweaks/TweakTesting.cpp
@@ -136,7 +136,7 @@ bool TweakTest::isAvailable(WrappedAST &AST,
   // We only care if prepare() succeeded, but must handle Errors.
   if (Result && !*Result)
     consumeError(Result->takeError());
-  return Result.hasValue();
+  return Result.has_value();
 }
 
 TweakTest::WrappedAST TweakTest::build(llvm::StringRef Code) const {

diff  --git a/clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp b/clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
index 41621aad7d4f0..3558b5f346a23 100644
--- a/clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
+++ b/clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
@@ -292,7 +292,7 @@ TEST(CheckOptionsValidation, MissingOptions) {
                        &DiagConsumer, false);
   Context.setDiagnosticsEngine(&DE);
   TestCheck TestCheck(&Context);
-  EXPECT_FALSE(TestCheck.getLocal("Opt").hasValue());
+  EXPECT_FALSE(TestCheck.getLocal("Opt"));
   EXPECT_EQ(TestCheck.getLocal("Opt", "Unknown"), "Unknown");
   // Missing options aren't errors.
   EXPECT_TRUE(DiagConsumer.take().empty());
@@ -336,7 +336,7 @@ TEST(CheckOptionsValidation, ValidIntOptions) {
   CHECK_VAL(TestCheck.getIntLocal<bool>("BoolFalseValue"), false);
   CHECK_VAL(TestCheck.getIntLocal<bool>("BoolTrueShort"), true);
   CHECK_VAL(TestCheck.getIntLocal<bool>("BoolFalseShort"), false);
-  EXPECT_FALSE(TestCheck.getIntLocal<bool>("BoolUnparseable").hasValue());
+  EXPECT_FALSE(TestCheck.getIntLocal<bool>("BoolUnparseable"));
 
   EXPECT_THAT(
       DiagConsumer.take(),

diff  --git a/clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp b/clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp
index ae9018faf6ae2..93cffadb8279e 100644
--- a/clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp
+++ b/clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp
@@ -21,7 +21,7 @@ static std::string runCheck(StringRef Code, const Twine &Filename,
   std::string Result = test::runCheckOnCode<T>(
       Code, &Errors, Filename, std::string("-xc++-header"), ClangTidyOptions{},
       std::move(PathsToContent));
-  if (Errors.size() != (size_t)ExpectedWarning.hasValue())
+  if (Errors.size() != (size_t)ExpectedWarning.has_value())
     return "invalid error count";
   if (ExpectedWarning && *ExpectedWarning != Errors.back().Message.Message)
     return "expected: '" + ExpectedWarning->str() + "', saw: '" +

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index f7bac66c484b8..17b8e6bc1b470 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -2839,7 +2839,7 @@ bool CodeGenModule::isProfileInstrExcluded(llvm::Function *Fn,
   auto &SM = Context.getSourceManager();
   if (const auto *MainFile = SM.getFileEntryForID(SM.getMainFileID())) {
     Optional<bool> V = ProfileList.isFileExcluded(MainFile->getName(), Kind);
-    if (V.hasValue())
+    if (V)
       return *V;
   }
   return ProfileList.getDefault();

diff  --git a/clang/unittests/ASTMatchers/ASTMatchersInternalTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersInternalTest.cpp
index 6573461c9fc1e..eb9071bd9cb6d 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersInternalTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersInternalTest.cpp
@@ -277,7 +277,7 @@ TEST(Matcher, matchOverEntireASTContext) {
 
 TEST(DynTypedMatcherTest, TraversalKindForwardsToImpl) {
   auto M = DynTypedMatcher(decl());
-  EXPECT_FALSE(M.getTraversalKind().hasValue());
+  EXPECT_FALSE(M.getTraversalKind());
 
   M = DynTypedMatcher(traverse(TK_AsIs, decl()));
   EXPECT_THAT(M.getTraversalKind(), llvm::ValueIs(TK_AsIs));

diff  --git a/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp b/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
index 255432dc3862a..eaba6b762c026 100644
--- a/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
+++ b/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
@@ -149,7 +149,7 @@ bool matchesRange(SourceRange Range, unsigned StartLine,
 llvm::Optional<DynTypedMatcher> getSingleMatcher(const VariantValue &Value) {
   llvm::Optional<DynTypedMatcher> Result =
       Value.getMatcher().getSingleMatcher();
-  EXPECT_TRUE(Result.hasValue());
+  EXPECT_TRUE(Result);
   return Result;
 }
 
@@ -280,7 +280,7 @@ TEST(ParserTest, FullParserTest) {
   EXPECT_TRUE(matches("unsigned aaaccbb;", M));
 
   Code = "hasInitializer(\n    binaryOperator(hasLHS(\"A\")))";
-  EXPECT_TRUE(!Parser::parseMatcherExpression(Code, &Error).hasValue());
+  EXPECT_TRUE(!Parser::parseMatcherExpression(Code, &Error));
   EXPECT_EQ("1:1: Error parsing argument 1 for matcher hasInitializer.\n"
             "2:5: Error parsing argument 1 for matcher binaryOperator.\n"
             "2:20: Error building matcher hasLHS.\n"
@@ -421,7 +421,7 @@ TEST(ParserTest, ParseMultiline) {
   )
 )matcher";
     Diagnostics Error;
-    EXPECT_TRUE(Parser::parseMatcherExpression(Code, &Error).hasValue());
+    EXPECT_TRUE(Parser::parseMatcherExpression(Code, &Error));
   }
 
   {
@@ -432,7 +432,7 @@ TEST(ParserTest, ParseMultiline) {
   )
 )matcher";
     Diagnostics Error;
-    EXPECT_TRUE(Parser::parseMatcherExpression(Code, &Error).hasValue());
+    EXPECT_TRUE(Parser::parseMatcherExpression(Code, &Error));
   }
 
   {
@@ -440,7 +440,7 @@ TEST(ParserTest, ParseMultiline) {
   "paramName")
 )matcher";
     Diagnostics Error;
-    EXPECT_TRUE(Parser::parseMatcherExpression(Code, &Error).hasValue());
+    EXPECT_TRUE(Parser::parseMatcherExpression(Code, &Error));
   }
 
   {
@@ -481,7 +481,7 @@ decl()))matcher";
   ("paramName")
 )matcher";
     M = Parser::parseMatcherExpression(Code, nullptr, &NamedValues, &Error);
-    EXPECT_FALSE(M.hasValue());
+    EXPECT_FALSE(M);
     EXPECT_EQ("1:15: Malformed bind() expression.", Error.toStringFull());
   }
 
@@ -494,7 +494,7 @@ decl()))matcher";
   bind("paramName")
 )matcher";
     M = Parser::parseMatcherExpression(Code, nullptr, &NamedValues, &Error);
-    EXPECT_FALSE(M.hasValue());
+    EXPECT_FALSE(M);
     EXPECT_EQ("1:11: Period not followed by valid chained call.",
               Error.toStringFull());
   }
@@ -506,7 +506,7 @@ decl()))matcher";
 ()
 )matcher";
     M = Parser::parseMatcherExpression(Code, nullptr, nullptr, &Error);
-    EXPECT_FALSE(M.hasValue());
+    EXPECT_FALSE(M);
     EXPECT_EQ("1:8: Error parsing matcher. Found token "
               "<NewLine> while looking for '('.",
               Error.toStringFull());
@@ -521,7 +521,7 @@ decl()))matcher";
   )
 )matcher";
     M = Parser::parseMatcherExpression(Code, nullptr, nullptr, &Error);
-    EXPECT_FALSE(M.hasValue());
+    EXPECT_FALSE(M);
     StringRef Expected = R"error(1:1: Error parsing argument 1 for matcher varDecl.
 2:3: Matcher not found: doesNotExist)error";
     EXPECT_EQ(Expected, Error.toStringFull());

diff  --git a/clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp b/clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp
index 797b2849acedf..05cd67e52fd48 100644
--- a/clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp
@@ -94,7 +94,7 @@ struct ValueLattice {
 };
 
 std::ostream &operator<<(std::ostream &OS, const ValueLattice &L) {
-  if (L.Value.hasValue())
+  if (L.Value)
     return OS << *L.Value;
   switch (L.State) {
   case ValueLattice::ValueState::Undefined:
@@ -194,9 +194,7 @@ MATCHER_P(Var, name,
   return arg->getName() == name;
 }
 
-MATCHER_P(HasConstantVal, v, "") {
-  return arg.Value.hasValue() && *arg.Value == v;
-}
+MATCHER_P(HasConstantVal, v, "") { return arg.Value && *arg.Value == v; }
 
 MATCHER(Varies, "") { return arg == arg.top(); }
 

diff  --git a/clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp b/clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp
index 842e3502efaaf..6561385cfd84a 100644
--- a/clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp
@@ -171,9 +171,7 @@ class ConstantPropagationAnalysis
 using ::testing::Pair;
 using ::testing::UnorderedElementsAre;
 
-MATCHER_P(HasConstantVal, v, "") {
-  return arg.Data.hasValue() && arg.Data->Value == v;
-}
+MATCHER_P(HasConstantVal, v, "") { return arg.Data && arg.Data->Value == v; }
 
 MATCHER(IsUnknown, "") { return arg == arg.bottom(); }
 MATCHER(Varies, "") { return arg == arg.top(); }

diff  --git a/clang/unittests/Analysis/FlowSensitive/TestingSupport.h b/clang/unittests/Analysis/FlowSensitive/TestingSupport.h
index 957d73fd6d0c4..ce439f5613028 100644
--- a/clang/unittests/Analysis/FlowSensitive/TestingSupport.h
+++ b/clang/unittests/Analysis/FlowSensitive/TestingSupport.h
@@ -131,7 +131,7 @@ llvm::Error checkDataflow(
   std::vector<std::pair<std::string, StateT>> Results;
   for (const CFGBlock *Block : CFCtx->getCFG()) {
     // Skip blocks that were not evaluated.
-    if (!BlockStates[Block->getBlockID()].hasValue())
+    if (!BlockStates[Block->getBlockID()])
       continue;
 
     transferBlock(

diff  --git a/clang/unittests/Basic/DarwinSDKInfoTest.cpp b/clang/unittests/Basic/DarwinSDKInfoTest.cpp
index aa1feeb293c0e..8d720c2e0a6f0 100644
--- a/clang/unittests/Basic/DarwinSDKInfoTest.cpp
+++ b/clang/unittests/Basic/DarwinSDKInfoTest.cpp
@@ -19,7 +19,7 @@ TEST(DarwinSDKInfo, VersionMapping) {
   Optional<DarwinSDKInfo::RelatedTargetVersionMapping> Mapping =
       DarwinSDKInfo::RelatedTargetVersionMapping::parseJSON(Obj,
                                                             VersionTuple());
-  EXPECT_TRUE(Mapping.hasValue());
+  EXPECT_TRUE(Mapping);
   EXPECT_EQ(Mapping->getMinimumValue(), VersionTuple(1));
 
   // Exact mapping.
@@ -54,7 +54,7 @@ TEST(DarwinSDKInfo, VersionMappingMissingKey) {
   Optional<DarwinSDKInfo::RelatedTargetVersionMapping> Mapping =
       DarwinSDKInfo::RelatedTargetVersionMapping::parseJSON(Obj,
                                                             VersionTuple());
-  EXPECT_TRUE(Mapping.hasValue());
+  EXPECT_TRUE(Mapping);
   EXPECT_EQ(
       Mapping->map(VersionTuple(4), VersionTuple(0, 1), VersionTuple(100)),
       None);

diff  --git a/clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp b/clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
index f0dc55a47bff3..5b76480d3b869 100644
--- a/clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
+++ b/clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
@@ -194,7 +194,7 @@ struct VerifyingConsumer {
       if (result())
         return *result();
 
-      ResultIsReady.wait(L, [this]() { return result().hasValue(); });
+      ResultIsReady.wait(L, [this]() { return result().has_value(); });
     }
     return false; // Just to make compiler happy.
   }

diff  --git a/clang/unittests/Lex/LexerTest.cpp b/clang/unittests/Lex/LexerTest.cpp
index f534de1ca813a..0ad644ce71465 100644
--- a/clang/unittests/Lex/LexerTest.cpp
+++ b/clang/unittests/Lex/LexerTest.cpp
@@ -612,7 +612,7 @@ TEST_F(LexerTest, FindNextToken) {
       SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID());
   while (true) {
     auto T = Lexer::findNextToken(Loc, SourceMgr, LangOpts);
-    ASSERT_TRUE(T.hasValue());
+    ASSERT_TRUE(T);
     if (T->is(tok::eof))
       break;
     GeneratedByNextToken.push_back(getSourceText(*T, *T));

diff  --git a/clang/unittests/Tooling/SourceCodeTest.cpp b/clang/unittests/Tooling/SourceCodeTest.cpp
index badc6f88fc0af..2d4757c8c770d 100644
--- a/clang/unittests/Tooling/SourceCodeTest.cpp
+++ b/clang/unittests/Tooling/SourceCodeTest.cpp
@@ -474,7 +474,7 @@ int c = BAR 3.0;
   IntLitVisitor Visitor;
   Visitor.OnIntLit = [](IntegerLiteral *Expr, ASTContext *Context) {
     auto Range = CharSourceRange::getTokenRange(Expr->getSourceRange());
-    EXPECT_FALSE(getRangeForEdit(Range, *Context).hasValue());
+    EXPECT_FALSE(getRangeForEdit(Range, *Context));
   };
   Visitor.runOver(Code);
 }


        


More information about the cfe-commits mailing list