I'm not sure if I'm missing something, but, user-defined literals, which invokes user-defined functions that could return anything, are also a kind of literals.
The standard says that a literal is always a prvalue, unless it is a string literal, but:
#include <iostream>
#include <typeinfo>
int& operator""_a(unsigned long long c);
int main()
{
std::cout << std::is_same<decltype(5_a), int&>::value;
}
prints 1 in both GCC and Clang, which proofs that the literal 5_a
(which is not a string literal) is being treated as a lvalue instead of an rvalue:
[expr.prim.literal]/1 A literal is a primary expression. Its type depends on its form. A string literal is an lvalue; all other literals are prvalues.
and user-defined literals are literals too.
What is what I'm missing?
5_a
is equal to the calloperator""_a(5)
). And your operator function returns an lvalue reference, which you compare to an lvalue reference of the same type. – Some programmer dude5_a
is an lvalue in your example, and presumably all compilers correctly invoke it as such. Is there a real source of confusion? – Barry