gcc - How to hide extra output from #pragma message -


current status

bug filed in gcc bugtracker (includes simple testcase): https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66234


i'm porting code new platform , toolchain, includes upgrade gcc 4.7.2 gcc 4.9.2 (or more specifically, release 2012 2014 of oselas toolchains - i've reproduced behavior on host machine gcc 4.6.4 (works) , gcc 4.8.3 (does not work)).

during build of application use #pragma message statements output builddate , hostname (note buildtag , buildhost stored constants used application afterwards):

#define buildtag (__date__  " "  __time__) #define buildhost built_on  #define str_helper(x) #x #define str(x) str_helper(x)  #pragma message "setting builddate to: " str(buildtag) #pragma message "building on: " str(buildhost) 

the old toolchains (gcc 4.7.2 / 4.6.4) output following, want:

note: #pragma message: setting builddate to: ("may 15 2015" " " 10:35:12") note: #pragma message: building on: my-host 

however, new toolchains (gcc 4.9.2 / 4.8.3) gives me:

note: #pragma message: setting builddate to: ("may 15 2015" " " "10:39:35") #pragma message "setting builddate to: " str(buildtag) ^ note: in definition of macro 'str_helper' #define str_helper(x) #x                        ^ note: in expansion of macro 'str' #pragma message "setting builddate to: " str(buildtag)                                          ^ note: #pragma message: building on: my-host #pragma message "building on: " str(buildhost)                                              ^ note: in definition of macro 'str_helper' #define str_helper(x) #x                        ^ note: in expansion of macro 'str' #pragma message "building on: " str(buildhost)                                 ^ 

(note i've removed file path/location output in both listings.)

sure, output want there, there's whole lot of stuff also. there anyway hide additional in definition of macro / in expansion of macro / etc. messages while keeping desired output?

or doing wrong way, , there better method print out messages?

short answer

to hide output, pass -ftrack-macro-expansion=0 , -fno-diagnostics-show-caret options added in gcc version 4.8.

long answer

this looks bug in gcc, may want report. looks same or related this bug.

i found able reproduce vanilla (built source) gcc version 4.9.2:

$ cat test.c  #define buildtag (__date__  " "  __time__) #define buildhost built_on  #define str_helper(x) #x #define str(x) str_helper(x)  #pragma message "setting builddate to: " str(buildtag) #pragma message "building on: " str(buildhost) $ g++ -c test.c test.c:7:1: note: #pragma message: setting builddate to: ("may 18 2015" " " "14:36:12")  #pragma message "setting builddate to: " str(buildtag)  ^ test.c:4:24: note: in definition of macro 'str_helper'  #define str_helper(x) #x                         ^ test.c:7:42: note: in expansion of macro 'str'  #pragma message "setting builddate to: " str(buildtag)                                           ^ test.c:8:46: note: #pragma message: building on: built_on  #pragma message "building on: " str(buildhost)                                               ^ test.c:4:24: note: in definition of macro 'str_helper'  #define str_helper(x) #x                         ^ test.c:8:33: note: in expansion of macro 'str'  #pragma message "building on: " str(buildhost)                                  ^ 

notice occurs c++ pre-processor (i.e. g++ instead of gcc), , goes away if pass -ftrack-macro-expansion=0:

$ gcc -c test.c test.c:7:9: note: #pragma message: setting builddate to: ("may 18 2015" " " "14:36:17")  #pragma message "setting builddate to: " str(buildtag)          ^ test.c:8:9: note: #pragma message: building on: built_on  #pragma message "building on: " str(buildhost)          ^ $ g++ -c test.c -ftrack-macro-expansion=0 test.c:7:42: note: #pragma message: setting builddate to: ("may 18 2015" " " "14:36:35")  #pragma message "setting builddate to: " str(buildtag)                                           ^ test.c:8:33: note: #pragma message: building on: built_on  #pragma message "building on: " str(buildhost)                                  ^ 

in change log gcc 4.8 shows -ftrack-macro-expansion=2 passed default explains why behavior wasn't present in version 4.7.2.

you can pass -fno-diagnostics-show-caret (which added in gcc 4.8) if want have same output 4.7.2:

$ g++ -c test.c -ftrack-macro-expansion=0 -fno-diagnostics-show-caret test.c:7:42: note: #pragma message: setting builddate to: ("may 18 2015" " " "14:39:48") test.c:8:33: note: #pragma message: building on: built_on 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -