public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "egallager at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/103869] New: better diagnostics surrounding uses of -fms-extensions
Date: Thu, 30 Dec 2021 19:57:22 +0000	[thread overview]
Message-ID: <bug-103869-4@http.gcc.gnu.org/bugzilla/> (raw)

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.

             reply	other threads:[~2021-12-30 19:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-30 19:57 egallager at gcc dot gnu.org [this message]
2021-12-30 21:53 ` [Bug c++/103869] " pinskia at gcc dot gnu.org
2023-02-01 18:40 ` jason at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-103869-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).