Author: Kazu Hirata Date: 2022-12-03T12:14:19-08:00 New Revision: a41fbb1fc2126e9791fd0f159f21935f6c2f93c4
URL: https://github.com/llvm/llvm-project/commit/a41fbb1fc2126e9791fd0f159f21935f6c2f93c4 DIFF: https://github.com/llvm/llvm-project/commit/a41fbb1fc2126e9791fd0f159f21935f6c2f93c4.diff LOG: [clang/unittests] Use std::nullopt instead of None (NFC) This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716 Added: Modified: clang/unittests/AST/ASTImporterTest.cpp clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp clang/unittests/Analysis/FlowSensitive/TransferTest.cpp clang/unittests/Basic/DarwinSDKInfoTest.cpp clang/unittests/Basic/FileEntryTest.cpp clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp clang/unittests/Frontend/ASTUnitTest.cpp clang/unittests/Lex/HeaderSearchTest.cpp clang/unittests/Serialization/SourceLocationEncodingTest.cpp clang/unittests/StaticAnalyzer/CallDescriptionTest.cpp clang/unittests/Tooling/ASTSelectionTest.cpp clang/unittests/Tooling/HeaderAnalysisTest.cpp clang/unittests/Tooling/SourceCodeBuildersTest.cpp clang/unittests/Tooling/StandardLibraryTest.cpp clang/unittests/Tooling/StencilTest.cpp clang/unittests/Tooling/Syntax/TokensTest.cpp clang/unittests/Tooling/TransformerTest.cpp Removed: ################################################################################ diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index cb8c0bf5dcd5a..865574f0fec6d 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -4818,7 +4818,7 @@ TEST_P(ASTImporterOptionSpecificTestBase, ImportSubstTemplateTypeParmType) { ASSERT_EQ(Subst->getPackIndex(), PackIndex); }; auto tests = [&](ASTContext &Ctx) { - testType(Ctx, "void", None); + testType(Ctx, "void", std::nullopt); testType(Ctx, "char", 3); testType(Ctx, "float", 2); testType(Ctx, "int", 1); diff --git a/clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp b/clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp index 39a1e1dd0859f..4562a6294b2df 100644 --- a/clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp +++ b/clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp @@ -61,9 +61,10 @@ struct ValueLattice { // When `None`, the lattice is either at top or bottom, based on `State`. llvm::Optional<int64_t> Value; - constexpr ValueLattice() : State(ValueState::Undefined), Value(llvm::None) {} + constexpr ValueLattice() + : State(ValueState::Undefined), Value(std::nullopt) {} constexpr ValueLattice(int64_t V) : State(ValueState::Defined), Value(V) {} - constexpr ValueLattice(ValueState S) : State(S), Value(llvm::None) {} + constexpr ValueLattice(ValueState S) : State(S), Value(std::nullopt) {} static constexpr ValueLattice bottom() { return ValueLattice(ValueState::Undefined); diff --git a/clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp b/clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp index 60b7860917899..9c52ed1b52e2f 100644 --- a/clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp +++ b/clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp @@ -63,7 +63,9 @@ struct ConstantPropagationLattice { // `None` is "bottom". llvm::Optional<VarValue> Data; - static constexpr ConstantPropagationLattice bottom() { return {llvm::None}; } + static constexpr ConstantPropagationLattice bottom() { + return {std::nullopt}; + } static constexpr ConstantPropagationLattice top() { return {VarValue{nullptr, 0}}; } diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp index 01f61cab3716e..7e7be3c9e07ef 100644 --- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp +++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp @@ -3849,7 +3849,7 @@ TEST(TransferTest, ContextSensitiveOptionDisabled) { EXPECT_FALSE(Env.flowConditionImplies(FooVal)); EXPECT_FALSE(Env.flowConditionImplies(Env.makeNot(FooVal))); }, - {TransferOptions{/*.ContextSensitiveOpts=*/llvm::None}}); + {TransferOptions{/*.ContextSensitiveOpts=*/std::nullopt}}); } TEST(TransferTest, ContextSensitiveDepthZero) { diff --git a/clang/unittests/Basic/DarwinSDKInfoTest.cpp b/clang/unittests/Basic/DarwinSDKInfoTest.cpp index d56e13d839162..887f74a97a58f 100644 --- a/clang/unittests/Basic/DarwinSDKInfoTest.cpp +++ b/clang/unittests/Basic/DarwinSDKInfoTest.cpp @@ -23,23 +23,26 @@ TEST(DarwinSDKInfo, VersionMapping) { EXPECT_EQ(Mapping->getMinimumValue(), VersionTuple(1)); // Exact mapping. - EXPECT_EQ(Mapping->map(VersionTuple(3), VersionTuple(0, 1), None), + EXPECT_EQ(Mapping->map(VersionTuple(3), VersionTuple(0, 1), std::nullopt), VersionTuple(1)); - EXPECT_EQ(Mapping->map(VersionTuple(3, 0), VersionTuple(0, 1), None), + EXPECT_EQ(Mapping->map(VersionTuple(3, 0), VersionTuple(0, 1), std::nullopt), VersionTuple(1)); - EXPECT_EQ(Mapping->map(VersionTuple(3, 0, 0), VersionTuple(0, 1), None), - VersionTuple(1)); - EXPECT_EQ(Mapping->map(VersionTuple(3, 1), VersionTuple(0, 1), None), - VersionTuple(1, 2)); - EXPECT_EQ(Mapping->map(VersionTuple(3, 1, 0), VersionTuple(0, 1), None), + EXPECT_EQ( + Mapping->map(VersionTuple(3, 0, 0), VersionTuple(0, 1), std::nullopt), + VersionTuple(1)); + EXPECT_EQ(Mapping->map(VersionTuple(3, 1), VersionTuple(0, 1), std::nullopt), VersionTuple(1, 2)); + EXPECT_EQ( + Mapping->map(VersionTuple(3, 1, 0), VersionTuple(0, 1), std::nullopt), + VersionTuple(1, 2)); // Missing mapping - fallback to major. - EXPECT_EQ(Mapping->map(VersionTuple(3, 0, 1), VersionTuple(0, 1), None), - VersionTuple(1)); + EXPECT_EQ( + Mapping->map(VersionTuple(3, 0, 1), VersionTuple(0, 1), std::nullopt), + VersionTuple(1)); // Minimum - EXPECT_EQ(Mapping->map(VersionTuple(2), VersionTuple(0, 1), None), + EXPECT_EQ(Mapping->map(VersionTuple(2), VersionTuple(0, 1), std::nullopt), VersionTuple(0, 1)); // Maximum @@ -57,7 +60,7 @@ TEST(DarwinSDKInfo, VersionMappingMissingKey) { EXPECT_TRUE(Mapping); EXPECT_EQ( Mapping->map(VersionTuple(4), VersionTuple(0, 1), VersionTuple(100)), - None); + std::nullopt); } TEST(DarwinSDKInfo, VersionMappingParseEmpty) { @@ -95,22 +98,23 @@ TEST(DarwinSDKInfoTest, ParseAndTestMappingMacCatalyst) { ASSERT_TRUE(Mapping); // Verify that the macOS versions that are present in the map are translated // directly to their corresponding Mac Catalyst versions. - EXPECT_EQ(*Mapping->map(VersionTuple(10, 15), VersionTuple(), None), + EXPECT_EQ(*Mapping->map(VersionTuple(10, 15), VersionTuple(), std::nullopt), VersionTuple(13, 1)); - EXPECT_EQ(*Mapping->map(VersionTuple(11, 0), VersionTuple(), None), + EXPECT_EQ(*Mapping->map(VersionTuple(11, 0), VersionTuple(), std::nullopt), VersionTuple(14, 0)); - EXPECT_EQ(*Mapping->map(VersionTuple(11, 2), VersionTuple(), None), + EXPECT_EQ(*Mapping->map(VersionTuple(11, 2), VersionTuple(), std::nullopt), VersionTuple(14, 2)); // Verify that a macOS version that's not present in the map is translated // like the nearest major OS version. - EXPECT_EQ(*Mapping->map(VersionTuple(11, 1), VersionTuple(), None), + EXPECT_EQ(*Mapping->map(VersionTuple(11, 1), VersionTuple(), std::nullopt), VersionTuple(14, 0)); // Verify that the macOS versions that are outside of the mapped version // range map to the min/max values passed to the `map` call. - EXPECT_EQ(*Mapping->map(VersionTuple(10, 14), VersionTuple(99, 99), None), - VersionTuple(99, 99)); + EXPECT_EQ( + *Mapping->map(VersionTuple(10, 14), VersionTuple(99, 99), std::nullopt), + VersionTuple(99, 99)); EXPECT_EQ( *Mapping->map(VersionTuple(11, 5), VersionTuple(), VersionTuple(99, 99)), VersionTuple(99, 99)); @@ -143,22 +147,23 @@ TEST(DarwinSDKInfoTest, ParseAndTestMappingIOSDerived) { // Verify that the iOS versions that are present in the map are translated // directly to their corresponding tvOS versions. - EXPECT_EQ(*Mapping->map(VersionTuple(10, 0), VersionTuple(), None), + EXPECT_EQ(*Mapping->map(VersionTuple(10, 0), VersionTuple(), std::nullopt), VersionTuple(10, 0)); - EXPECT_EQ(*Mapping->map(VersionTuple(10, 3, 1), VersionTuple(), None), + EXPECT_EQ(*Mapping->map(VersionTuple(10, 3, 1), VersionTuple(), std::nullopt), VersionTuple(10, 2)); - EXPECT_EQ(*Mapping->map(VersionTuple(11, 0), VersionTuple(), None), + EXPECT_EQ(*Mapping->map(VersionTuple(11, 0), VersionTuple(), std::nullopt), VersionTuple(11, 0)); // Verify that an iOS version that's not present in the map is translated // like the nearest major OS version. - EXPECT_EQ(*Mapping->map(VersionTuple(10, 1), VersionTuple(), None), + EXPECT_EQ(*Mapping->map(VersionTuple(10, 1), VersionTuple(), std::nullopt), VersionTuple(10, 0)); // Verify that the iOS versions that are outside of the mapped version // range map to the min/max values passed to the `map` call. - EXPECT_EQ(*Mapping->map(VersionTuple(9, 0), VersionTuple(99, 99), None), - VersionTuple(99, 99)); + EXPECT_EQ( + *Mapping->map(VersionTuple(9, 0), VersionTuple(99, 99), std::nullopt), + VersionTuple(99, 99)); EXPECT_EQ( *Mapping->map(VersionTuple(13, 0), VersionTuple(), VersionTuple(99, 99)), VersionTuple(99, 99)); diff --git a/clang/unittests/Basic/FileEntryTest.cpp b/clang/unittests/Basic/FileEntryTest.cpp index 4249a3d550148..b1755e07f48fc 100644 --- a/clang/unittests/Basic/FileEntryTest.cpp +++ b/clang/unittests/Basic/FileEntryTest.cpp @@ -93,7 +93,7 @@ TEST(FileEntryTest, OptionalFileEntryRefDegradesToFileEntryPtr) { OptionalFileEntryRefDegradesToFileEntryPtr M0; OptionalFileEntryRefDegradesToFileEntryPtr M1 = Refs.addFile("1"); OptionalFileEntryRefDegradesToFileEntryPtr M2 = Refs.addFile("2"); - OptionalFileEntryRefDegradesToFileEntryPtr M0Also = None; + OptionalFileEntryRefDegradesToFileEntryPtr M0Also = std::nullopt; OptionalFileEntryRefDegradesToFileEntryPtr M1Also = Refs.addFileAlias("1-also", *M1); diff --git a/clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp b/clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp index 3a73f39e73b3c..62faf032a3ee7 100644 --- a/clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp +++ b/clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp @@ -183,7 +183,7 @@ struct VerifyingConsumer { return true; if (!UnexpectedInitial.empty() || !UnexpectedNonInitial.empty()) return false; - return llvm::None; + return std::nullopt; } // This method is used by tests. diff --git a/clang/unittests/Frontend/ASTUnitTest.cpp b/clang/unittests/Frontend/ASTUnitTest.cpp index 1bfc957f21bfa..f3859536f368c 100644 --- a/clang/unittests/Frontend/ASTUnitTest.cpp +++ b/clang/unittests/Frontend/ASTUnitTest.cpp @@ -168,9 +168,9 @@ TEST_F(ASTUnitTest, LoadFromCommandLineEarlyError) { ASTUnit *AST = ASTUnit::LoadFromCommandLine( &Args[0], &Args[4], PCHContainerOps, Diags, "", false, - CaptureDiagsKind::All, None, true, 0, TU_Complete, false, false, false, - SkipFunctionBodiesScope::None, false, true, false, false, None, &ErrUnit, - nullptr); + CaptureDiagsKind::All, std::nullopt, true, 0, TU_Complete, false, false, + false, SkipFunctionBodiesScope::None, false, true, false, false, + std::nullopt, &ErrUnit, nullptr); ASSERT_EQ(AST, nullptr); ASSERT_NE(ErrUnit, nullptr); diff --git a/clang/unittests/Lex/HeaderSearchTest.cpp b/clang/unittests/Lex/HeaderSearchTest.cpp index 939f5a7210d8a..e67445f1aeadc 100644 --- a/clang/unittests/Lex/HeaderSearchTest.cpp +++ b/clang/unittests/Lex/HeaderSearchTest.cpp @@ -38,8 +38,9 @@ class HeaderSearchTest : public ::testing::Test { } void addSearchDir(llvm::StringRef Dir) { - VFS->addFile(Dir, 0, llvm::MemoryBuffer::getMemBuffer(""), /*User=*/None, - /*Group=*/None, llvm::sys::fs::file_type::directory_file); + VFS->addFile( + Dir, 0, llvm::MemoryBuffer::getMemBuffer(""), /*User=*/std::nullopt, + /*Group=*/std::nullopt, llvm::sys::fs::file_type::directory_file); auto DE = FileMgr.getOptionalDirectoryRef(Dir); assert(DE); auto DL = DirectoryLookup(*DE, SrcMgr::C_User, /*isFramework=*/false); @@ -47,8 +48,9 @@ class HeaderSearchTest : public ::testing::Test { } void addSystemFrameworkSearchDir(llvm::StringRef Dir) { - VFS->addFile(Dir, 0, llvm::MemoryBuffer::getMemBuffer(""), /*User=*/None, - /*Group=*/None, llvm::sys::fs::file_type::directory_file); + VFS->addFile( + Dir, 0, llvm::MemoryBuffer::getMemBuffer(""), /*User=*/std::nullopt, + /*Group=*/std::nullopt, llvm::sys::fs::file_type::directory_file); auto DE = FileMgr.getOptionalDirectoryRef(Dir); assert(DE); auto DL = DirectoryLookup(*DE, SrcMgr::C_System, /*isFramework=*/true); @@ -58,7 +60,8 @@ class HeaderSearchTest : public ::testing::Test { void addHeaderMap(llvm::StringRef Filename, std::unique_ptr<llvm::MemoryBuffer> Buf, bool isAngled = false) { - VFS->addFile(Filename, 0, std::move(Buf), /*User=*/None, /*Group=*/None, + VFS->addFile(Filename, 0, std::move(Buf), /*User=*/std::nullopt, + /*Group=*/std::nullopt, llvm::sys::fs::file_type::regular_file); auto FE = FileMgr.getFile(Filename, true); assert(FE); @@ -197,9 +200,10 @@ TEST_F(HeaderSearchTest, NestedFramework) { TEST_F(HeaderSearchTest, HeaderFrameworkLookup) { std::string HeaderPath = "/tmp/Frameworks/Foo.framework/Headers/Foo.h"; addSystemFrameworkSearchDir("/tmp/Frameworks"); - VFS->addFile( - HeaderPath, 0, llvm::MemoryBuffer::getMemBufferCopy("", HeaderPath), - /*User=*/None, /*Group=*/None, llvm::sys::fs::file_type::regular_file); + VFS->addFile(HeaderPath, 0, + llvm::MemoryBuffer::getMemBufferCopy("", HeaderPath), + /*User=*/std::nullopt, /*Group=*/std::nullopt, + llvm::sys::fs::file_type::regular_file); bool IsFrameworkFound = false; auto FoundFile = Search.LookupFile( @@ -267,7 +271,8 @@ TEST_F(HeaderSearchTest, HeaderMapFrameworkLookup) { VFS->addFile( HeaderDirName + HeaderName, 0, llvm::MemoryBuffer::getMemBufferCopy("", HeaderDirName + HeaderName), - /*User=*/None, /*Group=*/None, llvm::sys::fs::file_type::regular_file); + /*User=*/std::nullopt, /*Group=*/std::nullopt, + llvm::sys::fs::file_type::regular_file); bool IsMapped = false; auto FoundFile = Search.LookupFile( diff --git a/clang/unittests/Serialization/SourceLocationEncodingTest.cpp b/clang/unittests/Serialization/SourceLocationEncodingTest.cpp index 3839def0c6005..f33a909a65335 100644 --- a/clang/unittests/Serialization/SourceLocationEncodingTest.cpp +++ b/clang/unittests/Serialization/SourceLocationEncodingTest.cpp @@ -21,7 +21,7 @@ using LocSeq = SourceLocationSequence; // If ExpectedEncoded is provided, verify the encoded value too. // Loc is the raw (in-memory) form of SourceLocation. void roundTrip(SourceLocation::UIntTy Loc, - llvm::Optional<uint64_t> ExpectedEncoded = llvm::None) { + llvm::Optional<uint64_t> ExpectedEncoded = std::nullopt) { uint64_t ActualEncoded = SourceLocationEncoding::encode(SourceLocation::getFromRawEncoding(Loc)); if (ExpectedEncoded) diff --git a/clang/unittests/StaticAnalyzer/CallDescriptionTest.cpp b/clang/unittests/StaticAnalyzer/CallDescriptionTest.cpp index bfdb357d60aab..991a45d30103b 100644 --- a/clang/unittests/StaticAnalyzer/CallDescriptionTest.cpp +++ b/clang/unittests/StaticAnalyzer/CallDescriptionTest.cpp @@ -153,7 +153,7 @@ TEST(CallDescription, RequiredArguments) { TEST(CallDescription, LackOfRequiredArguments) { EXPECT_TRUE(tooling::runToolOnCode( std::unique_ptr<FrontendAction>(new CallDescriptionAction<>({ - {{"foo", None}, true}, + {{"foo", std::nullopt}, true}, {{"foo", 2}, false}, })), "void foo(int); void foo(int, int); void bar() { foo(1); }")); diff --git a/clang/unittests/Tooling/ASTSelectionTest.cpp b/clang/unittests/Tooling/ASTSelectionTest.cpp index 531f9ac89f441..430562e9d2e0f 100644 --- a/clang/unittests/Tooling/ASTSelectionTest.cpp +++ b/clang/unittests/Tooling/ASTSelectionTest.cpp @@ -149,13 +149,13 @@ ForAllChildrenOf allChildrenOf(const SelectedASTNode &Node) { TEST(ASTSelectionFinder, CursorNoSelection) { findSelectedASTNodes( - " void f() { }", {1, 1}, None, + " void f() { }", {1, 1}, std::nullopt, [](Optional<SelectedASTNode> Node) { EXPECT_FALSE(Node); }); } TEST(ASTSelectionFinder, CursorAtStartOfFunction) { findSelectedASTNodes( - "void f() { }", {1, 1}, None, [](Optional<SelectedASTNode> Node) { + "void f() { }", {1, 1}, std::nullopt, [](Optional<SelectedASTNode> Node) { EXPECT_TRUE(Node); checkNode<TranslationUnitDecl>(*Node, SourceSelectionKind::None, /*NumChildren=*/1); @@ -525,15 +525,15 @@ TEST(ASTSelectionFinder, CorrectEndForObjectiveCImplementation) { @ end )"; // Just after '@ end' - findSelectedASTNodes(Source, {5, 6}, None, - [](Optional<SelectedASTNode> Node) { - EXPECT_TRUE(Node); - EXPECT_EQ(Node->Children.size(), 1u); - checkNode<ObjCImplementationDecl>( - Node->Children[0], - SourceSelectionKind::ContainsSelection); - }, - SelectionFinderVisitor::Lang_OBJC); + findSelectedASTNodes( + Source, {5, 6}, std::nullopt, + [](Optional<SelectedASTNode> Node) { + EXPECT_TRUE(Node); + EXPECT_EQ(Node->Children.size(), 1u); + checkNode<ObjCImplementationDecl>( + Node->Children[0], SourceSelectionKind::ContainsSelection); + }, + SelectionFinderVisitor::Lang_OBJC); } const SelectedASTNode &checkFnBody(const Optional<SelectedASTNode> &Node, @@ -688,7 +688,7 @@ void f2() { )"; // No selection range. findSelectedASTNodesWithRange( - Source, {2, 2}, None, + Source, {2, 2}, std::nullopt, [](SourceRange SelectionRange, Optional<SelectedASTNode> Node) { EXPECT_TRUE(Node); Optional<CodeRangeASTSelection> SelectedCode = diff --git a/clang/unittests/Tooling/HeaderAnalysisTest.cpp b/clang/unittests/Tooling/HeaderAnalysisTest.cpp index c6ba625c0c062..a2096d00d7e50 100644 --- a/clang/unittests/Tooling/HeaderAnalysisTest.cpp +++ b/clang/unittests/Tooling/HeaderAnalysisTest.cpp @@ -66,11 +66,11 @@ TEST(HeaderAnalysisTest, ParseIWYUPragma) { EXPECT_THAT(parseIWYUPragma("// IWYU pragma: keep me\netc"), ValueIs(Eq("keep me"))); EXPECT_THAT(parseIWYUPragma("/* IWYU pragma: keep */"), ValueIs(Eq("keep"))); - EXPECT_EQ(parseIWYUPragma("// IWYU pragma: keep"), llvm::None) + EXPECT_EQ(parseIWYUPragma("// IWYU pragma: keep"), std::nullopt) << "Prefix is sensitive to whitespace"; - EXPECT_EQ(parseIWYUPragma("// IWYU pragma:keep"), llvm::None) + EXPECT_EQ(parseIWYUPragma("// IWYU pragma:keep"), std::nullopt) << "Prefix is sensitive to whitespace"; - EXPECT_EQ(parseIWYUPragma("/\n* IWYU pragma: keep */"), llvm::None) + EXPECT_EQ(parseIWYUPragma("/\n* IWYU pragma: keep */"), std::nullopt) << "Must start with /* or //"; } diff --git a/clang/unittests/Tooling/SourceCodeBuildersTest.cpp b/clang/unittests/Tooling/SourceCodeBuildersTest.cpp index 50167881e5cd6..a65f6d961185a 100644 --- a/clang/unittests/Tooling/SourceCodeBuildersTest.cpp +++ b/clang/unittests/Tooling/SourceCodeBuildersTest.cpp @@ -71,14 +71,14 @@ static llvm::Optional<TestMatch> matchStmt(StringRef StatementCode, {"-Wno-unused-value"}); if (AstUnit == nullptr) { ADD_FAILURE() << "AST construction failed"; - return llvm::None; + return std::nullopt; } ASTContext &Context = AstUnit->getASTContext(); auto Matches = ast_matchers::match(wrapMatcher(Matcher), Context); // We expect a single, exact match for the statement. if (Matches.size() != 1) { ADD_FAILURE() << "Wrong number of matches: " << Matches.size(); - return llvm::None; + return std::nullopt; } return TestMatch{std::move(AstUnit), MatchResult(Matches[0], &Context)}; } diff --git a/clang/unittests/Tooling/StandardLibraryTest.cpp b/clang/unittests/Tooling/StandardLibraryTest.cpp index 64c01b56eab88..01dc58c9ba481 100644 --- a/clang/unittests/Tooling/StandardLibraryTest.cpp +++ b/clang/unittests/Tooling/StandardLibraryTest.cpp @@ -94,13 +94,13 @@ TEST(StdlibTest, Recognizer) { stdlib::Recognizer Recognizer; - EXPECT_EQ(Recognizer(&VectorNonstd), llvm::None); + EXPECT_EQ(Recognizer(&VectorNonstd), std::nullopt); EXPECT_EQ(Recognizer(Vec), stdlib::Symbol::named("std::", "vector")); EXPECT_EQ(Recognizer(Nest), stdlib::Symbol::named("std::", "vector")); EXPECT_EQ(Recognizer(Clock), stdlib::Symbol::named("std::chrono::", "system_clock")); EXPECT_EQ(Recognizer(CDivT), stdlib::Symbol::named("", "div_t")); - EXPECT_EQ(Recognizer(Sec), llvm::None); + EXPECT_EQ(Recognizer(Sec), std::nullopt); } } // namespace diff --git a/clang/unittests/Tooling/StencilTest.cpp b/clang/unittests/Tooling/StencilTest.cpp index 45dab154c7d6b..ee77933c428df 100644 --- a/clang/unittests/Tooling/StencilTest.cpp +++ b/clang/unittests/Tooling/StencilTest.cpp @@ -76,14 +76,14 @@ static llvm::Optional<TestMatch> matchStmt(StringRef StatementCode, wrapSnippet(ExtraPreface, StatementCode), {"-Wno-unused-value"}); if (AstUnit == nullptr) { ADD_FAILURE() << "AST construction failed"; - return llvm::None; + return std::nullopt; } ASTContext &Context = AstUnit->getASTContext(); auto Matches = ast_matchers::match(wrapMatcher(Matcher), Context); // We expect a single, exact match for the statement. if (Matches.size() != 1) { ADD_FAILURE() << "Wrong number of matches: " << Matches.size(); - return llvm::None; + return std::nullopt; } return TestMatch{std::move(AstUnit), MatchResult(Matches[0], &Context)}; } diff --git a/clang/unittests/Tooling/Syntax/TokensTest.cpp b/clang/unittests/Tooling/Syntax/TokensTest.cpp index 85fc837fbe2be..dfda6cbcfe9c0 100644 --- a/clang/unittests/Tooling/Syntax/TokensTest.cpp +++ b/clang/unittests/Tooling/Syntax/TokensTest.cpp @@ -661,10 +661,10 @@ TEST_F(TokenBufferTest, SpelledByExpanded) { EXPECT_THAT(Buffer.spelledForExpanded(findExpanded("b1 b2")), ValueIs(SameRange(findSpelled("split B").drop_front()))); // Ranges not fully covering macro invocations should fail. - EXPECT_EQ(Buffer.spelledForExpanded(findExpanded("a1 a2")), llvm::None); - EXPECT_EQ(Buffer.spelledForExpanded(findExpanded("b2")), llvm::None); + EXPECT_EQ(Buffer.spelledForExpanded(findExpanded("a1 a2")), std::nullopt); + EXPECT_EQ(Buffer.spelledForExpanded(findExpanded("b2")), std::nullopt); EXPECT_EQ(Buffer.spelledForExpanded(findExpanded("a2 a3 split b1 b2")), - llvm::None); + std::nullopt); // Recursive macro invocations. recordTokens(R"cpp( @@ -731,7 +731,7 @@ TEST_F(TokenBufferTest, SpelledByExpanded) { ID2(ID(a1), ID(a2) a3) ID2(a4, a5 a6 a7) )cpp"); // Should fail, spans multiple arguments. - EXPECT_EQ(Buffer.spelledForExpanded(findExpanded("a1 a2")), llvm::None); + EXPECT_EQ(Buffer.spelledForExpanded(findExpanded("a1 a2")), std::nullopt); EXPECT_THAT(Buffer.spelledForExpanded(findExpanded("a2 a3")), ValueIs(SameRange(findSpelled("ID ( a2 ) a3")))); EXPECT_THAT( @@ -742,7 +742,8 @@ TEST_F(TokenBufferTest, SpelledByExpanded) { EXPECT_THAT(Buffer.spelledForExpanded(findExpanded("a4 a5 a6 a7")), ValueIs(SameRange(findSpelled("ID2 ( a4 , a5 a6 a7 )")))); // Should fail, spans multiple invocations. - EXPECT_EQ(Buffer.spelledForExpanded(findExpanded("a1 a2 a3 a4")), llvm::None); + EXPECT_EQ(Buffer.spelledForExpanded(findExpanded("a1 a2 a3 a4")), + std::nullopt); // https://github.com/clangd/clangd/issues/1289 recordTokens(R"cpp( @@ -750,7 +751,7 @@ TEST_F(TokenBufferTest, SpelledByExpanded) { #define INDIRECT FOO(y) INDIRECT // expands to foo(y) )cpp"); - EXPECT_EQ(Buffer.spelledForExpanded(findExpanded("y")), llvm::None); + EXPECT_EQ(Buffer.spelledForExpanded(findExpanded("y")), std::nullopt); recordTokens(R"cpp( #define FOO(X) a X b @@ -776,7 +777,7 @@ TEST_F(TokenBufferTest, SpelledByExpanded) { )cpp"); EXPECT_THAT(Buffer.spelledForExpanded(findExpanded("good")), ValueIs(SameRange(findSpelled("good")))); - EXPECT_EQ(Buffer.spelledForExpanded(findExpanded("bad")), llvm::None); + EXPECT_EQ(Buffer.spelledForExpanded(findExpanded("bad")), std::nullopt); recordTokens(R"cpp( #define PREV prev @@ -787,7 +788,7 @@ TEST_F(TokenBufferTest, SpelledByExpanded) { )cpp"); EXPECT_THAT(Buffer.spelledForExpanded(findExpanded("good")), ValueIs(SameRange(findSpelled("good")))); - EXPECT_EQ(Buffer.spelledForExpanded(findExpanded("bad")), llvm::None); + EXPECT_EQ(Buffer.spelledForExpanded(findExpanded("bad")), std::nullopt); recordTokens(R"cpp( #define ID(X) X @@ -798,7 +799,7 @@ TEST_F(TokenBufferTest, SpelledByExpanded) { )cpp"); EXPECT_THAT(Buffer.spelledForExpanded(findExpanded("good")), ValueIs(SameRange(findSpelled("good")))); - EXPECT_EQ(Buffer.spelledForExpanded(findExpanded("bad")), llvm::None); + EXPECT_EQ(Buffer.spelledForExpanded(findExpanded("bad")), std::nullopt); } TEST_F(TokenBufferTest, ExpandedTokensForRange) { @@ -856,7 +857,7 @@ TEST_F(TokenBufferTest, ExpansionsOverlapping) { SameRange(findExpanded("1 + 2 + 3"))))); // Only the first spelled token should be found. for (const auto &T : ID1.drop_front()) - EXPECT_EQ(Buffer.expansionStartingAt(&T), llvm::None); + EXPECT_EQ(Buffer.expansionStartingAt(&T), std::nullopt); llvm::ArrayRef<syntax::Token> ID2 = findSpelled("ID ( ID ( 2 + 3 + 4 ) )"); EXPECT_THAT(Buffer.expansionStartingAt(&ID2.front()), @@ -864,7 +865,7 @@ TEST_F(TokenBufferTest, ExpansionsOverlapping) { SameRange(findExpanded("2 + 3 + 4"))))); // Only the first spelled token should be found. for (const auto &T : ID2.drop_front()) - EXPECT_EQ(Buffer.expansionStartingAt(&T), llvm::None); + EXPECT_EQ(Buffer.expansionStartingAt(&T), std::nullopt); EXPECT_THAT(Buffer.expansionsOverlapping(llvm::makeArrayRef( findSpelled("1 + 2").data(), findSpelled("4").data())), @@ -886,7 +887,7 @@ int b = 1; SameRange(findExpanded("int a").take_front(0))))); // Only the first spelled token should be found. for (const auto &T : DefineFoo.drop_front()) - EXPECT_EQ(Buffer.expansionStartingAt(&T), llvm::None); + EXPECT_EQ(Buffer.expansionStartingAt(&T), std::nullopt); llvm::ArrayRef<syntax::Token> PragmaOnce = findSpelled("# pragma once"); EXPECT_THAT( @@ -895,7 +896,7 @@ int b = 1; SameRange(findExpanded("int b").take_front(0))))); // Only the first spelled token should be found. for (const auto &T : PragmaOnce.drop_front()) - EXPECT_EQ(Buffer.expansionStartingAt(&T), llvm::None); + EXPECT_EQ(Buffer.expansionStartingAt(&T), std::nullopt); EXPECT_THAT( Buffer.expansionsOverlapping(findSpelled("FOO ; # pragma")), diff --git a/clang/unittests/Tooling/TransformerTest.cpp b/clang/unittests/Tooling/TransformerTest.cpp index 73672820e1ddc..6d6ed33d8fd67 100644 --- a/clang/unittests/Tooling/TransformerTest.cpp +++ b/clang/unittests/Tooling/TransformerTest.cpp @@ -110,18 +110,18 @@ class ClangRefactoringTestBase : public testing::Test { "clang-tool", std::make_shared<PCHContainerOperations>(), FileContents)) { llvm::errs() << "Running tool failed.\n"; - return None; + return std::nullopt; } if (ErrorCount != 0) { llvm::errs() << "Generating changes failed.\n"; - return None; + return std::nullopt; } auto ChangedCode = applyAtomicChanges("input.cc", Code, Changes, ApplyChangesSpec()); if (!ChangedCode) { llvm::errs() << "Applying changes failed: " << llvm::toString(ChangedCode.takeError()) << "\n"; - return None; + return std::nullopt; } return *ChangedCode; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits