-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve std::source_location::function_name()
informativeness
#3063
Comments
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Internal MSVC-PR-423006 implemented |
@StephanTLavavej , do we need to ask Clang devs and EDG devs to implement |
Why not have both? simple name and full signature |
What is a preprocessor? |
A text replacing mechanism which is running before compilation. More details: https://en.cppreference.com/w/cpp/preprocessor |
I'm starting to migrate my codebase to using std::source_location over the equivalent home grown type, and I have to say that the switch to I have an assert macro which, among other things, uses With this macro, i get nice, simple, function signatures, for example:
Switching this macro to using
the actual function signature is
Is this really better to have 5x the characters in the output, including the unnecessary C++ has nothing in the standard library to assist developers in parsing function signatures, and MSVC, Clang, and GCC each have their own formatting. How are we supposed to parse this to get the actual function name? |
You can define |
Why does the
std::source_location::function_name()
return a string equivalent to__builtin_FUNCTION()
instead of__FUNCSIG__
? Are there any plans to change that in the future?The
<source_location>
header was introduced PR #664, and there was a discussion starting from this comment on improving the informativeness of thestd::source_location::function_name()
. There are also two (1, 2) DevCom tickets that are both in the “Under review” status since August 10, 2021, but there are no feedback since then.The suggestion is to make the
std::source_location::function_name()
return the same string as__FUNCSIG__
does, analogous to what GCC and Clang do by returning the string equivalent to__PRETTY_FUNCTION__
. Here is the side by side comparison (compiler explorer). Please note, that GCC and Clang also provide the__builtin_FUNCTION()
intrinsic which works the same as MSVC implementation, however, libstdc++ and libc++ implementations ofsource_location
rely on the__builtin_source_location()
intrinsic which works differently.This is not a bug report because the current implementation is definitely valid by the C++ Standard, but I find it a significant usability improvement for using
source_location
, thus bringing it here.If I am misunderstanding some concepts, please correct me in the comments.
Also tracked by internal VSO-1614161 / AB#1614161 .
The text was updated successfully, but these errors were encountered: