public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug preprocessor/99315] New: #pragma GCC warning does not concatenate string literals
@ 2021-03-01 10:14 fweimer at redhat dot com
  2021-03-01 10:27 ` [Bug preprocessor/99315] " jakub at gcc dot gnu.org
  2021-03-02  9:34 ` jakub at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: fweimer at redhat dot com @ 2021-03-01 10:14 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 99315
           Summary: #pragma GCC warning does not concatenate string
                    literals
           Product: gcc
           Version: 10.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: preprocessor
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fweimer at redhat dot com
  Target Milestone: ---

This:

#pragma GCC warning "foo" "bar"
#pragma GCC error "foo" "bar"

produces:

/tmp/t.c:1:21: warning: foo
    1 | #pragma GCC warning "foo" "bar"
      |                     ^~~~~
/tmp/t.c:2:19: error: foo
    2 | #pragma GCC error "foo" "bar"
      |                   ^~~~~

It is an oversight in the processing of the pragma arguments. Clang produces
this, which is closer to developer expectations:

/tmp/t.c:1:13: warning: foobar [-W#pragma-messages]
/tmp/t.c:2:13: error: foobar

(Another option would be to error out on multiple arguments to the pragma.)

This is not a regression, it's a bug that's always been present.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug preprocessor/99315] #pragma GCC warning does not concatenate string literals
  2021-03-01 10:14 [Bug preprocessor/99315] New: #pragma GCC warning does not concatenate string literals fweimer at redhat dot com
@ 2021-03-01 10:27 ` jakub at gcc dot gnu.org
  2021-03-02  9:34 ` jakub at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-03-01 10:27 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2021-03-01
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Note, string literal concatenation is implemented in c_parser_string_literal in
the C FE and in cp_parser_string_literal in the C++ FE.
Pragma processing is during translation phase 4 while string literal
concatenation is translation phase 6, plus these pragmas are GCC extension, so
we can do whatever we want, but perhaps handling the string literal
concatenation and erroring out on other arguments after it wouldn't be a bad
idea for GCC 12+.
As the pragmas handle just CPP_STRING, it wouldn't have to handle e.g. mixing
of the various string literal types etc.

Note, currently we diagnose as error
#pragma GCC warning ""
but we should error just on that form and not e.g. on
#pragma GCC warning "" "" "" "foobar"

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug preprocessor/99315] #pragma GCC warning does not concatenate string literals
  2021-03-01 10:14 [Bug preprocessor/99315] New: #pragma GCC warning does not concatenate string literals fweimer at redhat dot com
  2021-03-01 10:27 ` [Bug preprocessor/99315] " jakub at gcc dot gnu.org
@ 2021-03-02  9:34 ` jakub at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-03-02  9:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Also, I'd add that
#pragma message "foo " "bar " "baz"
already works fine because it is done in the FE and not in libcpp and so it can
use pragma_lex under the hood to do this.
And, it also has
  if (pragma_lex (&x) != CPP_EOF)
    warning (OPT_Wpragmas, "junk at end of %<#pragma pack%>");
message at the end in case one uses
#pragma message 4
or
#pragma message "foo" 4
etc.
I think #pragma GCC {warning,error} can stay where it is, but it would be nice
if it behaved the same way.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-03-02  9:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-01 10:14 [Bug preprocessor/99315] New: #pragma GCC warning does not concatenate string literals fweimer at redhat dot com
2021-03-01 10:27 ` [Bug preprocessor/99315] " jakub at gcc dot gnu.org
2021-03-02  9:34 ` jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).