Bug 52116 - pragma GCC diagnostic only acts on some lines
Summary: pragma GCC diagnostic only acts on some lines
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2012-02-03 19:35 UTC by Ben Longbons
Modified: 2016-08-09 17:40 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-02-04 00:00:00


Attachments
two and a half testcases (226 bytes, text/x-csrc)
2012-02-03 19:35 UTC, Ben Longbons
Details
patch to fix (2) (696 bytes, patch)
2012-02-04 11:09 UTC, Manuel López-Ibáñez
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ben Longbons 2012-02-03 19:35:05 UTC
Created attachment 26567 [details]
two and a half testcases

The attachment has two cases, but I think it might be the same bug. The second case is much easier to understand.

Case 1. Wrapping a warning location in _Pragma("GCC diagnostic ignored \"-Wshadow\"") does not work (sometimes). This precludes error suppression during macro expansion. Oddly, it suppresses as expected (mostly) if both are on the same line. (Although it behaves oddly if one is "warning" and one is "ignored")

Case 2:
If an error has multiple locations, such as "-Wshadow", it will still be reported at the original location, if it is suppressed at the new location.

This leads to a confusing, isolated message:
error: shadowed declaration is here [-Werror=shadow]

Tested: Debian GCC 4.6.2-11, GCC trunk r183363
Comment 1 Manuel López-Ibáñez 2012-02-04 11:09:44 UTC
Created attachment 26572 [details]
patch to fix (2)

I am not surprised. Location information in GCC is not very precise. Have you tested with GCC 4.7?

For 1), someone would need to look more closely at the locations recorded by each pragma, and compare them with the locations of the diagnostic.

Fixing 2) is easier. Just check the output of the first diagnostic and only emit the second if the output was true. Also, change the second warning() to inform(). An untested patch attached. Feel free to take it, test it and submit it. http://gcc.gnu.org/contribute.html
Comment 2 Ben Longbons 2012-02-04 18:30:46 UTC
ah, got home where I have a bunch of versions ...

GCC < 4.6 fail with error: #pragma GCC diagnostic not allowed inside functions

GCC 4.6.{0,1,2}, branch-4.6 r183147, and trunk r182496,r182728,r183173 also fail as described in this report. (Note that I already mentioned Debian GCC 4.6.2-11, GCC trunk r183363)
Comment 3 Manuel López-Ibáñez 2012-02-04 18:41:25 UTC
(In reply to comment #2)
> ah, got home where I have a bunch of versions ...

Since this is not a regression and GCC 4.7 is close to release, I don't think this will be fixed before GCC 4.8. Nonetheless, you can get the patch approved now for GCC 4.8, so it is committed as soon as the 4.8 branch is created.
Comment 4 Manuel López-Ibáñez 2012-02-13 17:24:31 UTC
Problem (2) is a duplicate of PR48062
Comment 5 Manuel López-Ibáñez 2016-08-09 17:40:26 UTC
(In reply to Ben Longbons from comment #0)
> Case 1. Wrapping a warning location in _Pragma("GCC diagnostic ignored
> \"-Wshadow\"") does not work (sometimes). This precludes error suppression
> during macro expansion. Oddly, it suppresses as expected (mostly) if both
> are on the same line. (Although it behaves oddly if one is "warning" and one
> is "ignored")

This seems fixed in GCC 7.0, possibly earlier.