In what module does the following utility macro: #if defined( __GNUC__ ) #define BOOST_PRAGMA_MESSAGE_IMPL_1( x ) _Pragma( #x ) #define BOOST_PRAGMA_MESSAGE( x ) BOOST_PRAGMA_MESSAGE_IMPL_1( message( x ) ) #elif defined( _MSC_VER ) #define BOOST_PRAGMA_MESSAGE_IMPL_2( x, f, ln ) __pragma( message( f "(" #ln "): note: " x ) ) #define BOOST_PRAGMA_MESSAGE_IMPL_1( x, f, ln ) BOOST_PRAGMA_MESSAGE_IMPL_2( x, f, ln ) #define BOOST_PRAGMA_MESSAGE( x ) BOOST_PRAGMA_MESSAGE_IMPL_1( x, __FILE__, __LINE__ ) #else #define BOOST_PRAGMA_MESSAGE( x ) #endif belong? Use: BOOST_PRAGMA_MESSAGE( "something" ) MS output: .\testbed.cpp(10): note: something g++ output: testbed.cpp:10:35: note: #pragma message: something BOOST_PRAGMA_MESSAGE( "something" ) ^
On 12/2/2017 4:20 PM, Peter Dimov via Boost wrote:
In what module does the following utility macro:
#if defined( __GNUC__ ) #define BOOST_PRAGMA_MESSAGE_IMPL_1( x ) _Pragma( #x ) #define BOOST_PRAGMA_MESSAGE( x ) BOOST_PRAGMA_MESSAGE_IMPL_1( message( x ) ) #elif defined( _MSC_VER ) #define BOOST_PRAGMA_MESSAGE_IMPL_2( x, f, ln ) __pragma( message( f "(" #ln "): note: " x ) ) #define BOOST_PRAGMA_MESSAGE_IMPL_1( x, f, ln ) BOOST_PRAGMA_MESSAGE_IMPL_2( x, f, ln ) #define BOOST_PRAGMA_MESSAGE( x ) BOOST_PRAGMA_MESSAGE_IMPL_1( x, __FILE__, __LINE__ ) #else #define BOOST_PRAGMA_MESSAGE( x ) #endif
belong?
Use:
BOOST_PRAGMA_MESSAGE( "something" )
Shouldn't this be: BOOST_PRAGMA_MESSAGE( something )
MS output:
.\testbed.cpp(10): note: something
g++ output:
testbed.cpp:10:35: note: #pragma message: something BOOST_PRAGMA_MESSAGE( "something" )
Edward Diener wrote:
Use:
BOOST_PRAGMA_MESSAGE( "something" )
Shouldn't this be:
BOOST_PRAGMA_MESSAGE( something )
Maybe. Should it be? #pragma message does take a quoted string: #pragma message( "something" ) as opposed to #warning, which doesn't: #warning something Since the macro is called PRAGMA_MESSAGE, a quoted string seemed more appropriate.
On 12/2/2017 5:09 PM, Peter Dimov via Boost wrote:
Edward Diener wrote:
Use:
BOOST_PRAGMA_MESSAGE( "something" )
Shouldn't this be:
BOOST_PRAGMA_MESSAGE( something )
Maybe. Should it be?
#pragma message does take a quoted string:
#pragma message( "something" )
as opposed to #warning, which doesn't:
#warning something
Since the macro is called PRAGMA_MESSAGE, a quoted string seemed more appropriate.
The BOOST_PRAGMA_MESSAGE which you showed expands its parameter to a quoted string by the eventual use of the # as the stringizing operator in the macro expansion.
Edward Diener wrote:
The BOOST_PRAGMA_MESSAGE which you showed expands its parameter to a quoted string by the eventual use of the # as the stringizing operator in the macro expansion.
Ah, you're saying that I made an error. No, I haven't, what I posted works, I copied and pasted the real output.
On 12/2/2017 10:27 PM, Peter Dimov via Boost wrote:
Edward Diener wrote:
The BOOST_PRAGMA_MESSAGE which you showed expands its parameter to a quoted string by the eventual use of the # as the stringizing operator in the macro expansion.
Ah, you're saying that I made an error. No, I haven't, what I posted works, I copied and pasted the real output.
You are correct. So your original post was a question as to what library the macro should be added ? I vote for core.
________________________________________ From: Boost [boost-bounces@lists.boost.org] on behalf of Edward Diener via Boost [boost@lists.boost.org] Sent: 03 December 2017 03:44
To: boost@lists.boost.org Cc: Edward Diener Subject: Re: [boost] BOOST_PRAGMA_MESSAGE?
On 12/2/2017 10:27 PM, Peter Dimov via Boost wrote: Edward Diener wrote:
The BOOST_PRAGMA_MESSAGE which you showed expands its parameter to a quoted string by the eventual use of the # as the stringizing operator in the macro expansion.
Ah, you're saying that I made an error. No, I haven't, what I posted works, I copied and pasted the real output.
You are correct.
So your original post was a question as to what library the macro should be added ? I vote for core.
Please note that the Clang compiler needs some attention here. For some reason Clang defines __GNUC__ as 4.2.1 so it is necessary to test for e.g. __clang_major__ before testing for __GNUC__. After some experimenting I can offer you this: #if defined(__clang_major__) #define STR(X) #X #define DEFER(M,...) M(__VA_ARGS__) #define BOOST_PRAGMA_MESSAGE(X) _Pragma(STR(message (X " at line " DEFER(STR,__LINE__)))) #elif defined( __GNUC__ ) .... the rest of your code. My output is like this: pragma.cpp:23:1: warning: something at line 23 [-W#pragma-messages] BOOST_PRAGMA_MESSAGE( "something" ) ^ pragma.cpp:11:33: note: expanded from macro 'BOOST_PRAGMA_MESSAGE' #define BOOST_PRAGMA_MESSAGE(X) _Pragma(STR(message (X " at line " DEFER... ^ <scratch space>:3:2: note: expanded from here message ("something" " at line " DEFER(STR,__LINE__)) I have tried that with Clang 3.6, 4.0 and 5.0 I hope this helps John Fletcher _______________________________________________ Unsubscribe & other changes: https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Flists.boost.org%2Fmailman%2Flistinfo.cgi%2Fboost&data=02%7C01%7CJ.P.Fletcher%40aston.ac.uk%7C37efe8f718cb406c50ca08d53a00464f%7Ca085950c4c2544d5945ab852fa44a221%7C0%7C0%7C636478695210047580&sdata=XRTmIR%2BTfwXJmPs90uGvMgrp9PXxpJoMdjznMjlqW20%3D&reserved=0
Fletcher, John P wrote:
Please note that the Clang compiler needs some attention here. For some reason Clang defines __GNUC__ as 4.2.1...
I know, the code relies on this, clang handles the __GNUC__ implementation fine.
My output is like this:
pragma.cpp:23:1: warning: something at line 23 [-W#pragma-messages] BOOST_PRAGMA_MESSAGE( "something" ) ^
That's what I get with the code as posted, too. C:\Projects\testbed>clang++ testbed.cpp testbed.cpp:12:1: warning: something [-W#pragma-messages] BOOST_PRAGMA_MESSAGE( "something" ) ^
________________________________________ From: Boost [boost-bounces@lists.boost.org] on behalf of Peter Dimov via Boost [boost@lists.boost.org] Sent: 03 December 2017 18:40 To: boost@lists.boost.org Cc: Peter Dimov Subject: Re: [boost] BOOST_PRAGMA_MESSAGE?
Fletcher, John P wrote:
Please note that the Clang compiler needs some attention here. For some reason Clang defines __GNUC__ as 4.2.1...
I know, the code relies on this, clang handles the __GNUC__ implementation fine.
My output is like this:
pragma.cpp:23:1: warning: something at line 23 [-W#pragma-messages] BOOST_PRAGMA_MESSAGE( "something" ) ^
That's what I get with the code as posted, too.
C:\Projects\testbed>clang++ testbed.cpp testbed.cpp:12:1: warning: something [-W#pragma-messages] BOOST_PRAGMA_MESSAGE( "something" ) ^
My aim was to reduce the number of extra lines of output. Mine has 2 extra lines against 3 for yours. The line starting <scratch space> seems to be a feature of the Clang implementation of _Pragma. I still think it is better to test for clang explicitly rather than to rely on it pretending to be something else. John _______________________________________________ Unsubscribe & other changes: https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Flists.boost.org%2Fmailman%2Flistinfo.cgi%2Fboost&data=02%7C01%7CJ.P.Fletcher%40aston.ac.uk%7C6560565f11fa41526c4308d53a7d9509%7Ca085950c4c2544d5945ab852fa44a221%7C0%7C0%7C636479233410516850&sdata=AeIXP9H4yMJbiYgmgrVdDQ4i%2FDQPv3HGA4dvyho7Rbg%3D&reserved=0
Fletcher, John P wrote:
My aim was to reduce the number of extra lines of output. Mine has 2 extra lines against 3 for yours. The line starting <scratch space> seems to be a feature of the Clang implementation of _Pragma.
Ah. #define BOOST_PRAGMA_MESSAGE( x ) _Pragma(BOOST_STRINGIZE(message(x))) then. This works for g++ too, no need to make it clang-specific.
Edward Diener wrote:
So your original post was a question as to what library the macro should be added ? I vote for core.
I decided to propose it for Config, since it would be useful there as well, as Config itself needs to emit messages via the preprocessor. https://github.com/boostorg/config/pull/195
participants (3)
-
Edward Diener
-
Fletcher, John P
-
Peter Dimov