Skip to content
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

__PRETTY_FUNCTION__ definition issue #423

Closed
landwehrj opened this issue Dec 14, 2021 · 3 comments · Fixed by #424
Closed

__PRETTY_FUNCTION__ definition issue #423

landwehrj opened this issue Dec 14, 2021 · 3 comments · Fixed by #424
Labels

Comments

@landwehrj
Copy link
Contributor

The check for PRETTY_FUNCTION at least on gcc returns false in the g3log/g3log.hpp:33:

#if !(defined(__PRETTY_FUNCTION__))

For instance, I tested the following code:

#if defined(__PRETTY_FUNCTION__)
error
#endif 

#include <iostream>

int main() {
  std::cout << __PRETTY_FUNCTION__ << std::endl;
  return 0; 
}

Which compiles and runs fine. I assume it's because the PRETTY_FUNCTION is a magic literal and not a macro?

This causes issues with other libraries that use the literal when including g3log.hpp because g3log.hpp overrides the magic literal.

@KjellKod
Copy link
Owner

https://gcc.gnu.org/onlinedocs/gcc/Function-Names.html

PRETTY_FUNCTION should be AFAIK part of gcc, potentially depending on GCC setup that is not the case for you. I think there are potentially bigger problems lurking for you , when gcc is compiling one library in one way and you are integrating other libraries that are constructed with a whole different GCC setup. At least that's how I interpret your answer.

I don't see this as an issue with g3log . This seems to be to be a system setup issue on your company's side.

g3log is public domain, so one option is to fork the repo and remove the troublesome code - if you can't align the GCC configurations across your systems.

@landwehrj
Copy link
Contributor Author

landwehrj commented Dec 14, 2021

I think there may be some misunderstanding. So what I am trying to convey is that it is part of gcc, but is not defined as a macro. It's a magic literal. It doesn't get defined until compile time after the preprocessor AFAIK. You can't test it with defined(), I believe.

So what's happening with g3log is that it is always overriding the built-in PRETTY_FUNCTION literal as far as I can tell.

Here is an example that shows it not being defined but printing the result:
https://coliru.stacked-crooked.com/a/93197612dbae85cc

You can click edit and recompile it if you want.

Here's a stack overflow post that confirms my thoughts:
https://stackoverflow.com/a/48223048/15387245

@KjellKod
Copy link
Owner

Look at that. "Magic Constants" -- and I considered myself a (at one time at least) C++ expert. You learn something new everyday.

It seems that the idef check is just nonsense in this case. Since we really want the adorned function, through __PRETTY_FUNCTION__, maybe just remove that ifdef definition section from the code?

Please put up a PR so we can evaluate. Nice find!

ref: https://gcc.gnu.org/onlinedocs/gcc/Function-Names.html

@KjellKod KjellKod linked a pull request Dec 20, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants