[PATCH] D158766: [AST] TypeSourceInfo for params of inherited constructor should be null

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 24 12:07:25 PDT 2023


sammccall created this revision.
sammccall added a reviewer: ymandel.
Herald added a project: All.
sammccall requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This matches behavior of other synthetic members like copy constructors,
and avoids RecursiveASTVisitor traversing TypeLocs that don't correspond
to any spelling of the type they describe.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158766

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp


Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===================================================================
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -2129,6 +2129,20 @@
       notMatches(Code, typeAliasTemplateDecl(hasName("typeAliasDecl"))));
 }
 
+TEST_P(ASTMatchersTest, TypeLocTest_DoesNotBindToSyntheticParams) {
+  if (!GetParam().isCXX11OrLater()) {
+    return;
+  }
+  EXPECT_TRUE(
+      notMatches(R"cpp(
+        struct Base { Base(int); };
+        struct Derived : Base { using Base::Base; };
+        Derived d(42); // force constructor to exist
+      )cpp",
+              typeLoc(loc(asString("int")),
+                      hasAncestor(cxxRecordDecl(hasAnyName("Derived"))))));
+}
+
 TEST_P(ASTMatchersTest, QualifiedTypeLocTest_BindsToConstIntVarDecl) {
   EXPECT_TRUE(matches("const int x = 0;",
                       qualifiedTypeLoc(loc(asString("const int")))));
Index: clang/lib/Sema/SemaDeclCXX.cpp
===================================================================
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -13926,11 +13926,9 @@
   // Build the parameter declarations.
   SmallVector<ParmVarDecl *, 16> ParamDecls;
   for (unsigned I = 0, N = FPT->getNumParams(); I != N; ++I) {
-    TypeSourceInfo *TInfo =
-        Context.getTrivialTypeSourceInfo(FPT->getParamType(I), UsingLoc);
     ParmVarDecl *PD = ParmVarDecl::Create(
         Context, DerivedCtor, UsingLoc, UsingLoc, /*IdentifierInfo=*/nullptr,
-        FPT->getParamType(I), TInfo, SC_None, /*DefArg=*/nullptr);
+        FPT->getParamType(I), nullptr, SC_None, /*DefArg=*/nullptr);
     PD->setScopeInfo(0, I);
     PD->setImplicit();
     // Ensure attributes are propagated onto parameters (this matters for


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158766.553224.patch
Type: text/x-patch
Size: 1825 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230824/73db9936/attachment-0001.bin>


More information about the cfe-commits mailing list