#include <iostream>
#include <utility>
class test
{
private:
test(int) { }
public:
test foo() { return *this; }
static const char *name() { return "test"; }
};
int main()
{
std::cout << decltype(test().foo())::name() << std::endl; // 1
std::cout << decltype(std::declval<test>().foo())::name() << std::endl; // 2
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dXRpbGl0eT4KCmNsYXNzIHRlc3QKewpwcml2YXRlOgoJdGVzdChpbnQpIHsgfQpwdWJsaWM6Cgl0ZXN0IGZvbygpIHsgcmV0dXJuICp0aGlzOyB9CgoJc3RhdGljIGNvbnN0IGNoYXIgKm5hbWUoKSB7IHJldHVybiAidGVzdCI7IH0KfTsKCmludCBtYWluKCkKewoJc3RkOjpjb3V0IDw8IGRlY2x0eXBlKHRlc3QoKS5mb28oKSk6Om5hbWUoKSA8PCBzdGQ6OmVuZGw7ICAgICAgICAgICAgICAgLy8gMQoJc3RkOjpjb3V0IDw8IGRlY2x0eXBlKHN0ZDo6ZGVjbHZhbDx0ZXN0PigpLmZvbygpKTo6bmFtZSgpIDw8IHN0ZDo6ZW5kbDsgLy8gMgp9Cg==
prog.cpp: In function ‘int main()’:
prog.cpp:16:29: error: no matching function for call to ‘test::test()’
std::cout << decltype(test().foo())::name() << std::endl; // 1
^
prog.cpp:16:29: note: candidates are:
prog.cpp:7:2: note: test::test(int)
test(int) { }
^
prog.cpp:7:2: note: candidate expects 1 argument, 0 provided
prog.cpp:4:7: note: constexpr test::test(const test&)
class test
^
prog.cpp:4:7: note: candidate expects 1 argument, 0 provided
prog.cpp:4:7: note: constexpr test::test(test&&)
prog.cpp:4:7: note: candidate expects 1 argument, 0 provided
prog.cpp:16:29: error: no matching function for call to ‘test::test()’
std::cout << decltype(test().foo())::name() << std::endl; // 1
^
prog.cpp:16:29: note: candidates are:
prog.cpp:7:2: note: test::test(int)
test(int) { }
^
prog.cpp:7:2: note: candidate expects 1 argument, 0 provided
prog.cpp:4:7: note: constexpr test::test(const test&)
class test
^
prog.cpp:4:7: note: candidate expects 1 argument, 0 provided
prog.cpp:4:7: note: constexpr test::test(test&&)
prog.cpp:4:7: note: candidate expects 1 argument, 0 provided
prog.cpp:16:15: error: decltype evaluates to ‘<type error>’, which is not a class or enumeration type
std::cout << decltype(test().foo())::name() << std::endl; // 1
^