public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/103084] New: Accepts invalid using enum declaration with an invalid elaborated-type-specifier
@ 2021-11-04 17:06 aaron at aaronballman dot com
  2021-11-04 17:11 ` [Bug c++/103084] " mpolacek at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: aaron at aaronballman dot com @ 2021-11-04 17:06 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 103084
           Summary: Accepts invalid using enum declaration with an invalid
                    elaborated-type-specifier
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: aaron at aaronballman dot com
  Target Milestone: ---

GCC (and MSVC) currently accepts the following snippet while Clang and ICC
reject:
```
enum class Pig { Oink };
using Hog = Pig;
using enum Hog; // Clang & ICC rejects, GCC & MSVC accepts
```
I think Clang and ICC are correct to reject this code.
http://eel.is/c++draft/enum.udecl says that the production needs to parse an
elaborated-enum-specifier. One of the requirements for a valid
elaborated-enum-specifier is that the elaboration has to agree in kind with the
given declaration (https://eel.is/c++draft/dcl.type.elab#6). In this case, the
given declaration is not an enum, it's a type alias.

Note that all compilers reject the following slightly different example due to
the elaborated type specifier being invalid:
```
enum class Pig { Oink };
using Hog = Pig;
enum Hog H; // Everyone rejects
```

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

* [Bug c++/103084] Accepts invalid using enum declaration with an invalid elaborated-type-specifier
  2021-11-04 17:06 [Bug c++/103084] New: Accepts invalid using enum declaration with an invalid elaborated-type-specifier aaron at aaronballman dot com
@ 2021-11-04 17:11 ` mpolacek at gcc dot gnu.org
  2021-11-04 17:50 ` mpolacek at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-11-04 17:11 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2021-11-04
             Status|UNCONFIRMED                 |NEW
           Keywords|                            |accepts-invalid
                 CC|                            |mpolacek at gcc dot gnu.org

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Confirmed.

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

* [Bug c++/103084] Accepts invalid using enum declaration with an invalid elaborated-type-specifier
  2021-11-04 17:06 [Bug c++/103084] New: Accepts invalid using enum declaration with an invalid elaborated-type-specifier aaron at aaronballman dot com
  2021-11-04 17:11 ` [Bug c++/103084] " mpolacek at gcc dot gnu.org
@ 2021-11-04 17:50 ` mpolacek at gcc dot gnu.org
  2021-11-04 18:06 ` terra at gnome dot org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-11-04 17:50 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |terra at gnome dot org

--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
*** Bug 103087 has been marked as a duplicate of this bug. ***

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

* [Bug c++/103084] Accepts invalid using enum declaration with an invalid elaborated-type-specifier
  2021-11-04 17:06 [Bug c++/103084] New: Accepts invalid using enum declaration with an invalid elaborated-type-specifier aaron at aaronballman dot com
  2021-11-04 17:11 ` [Bug c++/103084] " mpolacek at gcc dot gnu.org
  2021-11-04 17:50 ` mpolacek at gcc dot gnu.org
@ 2021-11-04 18:06 ` terra at gnome dot org
  2021-11-04 18:33 ` mpolacek at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: terra at gnome dot org @ 2021-11-04 18:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from M Welinder <terra at gnome dot org> ---
I actually think gcc is right there.

http://eel.is/c++draft/dcl.type.elab#nt:elaborated-enum-specifier

There are requirements for elaborated-type-specifier, but none for 
elaborated-enum-specifier.  It's a separate production.

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

* [Bug c++/103084] Accepts invalid using enum declaration with an invalid elaborated-type-specifier
  2021-11-04 17:06 [Bug c++/103084] New: Accepts invalid using enum declaration with an invalid elaborated-type-specifier aaron at aaronballman dot com
                   ` (2 preceding siblings ...)
  2021-11-04 18:06 ` terra at gnome dot org
@ 2021-11-04 18:33 ` mpolacek at gcc dot gnu.org
  2021-11-04 18:38 ` aaron at aaronballman dot com
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-11-04 18:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
But elaborated-enum-specifier is an elaborated-type-specifier, so
[dcl.type.elab]#6 should still apply, right?

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

* [Bug c++/103084] Accepts invalid using enum declaration with an invalid elaborated-type-specifier
  2021-11-04 17:06 [Bug c++/103084] New: Accepts invalid using enum declaration with an invalid elaborated-type-specifier aaron at aaronballman dot com
                   ` (3 preceding siblings ...)
  2021-11-04 18:33 ` mpolacek at gcc dot gnu.org
@ 2021-11-04 18:38 ` aaron at aaronballman dot com
  2021-11-04 18:45 ` terra at gnome dot org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: aaron at aaronballman dot com @ 2021-11-04 18:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Aaron Ballman <aaron at aaronballman dot com> ---
