[PATCH] D92109: [ASTImporter] Support import of CXXDeductionGuideDecl
martong added inline comments. Comment at: clang/lib/AST/ASTImporter.cpp:3336 +if (Fun->getExplicitSpecifier().getExpr()) { + ExplicitExpr = importChecked(Err, Fun->getExplicitSpecifier().getExpr()); + if (Err) rnk wrote: > GCC 5.3 complained about this, so I rewrote it a different way without > generic lambdas in rG43b5b485a203f190ee4d5d3cab19c44ca865d316. > > Error spew: > ``` > FAILED: tools/clang/lib/AST/CMakeFiles/obj.clangAST.dir/ASTImporter.cpp.o > /b/s/w/ir/cache/builder/src/third_party/llvm-build-tools/gcc530trusty/bin/g++ > -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS > -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools/clang/lib/AST > -I/b/s/w/ir/cache/builder/src/third_party/llvm/clang/lib/AST > -I/b/s/w/ir/cache/builder/src/third_party/llvm/clang/include > -Itools/clang/include -Iinclude > -I/b/s/w/ir/cache/builder/src/third_party/llvm/llvm/include > -DLLVM_FORCE_HEAD_REVISION -fvisibility-inlines-hidden -Werror=date-time > -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual > -Wno-missing-field-initializers -pedantic -Wno-long-long > -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment > -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common > -Woverloaded-virtual -fno-strict-aliasing -O3 -fno-exceptions > -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -UNDEBUG > -std=c++14 -MD -MT > tools/clang/lib/AST/CMakeFiles/obj.clangAST.dir/ASTImporter.cpp.o -MF > tools/clang/lib/AST/CMakeFiles/obj.clangAST.dir/ASTImporter.cpp.o.d -o > tools/clang/lib/AST/CMakeFiles/obj.clangAST.dir/ASTImporter.cpp.o -c > /b/s/w/ir/cache/builder/src/third_party/llvm/clang/lib/AST/ASTImporter.cpp > /b/s/w/ir/cache/builder/src/third_party/llvm/clang/lib/AST/ASTImporter.cpp: > In instantiation of > ‘clang::ASTNodeImporter::VisitFunctionDecl(clang::FunctionDecl*):: > [with auto:1 = clang::CXXConversionDecl; clang::ExpectedExpr = > llvm::Expected]’: > /b/s/w/ir/cache/builder/src/third_party/llvm/clang/lib/AST/ASTImporter.cpp:3384:66: >required from here > /b/s/w/ir/cache/builder/src/third_party/llvm/clang/lib/AST/ASTImporter.cpp:3336:20: > error: cannot call member function ‘T > clang::ASTNodeImporter::importChecked(llvm::Error&, const T&) [with T = > clang::Expr*]’ without object >ExplicitExpr = importChecked(Err, > Fun->getExplicitSpecifier().getExpr()); > ^ > /b/s/w/ir/cache/builder/src/third_party/llvm/clang/lib/AST/ASTImporter.cpp: > In instantiation of > ‘clang::ASTNodeImporter::VisitFunctionDecl(clang::FunctionDecl*):: > [with auto:1 = clang::CXXDeductionGuideDecl; clang::ExpectedExpr = > llvm::Expected]’: > /b/s/w/ir/cache/builder/src/third_party/llvm/clang/lib/AST/ASTImporter.cpp:3402:57: >required from here > /b/s/w/ir/cache/builder/src/third_party/llvm/clang/lib/AST/ASTImporter.cpp:3336:20: > error: cannot call member function ‘T > clang::ASTNodeImporter::importChecked(llvm::Error&, const T&) [with T = > clang::Expr*]’ without object > [3456/5141] Building CXX object > tools/clang/lib/AST/CMakeFiles/obj.clangAST.dir/InheritViz.cpp.o > ``` Thanks, post-commit looks good! Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D92109/new/ https://reviews.llvm.org/D92109 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D92109: [ASTImporter] Support import of CXXDeductionGuideDecl
rnk added inline comments. Comment at: clang/lib/AST/ASTImporter.cpp:3336 +if (Fun->getExplicitSpecifier().getExpr()) { + ExplicitExpr = importChecked(Err, Fun->getExplicitSpecifier().getExpr()); + if (Err) GCC 5.3 complained about this, so I rewrote it a different way without generic lambdas in rG43b5b485a203f190ee4d5d3cab19c44ca865d316. Error spew: ``` FAILED: tools/clang/lib/AST/CMakeFiles/obj.clangAST.dir/ASTImporter.cpp.o /b/s/w/ir/cache/builder/src/third_party/llvm-build-tools/gcc530trusty/bin/g++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools/clang/lib/AST -I/b/s/w/ir/cache/builder/src/third_party/llvm/clang/lib/AST -I/b/s/w/ir/cache/builder/src/third_party/llvm/clang/include -Itools/clang/include -Iinclude -I/b/s/w/ir/cache/builder/src/third_party/llvm/llvm/include -DLLVM_FORCE_HEAD_REVISION -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -fno-strict-aliasing -O3 -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -UNDEBUG -std=c++14 -MD -MT tools/clang/lib/AST/CMakeFiles/obj.clangAST.dir/ASTImporter.cpp.o -MF tools/clang/lib/AST/CMakeFiles/obj.clangAST.dir/ASTImporter.cpp.o.d -o tools/clang/lib/AST/CMakeFiles/obj.clangAST.dir/ASTImporter.cpp.o -c /b/s/w/ir/cache/builder/src/third_party/llvm/clang/lib/AST/ASTImporter.cpp /b/s/w/ir/cache/builder/src/third_party/llvm/clang/lib/AST/ASTImporter.cpp: In instantiation of ‘clang::ASTNodeImporter::VisitFunctionDecl(clang::FunctionDecl*):: [with auto:1 = clang::CXXConversionDecl; clang::ExpectedExpr = llvm::Expected]’: /b/s/w/ir/cache/builder/src/third_party/llvm/clang/lib/AST/ASTImporter.cpp:3384:66: required from here /b/s/w/ir/cache/builder/src/third_party/llvm/clang/lib/AST/ASTImporter.cpp:3336:20: error: cannot call member function ‘T clang::ASTNodeImporter::importChecked(llvm::Error&, const T&) [with T = clang::Expr*]’ without object ExplicitExpr = importChecked(Err, Fun->getExplicitSpecifier().getExpr()); ^ /b/s/w/ir/cache/builder/src/third_party/llvm/clang/lib/AST/ASTImporter.cpp: In instantiation of ‘clang::ASTNodeImporter::VisitFunctionDecl(clang::FunctionDecl*):: [with auto:1 = clang::CXXDeductionGuideDecl; clang::ExpectedExpr = llvm::Expected]’: /b/s/w/ir/cache/builder/src/third_party/llvm/clang/lib/AST/ASTImporter.cpp:3402:57: required from here /b/s/w/ir/cache/builder/src/third_party/llvm/clang/lib/AST/ASTImporter.cpp:3336:20: error: cannot call member function ‘T clang::ASTNodeImporter::importChecked(llvm::Error&, const T&) [with T = clang::Expr*]’ without object [3456/5141] Building CXX object tools/clang/lib/AST/CMakeFiles/obj.clangAST.dir/InheritViz.cpp.o ``` Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D92109/new/ https://reviews.llvm.org/D92109 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D92109: [ASTImporter] Support import of CXXDeductionGuideDecl
This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG70eb2ce395be: [ASTImporter] Support import of CXXDeductionGuideDecl (authored by martong). Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D92109/new/ https://reviews.llvm.org/D92109 Files: clang/lib/AST/ASTImporter.cpp clang/unittests/AST/ASTImporterTest.cpp Index: clang/unittests/AST/ASTImporterTest.cpp === --- clang/unittests/AST/ASTImporterTest.cpp +++ clang/unittests/AST/ASTImporterTest.cpp @@ -5957,6 +5957,47 @@ EXPECT_EQ(Record, CompletedTags.front()); } +TEST_P(ImportFunctions, CTADImplicit) { + Decl *FromTU = getTuDecl( + R"( + template struct A { +A(T); + }; + A a{(int)0}; + )", + Lang_CXX17, "input.cc"); + auto *FromD = FirstDeclMatcher().match( + FromTU, + cxxDeductionGuideDecl(hasParameter(0, hasType(asString("A"); + auto *ToD = Import(FromD, Lang_CXX17); + ASSERT_TRUE(ToD); + EXPECT_TRUE(ToD->isCopyDeductionCandidate()); + // Check that the deduced class template is also imported. + EXPECT_TRUE(findFromTU(FromD)->Importer->GetAlreadyImportedOrNull( + FromD->getDeducedTemplate())); +} + +TEST_P(ImportFunctions, CTADUserDefinedExplicit) { + Decl *FromTU = getTuDecl( + R"( + template struct A { +A(T); + }; + template explicit A(T) -> A; + A a{(int)0}; // calls A::A(float) + )", + Lang_CXX17, "input.cc"); + auto *FromD = FirstDeclMatcher().match( + FromTU, cxxDeductionGuideDecl(unless(isImplicit(; + // Not-implicit: i.e. not compiler-generated, user defined. + ASSERT_FALSE(FromD->isImplicit()); + ASSERT_TRUE(FromD->isExplicit()); // Has the explicit keyword. + auto *ToD = Import(FromD, Lang_CXX17); + ASSERT_TRUE(ToD); + EXPECT_FALSE(FromD->isImplicit()); + EXPECT_TRUE(ToD->isExplicit()); +} + INSTANTIATE_TEST_CASE_P(ParameterizedTests, ASTImporterLookupTableTest, DefaultTestValuesForRunOptions, ); Index: clang/lib/AST/ASTImporter.cpp === --- clang/lib/AST/ASTImporter.cpp +++ clang/lib/AST/ASTImporter.cpp @@ -499,6 +499,7 @@ ExpectedDecl VisitCXXConstructorDecl(CXXConstructorDecl *D); ExpectedDecl VisitCXXDestructorDecl(CXXDestructorDecl *D); ExpectedDecl VisitCXXConversionDecl(CXXConversionDecl *D); +ExpectedDecl VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D); ExpectedDecl VisitFieldDecl(FieldDecl *D); ExpectedDecl VisitIndirectFieldDecl(IndirectFieldDecl *D); ExpectedDecl VisitFriendDecl(FriendDecl *D); @@ -3328,6 +3329,17 @@ return ToPOrErr.takeError(); } + // Common code to import an explicit specifier of different kind of functions. + auto ImportExplicitExpr = [this, ](auto *Fun) -> ExpectedExpr { +Expr *ExplicitExpr = nullptr; +if (Fun->getExplicitSpecifier().getExpr()) { + ExplicitExpr = importChecked(Err, Fun->getExplicitSpecifier().getExpr()); + if (Err) +return std::move(Err); +} +return ExplicitExpr; + }; + // Create the imported function. FunctionDecl *ToFunction = nullptr; if (auto *FromConstructor = dyn_cast(D)) { @@ -3369,17 +3381,13 @@ ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg); } else if (CXXConversionDecl *FromConversion = dyn_cast(D)) { -Expr *ExplicitExpr = nullptr; -if (FromConversion->getExplicitSpecifier().getExpr()) { - auto Imp = import(FromConversion->getExplicitSpecifier().getExpr()); - if (!Imp) -return Imp.takeError(); - ExplicitExpr = *Imp; -} +ExpectedExpr ExplicitExpr = ImportExplicitExpr(FromConversion); +if (!ExplicitExpr) + return ExplicitExpr.takeError(); if (GetImportedOrCreateDecl( ToFunction, D, Importer.getToContext(), cast(DC), ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), -ExplicitSpecifier(ExplicitExpr, +ExplicitSpecifier(*ExplicitExpr, FromConversion->getExplicitSpecifier().getKind()), D->getConstexprKind(), SourceLocation(), TrailingRequiresClause)) return ToFunction; @@ -3390,6 +3398,18 @@ Method->isInlineSpecified(), D->getConstexprKind(), SourceLocation(), TrailingRequiresClause)) return ToFunction; + } else if (auto *Guide = dyn_cast(D)) { +ExpectedExpr ExplicitExpr = ImportExplicitExpr(Guide); +if (!ExplicitExpr) + return ExplicitExpr.takeError(); +if (GetImportedOrCreateDecl( +ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, +ExplicitSpecifier(*ExplicitExpr, + Guide->getExplicitSpecifier().getKind()), +NameInfo, T, TInfo, ToEndLoc)) +
[PATCH] D92109: [ASTImporter] Support import of CXXDeductionGuideDecl
martong added inline comments. Comment at: clang/unittests/AST/ASTImporterTest.cpp:5900 + ASSERT_TRUE(ToD); + EXPECT_EQ(FromD->isCopyDeductionCandidate(), ToD->isCopyDeductionCandidate()); + // Check that the deduced class template is also imported. teemperor wrote: > Not sure if that's actually testing what it should. `FromD` is not the copy > deduction candidate, so this is just comparing that both Decls have the > default value `false`? > > If we pick the copy deduction candidate in this test then we could test that > we actually copy the value over and not just have the default 'false' flag > for `isCopyDeductionCandidate` (something like > `cxxDeductionGuideDecl(hasParameter(0, hasType(asString("A"` should > find the copy deduction candidate). > > Then we could also simplify this to > `EXPECT_TRUE(ToD->isCopyDeductionCandidate());`. Yeah, good point, updated so. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D92109/new/ https://reviews.llvm.org/D92109 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D92109: [ASTImporter] Support import of CXXDeductionGuideDecl
martong updated this revision to Diff 307988. martong marked 2 inline comments as done. martong added a comment. - Update test to match the copy deduction guide Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D92109/new/ https://reviews.llvm.org/D92109 Files: clang/lib/AST/ASTImporter.cpp clang/unittests/AST/ASTImporterTest.cpp Index: clang/unittests/AST/ASTImporterTest.cpp === --- clang/unittests/AST/ASTImporterTest.cpp +++ clang/unittests/AST/ASTImporterTest.cpp @@ -5884,6 +5884,47 @@ EXPECT_EQ(Record, CompletedTags.front()); } +TEST_P(ImportFunctions, CTADImplicit) { + Decl *FromTU = getTuDecl( + R"( + template struct A { +A(T); + }; + A a{(int)0}; + )", + Lang_CXX17, "input.cc"); + auto *FromD = FirstDeclMatcher().match( + FromTU, + cxxDeductionGuideDecl(hasParameter(0, hasType(asString("A"); + auto *ToD = Import(FromD, Lang_CXX17); + ASSERT_TRUE(ToD); + EXPECT_TRUE(ToD->isCopyDeductionCandidate()); + // Check that the deduced class template is also imported. + EXPECT_TRUE(findFromTU(FromD)->Importer->GetAlreadyImportedOrNull( + FromD->getDeducedTemplate())); +} + +TEST_P(ImportFunctions, CTADUserDefinedExplicit) { + Decl *FromTU = getTuDecl( + R"( + template struct A { +A(T); + }; + template explicit A(T) -> A; + A a{(int)0}; // calls A::A(float) + )", + Lang_CXX17, "input.cc"); + auto *FromD = FirstDeclMatcher().match( + FromTU, cxxDeductionGuideDecl(unless(isImplicit(; + // Not-implicit: i.e. not compiler-generated, user defined. + ASSERT_FALSE(FromD->isImplicit()); + ASSERT_TRUE(FromD->isExplicit()); // Has the explicit keyword. + auto *ToD = Import(FromD, Lang_CXX17); + ASSERT_TRUE(ToD); + EXPECT_FALSE(FromD->isImplicit()); + EXPECT_TRUE(ToD->isExplicit()); +} + INSTANTIATE_TEST_CASE_P(ParameterizedTests, ASTImporterLookupTableTest, DefaultTestValuesForRunOptions, ); Index: clang/lib/AST/ASTImporter.cpp === --- clang/lib/AST/ASTImporter.cpp +++ clang/lib/AST/ASTImporter.cpp @@ -499,6 +499,7 @@ ExpectedDecl VisitCXXConstructorDecl(CXXConstructorDecl *D); ExpectedDecl VisitCXXDestructorDecl(CXXDestructorDecl *D); ExpectedDecl VisitCXXConversionDecl(CXXConversionDecl *D); +ExpectedDecl VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D); ExpectedDecl VisitFieldDecl(FieldDecl *D); ExpectedDecl VisitIndirectFieldDecl(IndirectFieldDecl *D); ExpectedDecl VisitFriendDecl(FriendDecl *D); @@ -3328,6 +3329,17 @@ return ToPOrErr.takeError(); } + // Common code to import an explicit specifier of different kind of functions. + auto ImportExplicitExpr = [this, ](auto *Fun) -> ExpectedExpr { +Expr *ExplicitExpr = nullptr; +if (Fun->getExplicitSpecifier().getExpr()) { + ExplicitExpr = importChecked(Err, Fun->getExplicitSpecifier().getExpr()); + if (Err) +return std::move(Err); +} +return ExplicitExpr; + }; + // Create the imported function. FunctionDecl *ToFunction = nullptr; if (auto *FromConstructor = dyn_cast(D)) { @@ -3369,17 +3381,13 @@ ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg); } else if (CXXConversionDecl *FromConversion = dyn_cast(D)) { -Expr *ExplicitExpr = nullptr; -if (FromConversion->getExplicitSpecifier().getExpr()) { - auto Imp = import(FromConversion->getExplicitSpecifier().getExpr()); - if (!Imp) -return Imp.takeError(); - ExplicitExpr = *Imp; -} +ExpectedExpr ExplicitExpr = ImportExplicitExpr(FromConversion); +if (!ExplicitExpr) + return ExplicitExpr.takeError(); if (GetImportedOrCreateDecl( ToFunction, D, Importer.getToContext(), cast(DC), ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), -ExplicitSpecifier(ExplicitExpr, +ExplicitSpecifier(*ExplicitExpr, FromConversion->getExplicitSpecifier().getKind()), D->getConstexprKind(), SourceLocation(), TrailingRequiresClause)) return ToFunction; @@ -3390,6 +3398,18 @@ Method->isInlineSpecified(), D->getConstexprKind(), SourceLocation(), TrailingRequiresClause)) return ToFunction; + } else if (auto *Guide = dyn_cast(D)) { +ExpectedExpr ExplicitExpr = ImportExplicitExpr(Guide); +if (!ExplicitExpr) + return ExplicitExpr.takeError(); +if (GetImportedOrCreateDecl( +ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, +ExplicitSpecifier(*ExplicitExpr, + Guide->getExplicitSpecifier().getKind()), +NameInfo, T, TInfo, ToEndLoc)) + return ToFunction; +cast(ToFunction) +
[PATCH] D92109: [ASTImporter] Support import of CXXDeductionGuideDecl
teemperor accepted this revision. teemperor added a comment. This revision is now accepted and ready to land. I think the test could be made a bit stricter (see inline comment), but otherwise this LGTM. Thanks! Comment at: clang/unittests/AST/ASTImporterTest.cpp:5900 + ASSERT_TRUE(ToD); + EXPECT_EQ(FromD->isCopyDeductionCandidate(), ToD->isCopyDeductionCandidate()); + // Check that the deduced class template is also imported. Not sure if that's actually testing what it should. `FromD` is not the copy deduction candidate, so this is just comparing that both Decls have the default value `false`? If we pick the copy deduction candidate in this test then we could test that we actually copy the value over and not just have the default 'false' flag for `isCopyDeductionCandidate` (something like `cxxDeductionGuideDecl(hasParameter(0, hasType(asString("A"` should find the copy deduction candidate). Then we could also simplify this to `EXPECT_TRUE(ToD->isCopyDeductionCandidate());`. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D92109/new/ https://reviews.llvm.org/D92109 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D92109: [ASTImporter] Support import of CXXDeductionGuideDecl
martong added a comment. Thanks for the review! Your comment made me think about whether we handle the deduced template class properly (`getDeducedTemplate`). Then I realized we do import that when we import the `DeclarationName`. Anyway I added a check for that in the test. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D92109/new/ https://reviews.llvm.org/D92109 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D92109: [ASTImporter] Support import of CXXDeductionGuideDecl
martong updated this revision to Diff 307848. martong added a comment. - Add test for user-defined ctad - Handle IsCopyDeductionCandidate - Fix typo Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D92109/new/ https://reviews.llvm.org/D92109 Files: clang/lib/AST/ASTImporter.cpp clang/unittests/AST/ASTImporterTest.cpp Index: clang/unittests/AST/ASTImporterTest.cpp === --- clang/unittests/AST/ASTImporterTest.cpp +++ clang/unittests/AST/ASTImporterTest.cpp @@ -5884,6 +5884,46 @@ EXPECT_EQ(Record, CompletedTags.front()); } +TEST_P(ImportFunctions, CTADImplicit) { + Decl *FromTU = getTuDecl( + R"( + template struct A { +A(T); + }; + A a{(int)0}; + )", + Lang_CXX17, "input.cc"); + auto *FromD = FirstDeclMatcher().match( + FromTU, cxxDeductionGuideDecl()); + auto *ToD = Import(FromD, Lang_CXX17); + ASSERT_TRUE(ToD); + EXPECT_EQ(FromD->isCopyDeductionCandidate(), ToD->isCopyDeductionCandidate()); + // Check that the deduced class template is also imported. + EXPECT_TRUE(findFromTU(FromD)->Importer->GetAlreadyImportedOrNull( + FromD->getDeducedTemplate())); +} + +TEST_P(ImportFunctions, CTADUserDefinedExplicit) { + Decl *FromTU = getTuDecl( + R"( + template struct A { +A(T); + }; + template explicit A(T) -> A; + A a{(int)0}; // calls A::A(float) + )", + Lang_CXX17, "input.cc"); + auto *FromD = FirstDeclMatcher().match( + FromTU, cxxDeductionGuideDecl(unless(isImplicit(; + // Not-implicit: i.e. not compiler-generated, user defined. + ASSERT_FALSE(FromD->isImplicit()); + ASSERT_TRUE(FromD->isExplicit()); // Has the explicit keyword. + auto *ToD = Import(FromD, Lang_CXX17); + ASSERT_TRUE(ToD); + EXPECT_FALSE(FromD->isImplicit()); + EXPECT_TRUE(ToD->isExplicit()); +} + INSTANTIATE_TEST_CASE_P(ParameterizedTests, ASTImporterLookupTableTest, DefaultTestValuesForRunOptions, ); Index: clang/lib/AST/ASTImporter.cpp === --- clang/lib/AST/ASTImporter.cpp +++ clang/lib/AST/ASTImporter.cpp @@ -499,6 +499,7 @@ ExpectedDecl VisitCXXConstructorDecl(CXXConstructorDecl *D); ExpectedDecl VisitCXXDestructorDecl(CXXDestructorDecl *D); ExpectedDecl VisitCXXConversionDecl(CXXConversionDecl *D); +ExpectedDecl VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D); ExpectedDecl VisitFieldDecl(FieldDecl *D); ExpectedDecl VisitIndirectFieldDecl(IndirectFieldDecl *D); ExpectedDecl VisitFriendDecl(FriendDecl *D); @@ -3328,6 +3329,17 @@ return ToPOrErr.takeError(); } + // Common code to import an explicit specifier of different kind of functions. + auto ImportExplicitExpr = [this, ](auto *Fun) -> ExpectedExpr { +Expr *ExplicitExpr = nullptr; +if (Fun->getExplicitSpecifier().getExpr()) { + ExplicitExpr = importChecked(Err, Fun->getExplicitSpecifier().getExpr()); + if (Err) +return std::move(Err); +} +return ExplicitExpr; + }; + // Create the imported function. FunctionDecl *ToFunction = nullptr; if (auto *FromConstructor = dyn_cast(D)) { @@ -3369,17 +3381,13 @@ ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg); } else if (CXXConversionDecl *FromConversion = dyn_cast(D)) { -Expr *ExplicitExpr = nullptr; -if (FromConversion->getExplicitSpecifier().getExpr()) { - auto Imp = import(FromConversion->getExplicitSpecifier().getExpr()); - if (!Imp) -return Imp.takeError(); - ExplicitExpr = *Imp; -} +ExpectedExpr ExplicitExpr = ImportExplicitExpr(FromConversion); +if (!ExplicitExpr) + return ExplicitExpr.takeError(); if (GetImportedOrCreateDecl( ToFunction, D, Importer.getToContext(), cast(DC), ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), -ExplicitSpecifier(ExplicitExpr, +ExplicitSpecifier(*ExplicitExpr, FromConversion->getExplicitSpecifier().getKind()), D->getConstexprKind(), SourceLocation(), TrailingRequiresClause)) return ToFunction; @@ -3390,6 +3398,18 @@ Method->isInlineSpecified(), D->getConstexprKind(), SourceLocation(), TrailingRequiresClause)) return ToFunction; + } else if (auto *Guide = dyn_cast(D)) { +ExpectedExpr ExplicitExpr = ImportExplicitExpr(Guide); +if (!ExplicitExpr) + return ExplicitExpr.takeError(); +if (GetImportedOrCreateDecl( +ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, +ExplicitSpecifier(*ExplicitExpr, + Guide->getExplicitSpecifier().getKind()), +NameInfo, T, TInfo, ToEndLoc)) + return ToFunction; +cast(ToFunction) +
[PATCH] D92109: [ASTImporter] Support import of CXXDeductionGuideDecl
teemperor requested changes to this revision. teemperor added a comment. This revision now requires changes to proceed. You think it's worth it to have a test for a user-specified deduction guide? I think this is missing an 'explicit' deduction guide test, so maybe we could test both things in a single additional test case. Also, IIUC we ignore the IsCopyDeductionCandidate bit when importing and that seems like a potential bug to me (the value is apparently used for some overload resolution logic)? Beside those two things this looks good to me. Comment at: clang/lib/AST/ASTImporter.cpp:3332 + // Common code to import an explicit specifier of different kind of funcitons. + auto ImportExplicitExpr = [this, ](auto *Fun) -> ExpectedExpr { typo "funcitons" Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D92109/new/ https://reviews.llvm.org/D92109 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D92109: [ASTImporter] Support import of CXXDeductionGuideDecl
martong created this revision. martong added reviewers: teemperor, shafik, balazske. Herald added subscribers: cfe-commits, gamesh411, Szelethus, dkrupp, rnkovacs. Herald added a reviewer: a.sidorin. Herald added a project: clang. martong requested review of this revision. CXXDeductionGuideDecl is a FunctionDecl, but its constructor should be called appropriately, at least to set the kind variable properly. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D92109 Files: clang/lib/AST/ASTImporter.cpp clang/unittests/AST/ASTImporterTest.cpp Index: clang/unittests/AST/ASTImporterTest.cpp === --- clang/unittests/AST/ASTImporterTest.cpp +++ clang/unittests/AST/ASTImporterTest.cpp @@ -5884,6 +5884,21 @@ EXPECT_EQ(Record, CompletedTags.front()); } +TEST_P(ImportFunctions, CTAD) { + Decl *FromTU = getTuDecl( + R"( + template struct A { +A(T); + }; + A a{(int)0}; + )", + Lang_CXX17, "input.cc"); + auto *FromD = FirstDeclMatcher().match( + FromTU, cxxDeductionGuideDecl()); + auto *ToD = Import(FromD, Lang_CXX17); + ASSERT_TRUE(ToD); +} + INSTANTIATE_TEST_CASE_P(ParameterizedTests, ASTImporterLookupTableTest, DefaultTestValuesForRunOptions, ); Index: clang/lib/AST/ASTImporter.cpp === --- clang/lib/AST/ASTImporter.cpp +++ clang/lib/AST/ASTImporter.cpp @@ -499,6 +499,7 @@ ExpectedDecl VisitCXXConstructorDecl(CXXConstructorDecl *D); ExpectedDecl VisitCXXDestructorDecl(CXXDestructorDecl *D); ExpectedDecl VisitCXXConversionDecl(CXXConversionDecl *D); +ExpectedDecl VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D); ExpectedDecl VisitFieldDecl(FieldDecl *D); ExpectedDecl VisitIndirectFieldDecl(IndirectFieldDecl *D); ExpectedDecl VisitFriendDecl(FriendDecl *D); @@ -3328,6 +3329,17 @@ return ToPOrErr.takeError(); } + // Common code to import an explicit specifier of different kind of funcitons. + auto ImportExplicitExpr = [this, ](auto *Fun) -> ExpectedExpr { +Expr *ExplicitExpr = nullptr; +if (Fun->getExplicitSpecifier().getExpr()) { + ExplicitExpr = importChecked(Err, Fun->getExplicitSpecifier().getExpr()); + if (Err) +return std::move(Err); +} +return ExplicitExpr; + }; + // Create the imported function. FunctionDecl *ToFunction = nullptr; if (auto *FromConstructor = dyn_cast(D)) { @@ -3369,17 +3381,13 @@ ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg); } else if (CXXConversionDecl *FromConversion = dyn_cast(D)) { -Expr *ExplicitExpr = nullptr; -if (FromConversion->getExplicitSpecifier().getExpr()) { - auto Imp = import(FromConversion->getExplicitSpecifier().getExpr()); - if (!Imp) -return Imp.takeError(); - ExplicitExpr = *Imp; -} +ExpectedExpr ExplicitExpr = ImportExplicitExpr(FromConversion); +if (!ExplicitExpr) + return ExplicitExpr.takeError(); if (GetImportedOrCreateDecl( ToFunction, D, Importer.getToContext(), cast(DC), ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), -ExplicitSpecifier(ExplicitExpr, +ExplicitSpecifier(*ExplicitExpr, FromConversion->getExplicitSpecifier().getKind()), D->getConstexprKind(), SourceLocation(), TrailingRequiresClause)) return ToFunction; @@ -3390,6 +3398,16 @@ Method->isInlineSpecified(), D->getConstexprKind(), SourceLocation(), TrailingRequiresClause)) return ToFunction; + } else if (auto *Guide = dyn_cast(D)) { +ExpectedExpr ExplicitExpr = ImportExplicitExpr(Guide); +if (!ExplicitExpr) + return ExplicitExpr.takeError(); +if (GetImportedOrCreateDecl( +ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, +ExplicitSpecifier(*ExplicitExpr, + Guide->getExplicitSpecifier().getKind()), +NameInfo, T, TInfo, ToEndLoc)) + return ToFunction; } else { if (GetImportedOrCreateDecl( ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, @@ -3517,6 +3535,11 @@ return VisitCXXMethodDecl(D); } +ExpectedDecl +ASTNodeImporter::VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D) { + return VisitFunctionDecl(D); +} + ExpectedDecl ASTNodeImporter::VisitFieldDecl(FieldDecl *D) { // Import the major distinguishing characteristics of a variable. DeclContext *DC, *LexicalDC; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits