Skip to content

Commit 9bd6b77

Browse files
committed
Don't print & as part of reference template arguments.
In passing, also generalize the mechanism used to allow Decl's printName functions to override qualified name printing.
1 parent b09ee88 commit 9bd6b77

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

clang/lib/AST/Decl.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,10 +1542,19 @@ void NamedDecl::printQualifiedName(raw_ostream &OS,
15421542
return;
15431543
}
15441544
printNestedNameSpecifier(OS, P);
1545-
if (getDeclName() || isa<DecompositionDecl>(this))
1545+
if (getDeclName())
15461546
OS << *this;
1547-
else
1548-
OS << "(anonymous)";
1547+
else {
1548+
// Give the printName override a chance to pick a different name before we
1549+
// fall back to "(anonymous)".
1550+
SmallString<64> NameBuffer;
1551+
llvm::raw_svector_ostream NameOS(NameBuffer);
1552+
printName(NameOS);
1553+
if (NameBuffer.empty())
1554+
OS << "(anonymous)";
1555+
else
1556+
OS << NameBuffer;
1557+
}
15491558
}
15501559

15511560
void NamedDecl::printNestedNameSpecifier(raw_ostream &OS) const {

clang/lib/AST/TemplateBase.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -352,13 +352,9 @@ void TemplateArgument::print(const PrintingPolicy &Policy,
352352

353353
case Declaration: {
354354
NamedDecl *ND = getAsDecl();
355-
Out << '&';
356-
if (ND->getDeclName()) {
357-
// FIXME: distinguish between pointer and reference args?
358-
ND->printQualifiedName(Out);
359-
} else {
360-
Out << "(anonymous)";
361-
}
355+
if (!getParamTypeForDecl()->isReferenceType())
356+
Out << '&';
357+
ND->printQualifiedName(Out);
362358
break;
363359
}
364360

clang/test/CodeGenCXX/debug-info-template.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@ struct NN {
129129
// CHECK: [[NNV]] = distinct !DIGlobalVariable(name: "nn"
130130
// CHECK-SAME: type: ![[NNT:[0-9]+]]
131131

132-
// FIXME: these parameters should probably be rendered as 'glb' rather than
133-
// '&glb', since they're references, not pointers.
134-
// CHECK: ![[NNT]] ={{.*}}!DICompositeType(tag: DW_TAG_structure_type, name: "NN<tmpl_impl, &glb, &glb>",
132+
// CHECK: ![[NNT]] ={{.*}}!DICompositeType(tag: DW_TAG_structure_type, name: "NN<tmpl_impl, glb, glb>",
135133
// CHECK-SAME: templateParams: [[NNARGS:![0-9]*]]
136134
// CHECK-SAME: identifier:
137135
// CHECK: [[NNARGS]] = !{[[NNARG1:![0-9]*]], [[NNARG2:![0-9]*]], [[NNARG3:![0-9]*]]}

0 commit comments

Comments
 (0)