public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/95239] New: Unable to ignore -Wattribute-warning in macro
@ 2020-05-20 15:37 evan@coeus-group.com
  2022-10-19 20:51 ` [Bug c/95239] " lhyatt at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: evan@coeus-group.com @ 2020-05-20 15:37 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95239
           Summary: Unable to ignore -Wattribute-warning in macro
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: evan@coeus-group.com
  Target Milestone: ---

Created attachment 48573
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48573&action=edit
Test case

I'm trying to create a macro which evaluates an expression while ignoring
warnings generated by the warning attribute.  Basically, a slightly simplified
version of what I want is:

  #define IGNORE_WARNING_ATTR(expr) (__extension__({ \
    _Pragma("GCC diagnostic push") \
    _Pragma("GCC diagnostic ignored \"-Wattribute-warning\"") \
    int tmp = expr; \
    _Pragma("GCC diagnostic pop") \
    tmp; \
  }))

However, when I use it I still see the warning.

If I don't use a macro, but instead just do 

    int c = (__extension__({
        _Pragma("GCC diagnostic push")
        _Pragma("GCC diagnostic ignored \"-Wattribute-warning\"")
        int tmp = foo(argc);
        _Pragma("GCC diagnostic pop")
        tmp;
      }));

It works as intended; no warning.

If I use the macro version and preprocess the source file first, then compile
the preprocessed file separately, it works.

If I compile with g++ it works.

Using the attached test case, I get:

$ gcc -E -o warn-pp.c warn.c && gcc -o warn warn-pp.c
$ g++ -o warn warn.c
$ gcc -o warn warn.c
warn.c: In function ‘main’:
warn.c:23:31: warning: call to ‘foo’ declared with attribute warning: Calling
foo [-Wattribute-warning]
   23 |   int b = IGNORE_WARNING_ATTR(foo(argc));
      |                               ^~~~~~~~~
warn.c:4:15: note: in definition of macro ‘IGNORE_WARNING_ATTR’
    4 |     int tmp = expr; \
      |               ^~~~

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

* [Bug c/95239] Unable to ignore -Wattribute-warning in macro
  2020-05-20 15:37 [Bug c/95239] New: Unable to ignore -Wattribute-warning in macro evan@coeus-group.com
@ 2022-10-19 20:51 ` lhyatt at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: lhyatt at gcc dot gnu.org @ 2022-10-19 20:51 UTC (permalink / raw)
  To: gcc-bugs

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

Lewis Hyatt <lhyatt at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE
                 CC|                            |lhyatt at gcc dot gnu.org

--- Comment #1 from Lewis Hyatt <lhyatt at gcc dot gnu.org> ---
Same issue as PR97498.

*** This bug has been marked as a duplicate of bug 97498 ***

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

end of thread, other threads:[~2022-10-19 20:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-20 15:37 [Bug c/95239] New: Unable to ignore -Wattribute-warning in macro evan@coeus-group.com
2022-10-19 20:51 ` [Bug c/95239] " lhyatt 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).