Bug 71102 - _Pragma("GCC warning ...") should concatenate string literals
Summary: _Pragma("GCC warning ...") should concatenate string literals
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: preprocessor (show other bugs)
Version: 6.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-05-13 12:31 UTC by Zack Weinberg
Modified: 2016-05-13 12:34 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Zack Weinberg 2016-05-13 12:31:45 UTC
Consider

    #define warn1(msg) _Pragma (#msg)
    #define warn(msg) warn1 (GCC warning msg)
    #define lengthy_explanation(name) \
        "This is a long explanation about why `" #name "' is deprecated."

    #define SYMBOL warn(lengthy_explanation(SYMBOL)) 1

    int main(void) { return SYMBOL; }

With gcc (5 and 6), the warning message printed is

    test.c:9:13: warning: This is a long explanation about why `

which is obviously not what was wanted.  (The column position of the diagnostic is also wrong, but that's secondary.)  One could theoretically work around this by not using string literals in lengthy_explanation() but that risks blowing up in one's face if any of the words in the explanation happen to be macros (and also I'm not sure how I would get the quotation marks in there).

n.b. clang gets this right:

    test.c:9:25: warning: This is a long explanation about why `SYMBOL' is
          deprecated. [-W#pragma-messages]