<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - QualType::getAsString() sometimes produces && for lvalue references"
href="https://bugs.llvm.org/show_bug.cgi?id=38363">38363</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>QualType::getAsString() sometimes produces && for lvalue references
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>-New Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>a.d.romanov@yandex.ru
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>I've wrote a tool using clangAST and add a functionDecl matcher to match
instantiations of a function templates. For every instantiation it prints out
every parameter, its type, is it lvalue and rvalue:
if (funcDecl->isTemplateInstantiation()) {
std::cout << "instantiation of '" << funcDecl->getNameAsString() << "'\n";
for (const auto * parm : funcDecl->parameters()) {
const auto & name = parm->getNameAsString();
const auto & type = parm->getType();
std::cout << "\tparam '" << name << "'"
<< " with type: '" << type.getAsString() << "'"
<< " is lvalue ref: " << type->isLValueReferenceType()
<< " is rvalue ref: " << type->isRValueReferenceType()
Now for the following piece of code:
template <class T>
void foo(T && t)
{ }
int main()
{
int i = 1;
foo(i);
return 0;
}
I got an output:
instantiation of 'foo'
param 't' with type: 'int &&' is lvalue ref: 1 is rvalue ref: 0
QualType::getAsString() goes into
void TypePrinter::print(const Type *T, Qualifiers Quals, raw_ostream &OS,
StringRef PlaceHolder);
Simplified call graph looks like:
TypePrinter::print()
├─printBefore()
│ └─printLValueReferenceBefore()
│ ├─printBefore() // <- getPointeeTypeAsWritten = SubstTemplateTypeParmType
│ │ └─printSubstTemplateTypeParmBefore()
│ │ └─printBefore() // <- getReplacementType = LValueRefeferenceType
│ │ └─printLValueReferenceBefore()
│ │ ├─printBefore() // <- getPointeeTypeAsWritten = BuiltinType
│ │ │ └─printBuiltinBefore()
│ │ │ └─OS << T->getName();
│ │ └─OS << "&";
│ └─OS << "&";
├─...
└─printAfter() // nothing interesting
Maybe this one is a duplicate of <a class="bz_bug_link
bz_status_NEW "
title="NEW - clang -ast-print isn't production quality"
href="show_bug.cgi?id=11806">https://bugs.llvm.org/show_bug.cgi?id=11806</a></pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>