danix800 updated this revision to Diff 544854.
danix800 edited the summary of this revision.
Herald added a subscriber: pengfei.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D156461/new/
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,39 @@
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;
+ };
+ A baz() { return {}; }
+ )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
Index: clang/unittests/AST/ASTImporterTest.cpp
===================================================================
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -3175,6 +3175,39 @@
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;
+ };
+ A baz() { return {}; }
+ )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
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits