Maybe this experience will be interesting to someone... I'm currently trying to write a simple parser for function signatures for Boost.Log and collecting different curious use cases. The parser is supposed to extract the function name from the compiler-generated string with the signature (i.e. BOOST_CURRENT_FUNCTION). Now the interesting case I've stumbled upon is a conversion operator to a function pointer: namespace namespc { struct my_class2 { typedef char (*pfunc_t)(double); operator pfunc_t () const { std::cout << BOOST_CURRENT_FUNCTION << std::endl; return 0; } }; } I first tried to imagine how this could be written without the typedef, but my brain broke soon enough. Then I decided to ask the compiler, and naturally different compilers gave different answers. GCC nicely sidestepped the problem altogether: namespc::my_class2::operator pfunc_t() const MSVC was more creative: __cdecl namespc::my_class2::operator char (__cdecl *)(double)(__cdecl *(void) const)(double) Frankly, my brain can't parse this one either and it looks incorrect to me since the function pointer type is duplicated. So it seems, there's no syntax for expressing the operator without a typedef, is that right? In that case, I wonder what to do with MSVC output...
On 5.3.2014 г. 21:31 ч., Andrey Semashev wrote:
MSVC was more creative:
__cdecl namespc::my_class2::operator char (__cdecl *)(double)(__cdecl *(void) const)(double)
It seems that BOOST_CURRENT_FUNCTION expands to __FUNCSIG__ in msvc, as the simple __FUNCTION__ produces a far simpler output (similar to the one in gcc. Why don't you try using __FUNCTION__ when _MSC_VER is defined? -- Borislav
On Wednesday 05 March 2014 21:49:44 Borislav Stanimirov wrote:
On 5.3.2014 г. 21:31 ч., Andrey Semashev wrote:
MSVC was more creative: __cdecl namespc::my_class2::operator char (__cdecl
*)(double)(__cdecl *(void) const)(double)
It seems that BOOST_CURRENT_FUNCTION expands to __FUNCSIG__ in msvc, as the simple __FUNCTION__ produces a far simpler output (similar to the one in gcc.
Why don't you try using __FUNCTION__ when _MSC_VER is defined?
Yeah, I might resort to that since that's mostly what I need in Boost.Log. The point for __FUNCSIG__ is that in other cases it is more consistent with other compilers, so if someone wants to see the complete signature (which is the current behavior) he gets it with MSVC too.
participants (2)
-
Andrey Semashev
-
Borislav Stanimirov