Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/clang/lib/AST/TemplateBase.cpp b/clang/lib/AST/TemplateBase.cpp
- index 6a3d2b30e46..145d9909dbb 100644
- --- a/clang/lib/AST/TemplateBase.cpp
- +++ b/clang/lib/AST/TemplateBase.cpp
- @@ -352,7 +352,37 @@ void TemplateArgument::print(const PrintingPolicy &Policy,
- case Declaration: {
- NamedDecl *ND = getAsDecl();
- - if (!getParamTypeForDecl()->isReferenceType())
- + bool needsRef = true;
- + if (auto *VD = dyn_cast<ValueDecl>(ND)) {
- + const clang::Type *ArgTy = VD->getType()->getUnqualifiedDesugaredType();
- + const clang::Type *ParmTy =
- + getParamTypeForDecl()->getUnqualifiedDesugaredType();
- + clang::ASTContext &Ctx = ND->getASTContext();
- + needsRef = !Ctx.hasSameType(ArgTy, ParmTy);
- + if (needsRef && (ArgTy->isArrayType() || ArgTy->isFunctionType())) {
- + const clang::Type *decayedArgTy =
- + Ctx.getDecayedType(clang::QualType(ArgTy, 0)).getTypePtr();
- + needsRef = !Ctx.hasSameType(decayedArgTy, ParmTy);
- + if (!needsRef) {
- + int deptharg = 0, depthparam = 0;
- + clang::QualType NestArgTy = VD->getType();
- + while (const auto *Array =
- + dyn_cast<ArrayType>(NestArgTy.getCanonicalType())) {
- + deptharg++;
- + NestArgTy = Array->getElementType();
- + }
- + clang::QualType NestParmTy = getParamTypeForDecl();
- + while (const auto *Array =
- + dyn_cast<ArrayType>(NestParmTy.getCanonicalType())) {
- + depthparam++;
- + NestParmTy = Array->getElementType();
- + }
- + if ((deptharg > 0) && (depthparam > 0) && (deptharg != depthparam))
- + needsRef = true;
- + }
- + }
- + }
- + if (!getParamTypeForDecl()->isReferenceType() && needsRef)
- Out << '&';
- ND->printQualifiedName(Out);
- break;
- diff --git a/clang/test/CodeGenCXX/debug-info-codeview-display-name.cpp b/clang/test/CodeGenCXX/debug-info-codeview-display-name.cpp
- index ab3344bc991..86b9fb69901 100644
- --- a/clang/test/CodeGenCXX/debug-info-codeview-display-name.cpp
- +++ b/clang/test/CodeGenCXX/debug-info-codeview-display-name.cpp
- @@ -90,7 +90,7 @@ template <typename T, void (*)(void)>
- void fn_tmpl() {}
- template void fn_tmpl<int, freefunc>();
- -// CHECK-DAG: "fn_tmpl<int,&freefunc>"
- +// CHECK-DAG: "fn_tmpl<int,freefunc>"
- template <typename A, typename B, typename C> struct ClassTemplate { A a; B b; C c; };
- ClassTemplate<char, short, ClassTemplate<int, int, int> > f;
- diff --git a/clang/test/CodeGenCXX/debug-info-template.cpp b/clang/test/CodeGenCXX/debug-info-template.cpp
- index a07222ace15..c79441cbb5c 100644
- --- a/clang/test/CodeGenCXX/debug-info-template.cpp
- +++ b/clang/test/CodeGenCXX/debug-info-template.cpp
- @@ -1,6 +1,6 @@
- // RUN: %clang -S -emit-llvm -target x86_64-unknown_unknown -g %s -o - -std=c++11 | FileCheck %s
- -// CHECK: @tci = dso_local global %"struct.TC<unsigned int, 2, &glb, &foo::e, &foo::f, &foo::g, 1, 2, 3>::nested" zeroinitializer, align 1, !dbg [[TCI:![0-9]+]]
- +// CHECK: @tci = dso_local global %"struct.TC<unsigned int, 2, &glb, &foo::e, &foo::f, foo::g, 1, 2, 3>::nested" zeroinitializer, align 1, !dbg [[TCI:![0-9]+]]
- // CHECK: @tcn = dso_local global %struct.TC zeroinitializer, align 1, !dbg [[TCN:![0-9]+]]
- // CHECK: @nn = dso_local global %struct.NN zeroinitializer, align 1, !dbg [[NN:![0-9]+]]
- @@ -31,7 +31,7 @@ void func();
- // CHECK: ![[TCNESTED]] ={{.*}}!DICompositeType(tag: DW_TAG_structure_type, name: "nested",
- // CHECK-SAME: scope: ![[TC:[0-9]+]],
- -// CHECK: ![[TC]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "TC<unsigned int, 2, &glb, &foo::e, &foo::f, &foo::g, 1, 2, 3>"
- +// CHECK: ![[TC]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "TC<unsigned int, 2, &glb, &foo::e, &foo::f, foo::g, 1, 2, 3>"
- // CHECK-SAME: templateParams: [[TCARGS:![0-9]*]]
- TC
- // CHECK: [[TCARGS]] = !{[[TCARG1:![0-9]*]], [[TCARG2:![0-9]*]], [[TCARG3:![0-9]*]], [[TCARG4:![0-9]*]], [[TCARG5:![0-9]*]], [[TCARG6:![0-9]*]], [[TCARG7:![0-9]*]]}
- diff --git a/clang/test/SemaTemplate/temp_arg_nontype_cxx11.cpp b/clang/test/SemaTemplate/temp_arg_nontype_cxx11.cpp
- index 460b6def5d6..b080fa28478 100644
- --- a/clang/test/SemaTemplate/temp_arg_nontype_cxx11.cpp
- +++ b/clang/test/SemaTemplate/temp_arg_nontype_cxx11.cpp
- @@ -65,3 +65,22 @@ namespace PR42513 {
- void use() { f<X1>(); }
- }
- +
- +using FourChars = const char[4];
- +constexpr FourChars kEta = "Eta";
- +constexpr const char* kNull = "Phi";
- +
- +template <const char*, typename T> class Column {};
- +template <const char[], typename T> class Dolumn {};
- +template <const char(*)[4], typename T> class Folumn {};
- +template <FourChars*, typename T> class Golumn {};
- +template <const char* const *, typename T> class Holumn {};
- +
- +void lookup() {
- + Column<kEta,double>().ls(); // expected-error {{<kEta,}}
- + Column<nullptr, double>().ls(); // expected-error {{<nullptr,}}
- + Dolumn<kEta, double>().ls(); // expected-error {{<kEta,}}
- + Folumn<&kEta, double>().ls(); // expected-error {{<&kEta,}}
- + Golumn<&kEta, double>().ls(); // expected-error {{<&kEta,}}
- + Holumn<&kNull, double>().ls(); // expected-error {{<&kNull,}}
- +}
Add Comment
Please, Sign In to add comment