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;
 }
 


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

Reply via email to