Add __WXFUNCTION_SIG__ macro (PR #24554)

33 views
Skip to first unread message

Blake-Madden

unread,
May 24, 2024, 4:25:20 PMMay 24
to wx-...@googlegroups.com, Subscribed

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.


You can view, comment on, or merge this pull request online at:

  https://github.com/wxWidgets/wxWidgets/pull/24554

Commit Summary

  • 17dffad Add __WXFUNCTION_SIG__ macro

File Changes

(2 files)

Patch Links:


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/24554@github.com>

Blake-Madden

unread,
May 24, 2024, 4:26:59 PMMay 24
to wx-...@googlegroups.com, Push

@Blake-Madden pushed 1 commit.


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/24554/push/18578811116@github.com>

Blake-Madden

unread,
May 24, 2024, 5:37:28 PMMay 24
to wx-...@googlegroups.com, Push

@Blake-Madden pushed 1 commit.


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/24554/push/18579441151@github.com>

Blake-Madden

unread,
May 24, 2024, 5:57:30 PMMay 24
to wx-...@googlegroups.com, Push

@Blake-Madden pushed 1 commit.


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/24554/push/18579586879@github.com>

VZ

unread,
May 25, 2024, 10:10:54 AMMay 25
to wx-...@googlegroups.com, Subscribed

@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?


In interface/wx/cpp.h:

>      @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.

In interface/wx/cpp.h:

>      @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.


In interface/wx/cpp.h:

>      @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.Message ID: <wxWidgets/wxWidgets/pull/24554/review/2079029599@github.com>

Blake-Madden

unread,
May 25, 2024, 11:31:39 AMMay 25
to wx-...@googlegroups.com, Push

@Blake-Madden pushed 4 commits.

  • b18c9cf Mention being added in 3.3.0
  • 412361c Improve wording
  • 7f48f6a Verified that glang supports __PRETTY_FUNCTION__, so use that
  • 80b42da Add example


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/24554/push/18585291221@github.com>

Blake-Madden

unread,
May 25, 2024, 11:32:14 AMMay 25
to wx-...@googlegroups.com, Subscribed

@Blake-Madden commented on this pull request.


In interface/wx/cpp.h:

>      @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.Message ID: <wxWidgets/wxWidgets/pull/24554/review/2079064617@github.com>

Blake-Madden

unread,
May 25, 2024, 11:33:35 AMMay 25
to wx-...@googlegroups.com, Subscribed

@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.Message ID: <wxWidgets/wxWidgets/pull/24554/review/2079064819@github.com>

Blake-Madden

unread,
May 25, 2024, 11:33:46 AMMay 25
to wx-...@googlegroups.com, Subscribed

@Blake-Madden commented on this pull request.


In interface/wx/cpp.h:

>      @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.Message ID: <wxWidgets/wxWidgets/pull/24554/review/2079064850@github.com>

Blake-Madden

unread,
May 25, 2024, 11:34:32 AMMay 25
to wx-...@googlegroups.com, Subscribed

@Blake-Madden commented on this pull request.


In interface/wx/cpp.h:

>      @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.Message ID: <wxWidgets/wxWidgets/pull/24554/review/2079064962@github.com>

VZ

unread,
May 28, 2024, 1:03:13 PMMay 28
to wx-...@googlegroups.com, Subscribed

Closed #24554 via f1c5010.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/24554/issue_event/12960794306@github.com>

0tkl

unread,
May 28, 2024, 10:13:01 PMMay 28
to wx-...@googlegroups.com, Subscribed

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.Message ID: <wxWidgets/wxWidgets/pull/24554/c2136392432@github.com>

Blake-Madden

unread,
May 29, 2024, 6:55:57 AMMay 29
to wx-...@googlegroups.com, Subscribed

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.Message ID: <wxWidgets/wxWidgets/pull/24554/c2137128584@github.com>

Blake-Madden

unread,
May 29, 2024, 7:13:42 AMMay 29
to wx-...@googlegroups.com, Subscribed

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.Message ID: <wxWidgets/wxWidgets/pull/24554/c2137158671@github.com>

Blake-Madden

unread,
May 29, 2024, 7:59:47 AMMay 29
to wx-...@googlegroups.com, Subscribed

__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.Message ID: <wxWidgets/wxWidgets/pull/24554/c2137238455@github.com>

Reply all
Reply to author
Forward
0 new messages