[PATCH] D25131: Fix PR 28885: Fix AST Printer output for inheriting constructor using declarations

Alex Lorenz via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 30 14:40:23 PDT 2016


arphaman created this revision.
arphaman added a reviewer: rsmith.
arphaman added a subscriber: cfe-commits.
arphaman set the repository for this revision to rL LLVM.

This patch ensures that the AST printer outputs the correct C++ type for an inheriting constructor using declaration.

For example, for a using declaration in a code sample like this:

  struct A {
  	A();
  };
  
  struct B : A {
    using A::A;
  };

The AST printer will now print "using A::A" instead of "using A::B".

This bug is a regression since r274049.


Repository:
  rL LLVM

https://reviews.llvm.org/D25131

Files:
  lib/AST/DeclPrinter.cpp
  test/SemaCXX/cxx11-ast-print.cpp


Index: test/SemaCXX/cxx11-ast-print.cpp
===================================================================
--- test/SemaCXX/cxx11-ast-print.cpp
+++ test/SemaCXX/cxx11-ast-print.cpp
@@ -43,6 +43,14 @@
 // CHECK: const char *PR23120 = operator""_suffix<char32_t, 66615>();
 const char *PR23120 = U"𐐷"_suffix;
 
+// PR28885
+struct A {
+  A();
+};
+struct B : A {
+  using A::A; // CHECK:      using A::A;
+};            // CHECK-NEXT: };
+
 // CHECK: ;
 ;
 // CHECK-NOT: ;
Index: lib/AST/DeclPrinter.cpp
===================================================================
--- lib/AST/DeclPrinter.cpp
+++ lib/AST/DeclPrinter.cpp
@@ -1346,6 +1346,17 @@
   if (D->hasTypename())
     Out << "typename ";
   D->getQualifier()->print(Out, Policy);
+
+  // PR 28885: Use the correct record name when the using declaration is used
+  // for inheriting constructors.
+  for (const auto *Shadow : D->shadows()) {
+    if (const auto *ConstructorShadow =
+            dyn_cast<ConstructorUsingShadowDecl>(Shadow)) {
+      assert(Shadow->getDeclContext() == ConstructorShadow->getDeclContext());
+      Out << *ConstructorShadow->getNominatedBaseClass();
+      return;
+    }
+  }
   Out << *D;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25131.73145.patch
Type: text/x-patch
Size: 1193 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160930/ec7691dc/attachment.bin>


More information about the cfe-commits mailing list