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

            Bug ID: 103869
           Summary: better diagnostics surrounding uses of -fms-extensions
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: diagnostic, documentation
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: egallager at gcc dot gnu.org
  Target Milestone: ---

I am putting this under the "C" component because the option is documented
under the list of C Dialect Options:
https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html#C-Dialect-Options
However, it could also be considered a C++ bug as per bug 71283.

Let's start with the example code provided for the option:
$ cat ms-extensions.c
typedef int UOW;
struct ABC {
  UOW UOW;
};
$

The manual says, "In C++ code, this allows member names in structures to be
similar to previous types declarations." However, when compiling with the C
front-end, -Wc++-compat doesn't say anything about -fms-extensions allowing it,
nor does explicitly providing -fms-extensions silence it:
$ /usr/local/bin/gcc -c -Wall -Wextra -pedantic -Wshadow -Wc++-compat
ms-extensions.c
ms-extensions.c:3:7: warning: using 'UOW' as both field and typedef name is
invalid in C++ [-Wc++-compat]
    3 |   UOW UOW;
      |       ^~~
$ /usr/local/bin/gcc -c -Wall -Wextra -pedantic -Wshadow -Wc++-compat
-fms-extensions ms-extensions.c
ms-extensions.c:3:7: warning: using 'UOW' as both field and typedef name is
invalid in C++ [-Wc++-compat]
    3 |   UOW UOW;
      |       ^~~
$

Meanwhile, with the C++ front-end, the error message only notes -fpermissive as
a way to allow it, but not -fms-extensions:

$ /usr/local/bin/g++ -c -Wall -Wextra -pedantic -Wshadow ms-extensions.c
ms-extensions.c:3:7: error: declaration of 'UOW ABC::UOW' changes meaning of
'UOW' [-fpermissive]
    3 |   UOW UOW;
      |       ^~~
ms-extensions.c:1:13: note: 'UOW' declared here as 'typedef int UOW'
    1 | typedef int UOW;
      |             ^~~
$

-fpermissive turns the error into a warning, but providing -fms-extensions
removes even the warning:
$ /usr/local/bin/g++ -c -Wall -Wextra -pedantic -Wshadow -fpermissive
ms-extensions.c
ms-extensions.c:3:7: warning: declaration of 'UOW ABC::UOW' changes meaning of
'UOW' [-fpermissive]
    3 |   UOW UOW;
      |       ^~~
ms-extensions.c:1:13: note: 'UOW' declared here as 'typedef int UOW'
    1 | typedef int UOW;
      |             ^~~
$ /usr/local/bin/g++ -c -Wall -Wextra -pedantic -Wshadow -fpermissive
-fms-extensions ms-extensions.c
$ /usr/local/bin/g++ -c -Wall -Wextra -pedantic -Wshadow -fms-extensions
ms-extensions.c
$

IMO there should be a separate pedwarn even with -fms-extensions controlled by
a separate -Wms-extensions to complain in the -pedantic -fms-extensions case,
which could then be disabled with -pedantic -fms-extensions -Wno-ms-extensions
(or just -Wno-pedantic), e.g.:

$ /usr/local/bin/g++ -c -Wall -Wextra -pedantic -Wshadow -fms-extensions
ms-extensions.c
ms-extensions.c:3:7: warning: declaration of 'UOW ABC::UOW' is only being
allowed due to -fms-extensions [-Wms-extensions]
    3 |   UOW UOW;
      |       ^~~
ms-extensions.c:1:13: note: 'UOW' declared here as 'typedef int UOW'
    1 | typedef int UOW;
      |             ^~~
$

Alternatively, the additional complaint could come from -Wshadow instead.
Anyways, there are lots of possibilities here; let's try to come up with a
consensus as to what would work best.
  • [Bug c/103869] New: better diagn... egallager at gcc dot gnu.org via Gcc-bugs

Reply via email to