From ea9b59a33de1999ae8b56734d2af05deff687bb9 Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Mon, 3 Oct 2016 12:22:17 +0000 Subject: [PATCH] Fix PR 28885: Fix AST Printer output for the inherited constructor using declarations. This commit ensures that the correct record type is printed out for the using declarations that represent C++ inherited constructors. It fixes a regression introduced in r274049 which changed the name that's stored in the using declarations that correspond to inherited constructors. Differential Revision: https://reviews.llvm.org/D25131 llvm-svn: 283105 --- clang/lib/AST/DeclPrinter.cpp | 11 +++++++++++ clang/test/SemaCXX/cxx11-ast-print.cpp | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp index 7e786990becb1..6d47dd7b88376 100644 --- a/clang/lib/AST/DeclPrinter.cpp +++ b/clang/lib/AST/DeclPrinter.cpp @@ -1346,6 +1346,17 @@ void DeclPrinter::VisitUsingDecl(UsingDecl *D) { if (D->hasTypename()) Out << "typename "; D->getQualifier()->print(Out, Policy); + + // 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(Shadow)) { + assert(Shadow->getDeclContext() == ConstructorShadow->getDeclContext()); + Out << *ConstructorShadow->getNominatedBaseClass(); + return; + } + } Out << *D; } diff --git a/clang/test/SemaCXX/cxx11-ast-print.cpp b/clang/test/SemaCXX/cxx11-ast-print.cpp index 1eeb67a3d9b34..9c617af4e95fd 100644 --- a/clang/test/SemaCXX/cxx11-ast-print.cpp +++ b/clang/test/SemaCXX/cxx11-ast-print.cpp @@ -43,6 +43,14 @@ template const char *operator"" _suffix(); // CHECK: const char *PR23120 = operator""_suffix(); const char *PR23120 = U"𐐷"_suffix; +// PR28885 +struct A { + A(); +}; +struct B : A { + using A::A; // CHECK: using A::A; +}; // CHECK-NEXT: }; + // CHECK: ; ; // CHECK-NOT: ;