[llvm-bugs] [Bug 38363] New: QualType::getAsString() sometimes produces && for lvalue references

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jul 30 02:39:19 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=38363

            Bug ID: 38363
           Summary: QualType::getAsString() sometimes produces && for
                    lvalue references
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: a.d.romanov at yandex.ru
                CC: llvm-bugs at lists.llvm.org

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 https://bugs.llvm.org/show_bug.cgi?id=11806

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180730/8b3a20ef/attachment.html>


More information about the llvm-bugs mailing list