Due to the reference collapsing rules of C++ it is possible for a reference to be written as a RValue reference but have it turn into an LValue reference. If you use the -ast-dump flag when this happens the reference will still be printed out as an RValue reference. This can be very confusing when you are trying to figure out why a program is behaving the way it does or why a call to isRValueRefernce() is returning false when you would expect otherwise.
Attached are two files: 1) is a C++ program that contains a LValue reference written as an RValue reference 2) is the relevant section of the AST as it is printed by -ast-dump.
It seems to me that the fact that a reference is an LValue reference written as an RValue reference should be evident somewhere in the printed version of the AST. The place that seems to make the most sense is in the DeclRefExpr (0x201bdd0) when it prints out the string representation of the Function (0x201bcc0). This appears to be the representation of the instantiated template which is, if I am understanding the reference collapsing rules correctly, where the conversion from an RValue reference to an LValue reference occurs. If it is printed as an LValue reference there, and as an RValue reference in the FunctionTemplate (0x1ff3350), that should make it clear that the reference collapsing rules have been applied.
Before I filed this as a bug I wanted to get the mailing list’s feedback. Should the printing of LValue references written as RValue references be handled differently, or is the current behavior the desired behavior?
LValueAsRValueAST.txt (1.47 KB)
LValueAsRValue.cpp (139 Bytes)