Supporting string concatenation in _Pragma

231 views
Skip to first unread message

Myriachan

unread,
Jul 24, 2015, 8:55:04 PM7/24/15
to ISO C++ Standard - Future Proposals
It's quite annoying that the C99/C++11 directive _Pragma does not allow you to concatenate strings.  For example, with GCC/clang #pragma message:

#define ASDF "meow"
// OK
#pragma message ASDF ASDF
// Ill-formed: _Pragma takes a string literal argument
_Pragma
("message \"" ASDF "\"")

From reading the Standard, I think that the reason you can't concatenate strings in _Pragma is because string concatenation occurs at a later phase.  Despite this, it seems to me that string concatenation ought to be allowed in a _Pragma for programmers' sake.

By the way, I feel that #pragma message ought to be standardized by C and C++.  It's really simple to define it as outputting a diagnostic with the specified string in the matter of a failed static_assert, but without making the program ill-formed.  And it could be optional to output a diagnostic for it; just make it accepted by all compilers.

If not #pragma message, then add something like #warning and #message, with similar definition to #error.  (The concept of "warning" is not defined by the Standard, so #warning could also be ignored at QoI discretion like #message / #pragma message.)

Melissa

David Krauss

unread,
Jul 24, 2015, 10:16:07 PM7/24/15
to std-pr...@isocpp.org
On 2015–07–25, at 8:55 AM, Myriachan <myri...@gmail.com> wrote:

It's quite annoying that the C99/C++11 directive _Pragma does not allow you to concatenate strings.  For example, with GCC/clang #pragma message:

The typical usage is that you use a STRINGIZE macro to generate the string at the last minute. (If the string is not a literal, anyway.) IIRC that’s what the examples in the standard do. This requires that you don’t have illegal tokens and you don’t care too much about whitespace formatting, but it’s good enough.

Reply all
Reply to author
Forward
0 new messages