[PATCH] D56936: Fix handling of overriden methods during ASTImport

Balázs Kéri via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 21 00:20:13 PST 2019


balazske added inline comments.


================
Comment at: lib/AST/ASTImporter.cpp:3046
+        if (!D->doesThisDeclarationHaveABody())
+          return cast<Decl>(const_cast<FunctionDecl *>(FoundByLookup));
+        else {
----------------
The `cast<Decl>` should not be needed here (and is not done at the other return places). The `const_cast` can be omitted too (`FoundByLookup` is not const now).


================
Comment at: unittests/AST/ASTImporterTest.cpp:2243
+  auto BP = cxxMethodDecl(hasName("f"), hasParent(cxxRecordDecl(hasName("B"))));
+  auto DP = cxxMethodDecl(hasName("f"), hasParent(cxxRecordDecl(hasName("D"))));
+
----------------
I think names like `BP` and `BFP ` could be better (`P` should stand for "Pattern" and always the last part of the name, so use `BFP` and `BFIsDefP`). And for storing `B::F` a `BF` can be better name than `B`.


================
Comment at: unittests/AST/ASTImporterTest.cpp:2260
+TEST_P(ImportFunctions, ImportOverriddenMethodTwiceDefinitionFirst) {
+  auto CodeWithOutDef =
+      R"(
----------------
Use `CodeWithoutDef`.


================
Comment at: unittests/AST/ASTImporterTest.cpp:2312
+  auto DFP =
+      cxxMethodDecl(hasName("f"), hasParent(cxxRecordDecl(hasName("D"))));
+
----------------
It is ensured only by `FirstDeclMatcher` that not the definition is found (this pattern may match the definition too) for `BFP`. It may be more accurate to include in the pattern that this is not a definition.


================
Comment at: unittests/AST/ASTImporterTest.cpp:2325
+  EXPECT_EQ(DeclCounter<FunctionDecl>().match(ToTU, BFP), 1u);
+  EXPECT_EQ(DeclCounter<FunctionDecl>().match(ToTU, BFPIsDef), 0u);
+
----------------
For the out-of-class definition the `hasParent(cxxRecordDecl(hasName("B")))` does not match? (Otherwise this count should be 1.)


================
Comment at: unittests/AST/ASTImporterTest.cpp:2344
+
+TEST_P(ImportFunctions, ImportOverriddenMethodTwiceOutOfClassDefTwoTUs) {
+  auto CodeTU0 =
----------------
The previous tests use two TUs too so the name for this is not exact (here the code is different, maybe use `ImportOverriddenMethodTwiceOutOfClassDefInSeparateCode`?). This test does roughly the same as `ImportOverriddenMethodTwiceDefinitionFirst` but with the definition last and out-of-class version. (Name can be `ImportOverriddenMethodTwiceOutOfClassDefLast` too.) I am not sure why is the `foo` used here (`B::F` can be imported instead).


================
Comment at: unittests/AST/ASTImporterTest.cpp:2366
+  auto DFPIsDef = cxxMethodDecl(
+      hasName("f"), hasParent(cxxRecordDecl(hasName("B"))), isDefinition());
+  auto FooDef = functionDecl(hasName("foo"));
----------------
`hasName("B")` is wrong here, should be "D"?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56936/new/

https://reviews.llvm.org/D56936





More information about the cfe-commits mailing list