Why do primitive and user-defined types act differently when returned as 'const' from a function?
#include <iostream> using namespace std; template<typename T> void f(T&&) { cout << "f(T&&)" << endl; } template<typename T> void f(const T&&) { cout << "f(const T&&)" << endl; } struct A {}; const A g1() { return {}; } const int g2() { return {}; } int main() { f(g1()); // outputs "f(const T&&)" as expected. f(g2()); // outputs "f(T&&)" not as expected. } The issue description is embedded in the code. My compiler is clang 5.0 . I just wonder: Why does C++ treat built-in types and custom types differently in such a case? I don't have a quote from the standard, but cppreference confirms my