https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71102

            Bug ID: 71102
           Summary: _Pragma("GCC warning ...") should concatenate string
                    literals
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: preprocessor
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zackw at panix dot com
  Target Milestone: ---

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]

Reply via email to