[PATCH] D156461: [clang][ASTImporter] Merge implicit ctors with definition
Ding Fei via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 27 10:33:20 PDT 2023
danix800 created this revision.
danix800 added a project: clang.
Herald added a subscriber: martong.
Herald added a reviewer: a.sidorin.
Herald added a reviewer: shafik.
Herald added a project: All.
danix800 requested review of this revision.
Herald added a subscriber: cfe-commits.
Implicit ctors generated with definition should be merged into `To` context.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D156461
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
@@ -3175,6 +3175,38 @@
testNoImportOf(cxxMethodDecl(hasName("f")), Code);
}
+TEST_P(ImportImplicitMethods, MergeImplicitMethodWithDefinition) {
+ Decl *From, *To;
+ std::tie(From, To) = getImportedDecl(
+ R"s(
+ struct A {
+ A() : m() {}
+ int m;
+ };
+
+ A foo() { A a; return a; }
+ A bar() { return {}; }
+ )s",
+ Lang_CXX17,
+ R"s(
+ struct A {
+ A() : m() {}
+ int m;
+ };
+ )s",
+ Lang_CXX17, "A");
+
+ MatchVerifier<Decl> Verifier;
+ auto HasCopyCtor = has(cxxConstructorDecl(isCopyConstructor(), isImplicit()));
+ auto HasCtorInit =
+ hasAnyConstructorInitializer(cxxCtorInitializer(isMemberInitializer()));
+ auto HasMoveCtor =
+ has(cxxConstructorDecl(isMoveConstructor(), isImplicit(), HasCtorInit));
+ auto Pattern = cxxRecordDecl(HasCopyCtor, HasMoveCtor);
+ ASSERT_TRUE(Verifier.match(From, Pattern));
+ EXPECT_TRUE(Verifier.match(To, Pattern));
+}
+
TEST_P(ASTImporterOptionSpecificTestBase, ImportOfEquivalentRecord) {
Decl *ToR1;
{
Index: clang/lib/AST/ASTImporter.cpp
===================================================================
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -3734,9 +3734,14 @@
// Connect the redecl chain.
if (FoundByLookup) {
- auto *Recent = const_cast<FunctionDecl *>(
- FoundByLookup->getMostRecentDecl());
- ToFunction->setPreviousDecl(Recent);
+// if (auto *Ctor = dyn_cast<CXXConstructorDecl>(D);
+// Ctor && Ctor->isImplicit())
+// DC->removeDecl(FoundByLookup);
+// else {
+ auto *Recent =
+ const_cast<FunctionDecl *>(FoundByLookup->getMostRecentDecl());
+ ToFunction->setPreviousDecl(Recent);
+// }
// FIXME Probably we should merge exception specifications. E.g. In the
// "To" context the existing function may have exception specification with
// noexcept-unevaluated, while the newly imported function may have an
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156461.544846.patch
Type: text/x-patch
Size: 2219 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230727/678bb5fb/attachment.bin>
More information about the cfe-commits
mailing list