(In reply to Marek Polacek from comment #4)
> But elaborated-enum-specifier is an elaborated-type-specifier, so
> [dcl.type.elab]#6 should still apply, right?

That is my understanding. Otherwise p6 doesn't make much sense when it says
"The class-key or enum keyword present in the elaborated-type-specifier shall
agree" because that production has no enum keyword directly within it.

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

* [Bug c++/103084] Accepts invalid using enum declaration with an invalid elaborated-type-specifier
  2021-11-04 17:06 [Bug c++/103084] New: Accepts invalid using enum declaration with an invalid elaborated-type-specifier aaron at aaronballman dot com
                   ` (4 preceding siblings ...)
  2021-11-04 18:38 ` aaron at aaronballman dot com
@ 2021-11-04 18:45 ` terra at gnome dot org
  2021-11-04 18:54 ` terra at gnome dot org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: terra at gnome dot org @ 2021-11-04 18:45 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from M Welinder <terra at gnome dot org> ---
elaborated-enum-specifier can be a elaborated-type-specifier.  It is in the
"enum Hog H;" case.

But elaborated-enum-specifier is NOT an elaborated-type-specifier in the "using
enum Hog;" case,

See http://eel.is/c++draft/enum.udecl -- this uses elaborated-enum-specifier
directly.

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

* [Bug c++/103084] Accepts invalid using enum declaration with an invalid elaborated-type-specifier
  2021-11-04 17:06 [Bug c++/103084] New: Accepts invalid using enum declaration with an invalid elaborated-type-specifier aaron at aaronballman dot com
                   ` (5 preceding siblings ...)
  2021-11-04 18:45 ` terra at gnome dot org
@ 2021-11-04 18:54 ` terra at gnome dot org
  2021-11-04 19:07 ` aaron at aaronballman dot com
  2021-11-05 14:44 ` terra at gnome dot org
  8 siblings, 0 replies; 10+ messages in thread
From: terra at gnome dot org @ 2021-11-04 18:54 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from M Welinder <terra at gnome dot org> ---
Maybe kick it up to the C++ people?

Note, that if the code is not allowed then a type alias is no longer as
powerful as the original type.  I really doubt that was intended.

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

* [Bug c++/103084] Accepts invalid using enum declaration with an invalid elaborated-type-specifier
  2021-11-04 17:06 [Bug c++/103084] New: Accepts invalid using enum declaration with an invalid elaborated-type-specifier aaron at aaronballman dot com
                   ` (6 preceding siblings ...)
  2021-11-04 18:54 ` terra at gnome dot org
@ 2021-11-04 19:07 ` aaron at aaronballman dot com
  2021-11-05 14:44 ` terra at gnome dot org
  8 siblings, 0 replies; 10+ messages in thread
From: aaron at aaronballman dot com @ 2021-11-04 19:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Aaron Ballman <aaron at aaronballman dot com> ---
(In reply to M Welinder from comment #6)
> elaborated-enum-specifier can be a elaborated-type-specifier.  It is in the
> "enum Hog H;" case.
> 
> But elaborated-enum-specifier is NOT an elaborated-type-specifier in the
> "using enum Hog;" case,
> 
> See http://eel.is/c++draft/enum.udecl -- this uses elaborated-enum-specifier
> directly.

You're correct about the productions, but http://eel.is/c++draft/dcl.type.elab
then provides no semantics whatsoever for what type is referred to by an
elaborated-enum-specifier. https://eel.is/c++draft/dcl.type.elab#6 would not
apply, so the only requirement on the type then comes from
http://eel.is/c++draft/enum.udecl#1, which says that the type referred to must
be a reachable enum-specifier. But the type named isn't a reachable
enum-specifier (maybe, who knows, no semantics means we can't really say), it's
a type alias to an enum-specifier. So there's confusion either way you read it,
IMO.

(In reply to M Welinder from comment #7)
> Maybe kick it up to the C++ people?
>
> Note, that if the code is not allowed then a type alias is no longer as
> powerful as the original type.  I really doubt that was intended.

FWIW, my initial inclination was that Clang and ICC were wrong to reject
because this does seem like a useful construct that should be supported. It is
possible there's a Core issue here and that this should not be rejected. The
original paper on the topic doesn't say anything, and I didn't see a mention of
type aliases in the WG21 wiki discussions for the paper, but it's entirely
possible I missed something while looking. So I agree that it'd be useful to
allow this, but I'm not convinced the standard permits it currently.

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

* [Bug c++/103084] Accepts invalid using enum declaration with an invalid elaborated-type-specifier
  2021-11-04 17:06 [Bug c++/103084] New: Accepts invalid using enum declaration with an invalid elaborated-type-specifier aaron at aaronballman dot com
                   ` (7 preceding siblings ...)
  2021-11-04 19:07 ` aaron at aaronballman dot com
@ 2021-11-05 14:44 ` terra at gnome dot org
  8 siblings, 0 replies; 10+ messages in thread
From: terra at gnome dot org @ 2021-11-05 14:44 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from M Welinder <terra at gnome dot org> ---
I went back and looked at the proposal's revision history.

TLDR: this just adds to the confusion.


r3 (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1099r3.html):
* I read it as allowing "using enum Hog;"
* No mention of elaborated-type-specifier

r4 (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1099r4.html):
* I read it as *dis*allowing "using enum Hog;"
* "using enum foo" defined in terms of elaborated-type-specifier (not -enum-)

r5 (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1099r5.html):
* This is the version that was approved
* elaborated-enum-specifier first appears here
* "using enum foo" defined in terms of elaborated-enum-specifier

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

end of thread, other threads:[~2021-11-05 14:44 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-04 17:06 [Bug c++/103084] New: Accepts invalid using enum declaration with an invalid elaborated-type-specifier aaron at aaronballman dot com
2021-11-04 17:11 ` [Bug c++/103084] " mpolacek at gcc dot gnu.org
2021-11-04 17:50 ` mpolacek at gcc dot gnu.org
2021-11-04 18:06 ` terra at gnome dot org
2021-11-04 18:33 ` mpolacek at gcc dot gnu.org
2021-11-04 18:38 ` aaron at aaronballman dot com
2021-11-04 18:45 ` terra at gnome dot org
2021-11-04 18:54 ` terra at gnome dot org
2021-11-04 19:07 ` aaron at aaronballman dot com
2021-11-05 14:44 ` terra at gnome dot 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).