Bug 71003 - __extension__ silences pedwarn for "\e" in C but not in C++
Summary: __extension__ silences pedwarn for "\e" in C but not in C++
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2016-05-08 01:44 UTC by Eric Gallager
Modified: 2022-07-23 10:21 UTC (History)
5 users (show)

See Also:
Host: i386-apple-darwin9.8.0
Target: i386-apple-darwin9.8.0
Build: i386-apple-darwin9.8.0
Known to work:
Known to fail:
Last reconfirmed: 2017-08-18 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Gallager 2016-05-08 01:44:41 UTC
Say I have the following file:

$ cat __extension__.c
const char *str0 = "\e";
const char *str1 = __extension__ "\e";

When I try to compile it with gcc, everything works as expected:

$ /usr/local/bin/gcc -pedantic -c __extension__.c
__extension__.c:1:20: warning: non-ISO-standard escape sequence, '\e'
 const char *str0 = "\e";
                    ^~~~

i.e., it only warns on the string where I left off the __extension__.
However, when I try to compile it with g++, it warns on both strings:

$ /usr/local/bin/g++ -pedantic -c __extension__.c
__extension__.c:1:20: warning: non-ISO-standard escape sequence, '\e'
 const char *str0 = "\e";
                    ^~~~
__extension__.c:2:34: warning: non-ISO-standard escape sequence, '\e'
 const char *str1 = __extension__ "\e";
                                  ^~~~

This behavior is inconsistent. I would expect the warning for the string with __extension__ to be silenced in both cases, not just in C.

g++ version info:

$ /usr/local/bin/g++ -v
Using built-in specs.
COLLECT_GCC=/usr/local/bin/g++
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/i386-apple-darwin9.8.0/7.0.0/lto-wrapper
Target: i386-apple-darwin9.8.0
Configured with: ../configure --disable-werror --enable-languages=c,c++,lto,objc,obj-c++ --enable-stage1-checking=release -C --with-system-libunwind --enable-secureplt --enable-frame-pointer --enable-version-specific-runtime-libs --enable-assert --enable-fat --enable-portable-binary --enable-browser-plugin --enable-gconf-peer --enable-libgcj-debug --enable-gc-debug --enable-interpreter --enable-aot-compile-rpm --enable-java-home --with-x --enable-collections --enable-gstreamer-peer --enable-xmlj --enable-qt-peer --enable-debug --enable-local-sockets --without-isl --enable-objc-gc --enable-maintainer-mode --enable-host-shared CC=/usr/local/bin/gcc CXX=/usr/local/bin/g++ AUTOCONF=/usr/local/bin/autoconf AUTOHEADER=/usr/local/bin/autoheader AUTOM4TE=/usr/local/bin/autom4te AUTORECONF=/usr/local/bin/autoreconf AUTOSCAN=/usr/local/bin/autoscan AUTOUPDATE=/usr/local/bin/autoupdate IFNAMES=/usr/local/bin/ifnames
Thread model: posix
gcc version 7.0.0 20160426 (experimental) (GCC)
Comment 1 Martin Sebor 2017-08-18 15:03:47 UTC
Confirmed.  The manual says clearly that it should work so this is a G++ bug.

'-Wpedantic' does not cause warning messages for use of the alternate keywords
whose names begin and end with '__'.  Pedantic warnings are also disabled in
the expression that follows __extension__.
Comment 2 Eric Gallager 2018-10-07 02:22:16 UTC
(In reply to Martin Sebor from comment #1)
> Confirmed.  The manual says clearly that it should work so this is a G++ bug.
> 
> '-Wpedantic' does not cause warning messages for use of the alternate
> keywords
> whose names begin and end with '__'.  Pedantic warnings are also disabled in
> the expression that follows __extension__.

Thanks for confirming.
Comment 3 Manuel López-Ibáñez 2018-10-08 13:48:23 UTC
I'm pretty sure that this applies to all pedantic warnings that occur while preprocessing:

const int a0 = 0b101010;
const int a1 = __extension__ 0b101010;

C++ lexes everything at once without parsing __extension__. 

Same problem with pragma diagnostics (bug 53431).

Either these warnings are moved from the preprocessor to the FE, that is, somehow delayed, or the preprocessor has to learn about __extension__ and pragma diagnostics.

I'm surprised there is no older report about this.
Comment 4 Jonathan Wakely 2018-10-08 13:56:12 UTC
There's PR 87274 as well.
Comment 5 Eric Gallager 2019-01-08 03:55:30 UTC
(In reply to Manuel López-Ibáñez from comment #3)
> I'm pretty sure that this applies to all pedantic warnings that occur while
> preprocessing:
> 
> const int a0 = 0b101010;
> const int a1 = __extension__ 0b101010;
> 
> C++ lexes everything at once without parsing __extension__. 
> 
> Same problem with pragma diagnostics (bug 53431).
> 
> Either these warnings are moved from the preprocessor to the FE, that is,
> somehow delayed, or the preprocessor has to learn about __extension__ and
> pragma diagnostics.

I think the second option would make more sense
Comment 6 Eric Gallager 2021-07-30 17:59:22 UTC
The issue of __extension__ not working with the preprocessor came up again here: https://gcc.gnu.org/pipermail/gcc-patches/2021-July/575414.html