I recently discovered that decltype expressions are distorted as part of function symbol names when used as return types, and that this can cause unpleasant segmentation errors when dismantling expressions (for example, in debugging sessions) if the expression is too complex.
The first version uses the decltype return type, where the full expression gets garbled ( http://goo.gl/EALubx ):
#include <cstdint>
Compiled (GCC 5.2.0):
foo(): sub rsp, 24 lea rdi, [rsp+15] call decltype ((((declval<A>)()).bar)()) foo<A>(A const&) add rsp, 24 ret
The second version, almost equivalent, where the type of the expression is allowed as part of the optional template parameter ( http://goo.gl/DfQGR5 ):
#include <cstdint>
Compiled (GCC 5.2.0):
foo(): sub rsp, 24 lea rdi, [rsp+15] call void foo<A, void>(A const&) add rsp, 24 ret
I understand that template functions can only be overloaded by their return type, but should the compiler not have to resolve the decltype expression on its own and use the resulting type instead?
Can someone tell me why, or tell me where the C ++ spec states?
c ++ gcc c ++ 11 c ++ 14
Beren minor
source share