If compiling as C++20 or using GCC or MSVC, expands to function signature. Falls back to the function name (using __func__
) otherwise.
The rationale behind this is that __func__
can yield names such as operator()
, which (IMO) is not all that useful. This macro can be much more informative.
https://github.com/wxWidgets/wxWidgets/pull/24554
(2 files)
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
@Blake-Madden pushed 1 commit.
—
View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.
@Blake-Madden pushed 1 commit.
—
View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.
@Blake-Madden pushed 1 commit.
—
View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.
@vadz commented on this pull request.
Looks useful, thanks!
In include/wx/cpp.h:
> @@ -114,6 +114,26 @@ #define __WXFUNCTION__ __func__ #endif /* __WXFUNCTION__ already defined */ +/* + Display the current function's full signature, if available. + + Falls back to the function name (i.e., __func__) if not available. + */ +#ifndef __WXFUNCTION_SIG__ + #if __cplusplus >= 202002L + #include <source_location> + // actually displays the signature, not just the name + #define __WXFUNCTION_SIG__ std::source_location::current().function_name() + #elif defined(__VISUALC__) + #define __WXFUNCTION_SIG__ __FUNCSIG__ + #elif defined(__clang__) + #define __WXFUNCTION_SIG__ __func__
I thought clang supported __PRETTY_FUNCTION__
too, so do we really need to have a separate test for it here?
> @header{wx/cpp.h} */ #define __WXFUNCTION__ __func__ +/** + Display the current function's full signature, if available.
I think it would be more correct to say
⬇️ Suggested change- Display the current function's full signature, if available. + Expands to the current function's full signature, if available.
> @header{wx/cpp.h} */ #define __WXFUNCTION__ __func__ +/** + Display the current function's full signature, if available. + + Falls back to the function name (i.e., @c \__func__) if not available.
Would be nice to show a simple example showing the difference.
> @header{wx/cpp.h} */ #define __WXFUNCTION__ __func__ +/** + Display the current function's full signature, if available. + + Falls back to the function name (i.e., @c \__func__) if not available. + + @header{wx/cpp.h} +*/
Please add @since 3.3.0
.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
@Blake-Madden pushed 4 commits.
—
View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.
@Blake-Madden commented on this pull request.
> @header{wx/cpp.h} */ #define __WXFUNCTION__ __func__ +/** + Display the current function's full signature, if available. + + Falls back to the function name (i.e., @c \__func__) if not available. + + @header{wx/cpp.h} +*/
Darn, I keep forgetting that. Fixed.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
@Blake-Madden commented on this pull request.
In include/wx/cpp.h:
> @@ -114,6 +114,26 @@ #define __WXFUNCTION__ __func__ #endif /* __WXFUNCTION__ already defined */ +/* + Display the current function's full signature, if available. + + Falls back to the function name (i.e., __func__) if not available. + */ +#ifndef __WXFUNCTION_SIG__ + #if __cplusplus >= 202002L + #include <source_location> + // actually displays the signature, not just the name + #define __WXFUNCTION_SIG__ std::source_location::current().function_name() + #elif defined(__VISUALC__) + #define __WXFUNCTION_SIG__ __FUNCSIG__ + #elif defined(__clang__) + #define __WXFUNCTION_SIG__ __func__
Indeed it does. I read people complaining that it is missing that, but I verified that it does on compiler explorer. Fixed.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
@Blake-Madden commented on this pull request.
> @header{wx/cpp.h} */ #define __WXFUNCTION__ __func__ +/** + Display the current function's full signature, if available.
Fixed
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
> @header{wx/cpp.h} */ #define __WXFUNCTION__ __func__ +/** + Display the current function's full signature, if available. + + Falls back to the function name (i.e., @c \__func__) if not available.
Done. Used a member function with a const
decorator to really show off the difference.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
It breaks on apple clang 14 when compiled with C++20.
subprojects/wxWidgets-master/include/wx/cpp.h:124:18: fatal error: 'source_location' file not found
#include <source_location>
^~~~~~~~~~~~~~~~~
1 error generated.
What about using __cpp_lib_source_location
macro instead of __cplusplus
as the condition?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
I'll need to add a __has_include
workaround or something like that. I'll check it out.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
Does this fix it:
#ifndef __WXFUNCTION_SIG__
#if __cplusplus >= 202002L
#ifdef __has_cpp_attribute
#if __has_cpp_attribute(__cpp_lib_source_location)
#include <source_location>
// actually displays the signature, not just the name
#define __WXFUNCTION_SIG__ std::source_location::current().function_name()
#else
#define __WXFUNCTION_SIG__ __func__
#endif
#else
#define __WXFUNCTION_SIG__ __func__
#endif
#elif defined(__VISUALC__)
#define __WXFUNCTION_SIG__ __FUNCSIG__
#elif defined(__GNUG__)
#define __WXFUNCTION_SIG__ __PRETTY_FUNCTION__
#else
#define __WXFUNCTION_SIG__ __func__
#endif
#endif /* __WXFUNCTION_SIG__ already defined */
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
__has_cpp_attribute
seems really quirky under GCC trunk. I may just remove the C++20 stuff and rely on the platform macros.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.