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


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
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to