public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/107763] New: -Wreturn-type false-positive with fully-covered switch over enum
@ 2022-11-19 19:14 lebedev.ri at gmail dot com
  2022-11-19 19:19 ` [Bug c/107763] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: lebedev.ri at gmail dot com @ 2022-11-19 19:14 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 107763
           Summary: -Wreturn-type false-positive with fully-covered switch
                    over enum
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lebedev.ri at gmail dot com
  Target Milestone: ---

enum a { b };

int foo(a a) {
    switch(a) {
        case b: return 42;
    }
}


The `a` can only have value `a::b`,
so the function always returns 42, yet gcc complains:
> warning: control reaches end of non-void function [-Wreturn-type]

https://godbolt.org/z/j8ezrr5h3

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

* [Bug c/107763] -Wreturn-type false-positive with fully-covered switch over enum
  2022-11-19 19:14 [Bug c/107763] New: -Wreturn-type false-positive with fully-covered switch over enum lebedev.ri at gmail dot com
@ 2022-11-19 19:19 ` pinskia at gcc dot gnu.org
  2022-11-19 19:30 ` [Bug c++/107763] " lebedev.ri at gmail dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-19 19:19 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
>The `a` can only have value `a::b`,

NO, it has a full range of the underlying type. For GCC, see
https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/Structures-unions-enumerations-and-bit-fields-implementation.html#Structures-unions-enumerations-and-bit-fields-implementation

"Normally, the type is unsigned int if there are no negative values in the
enumeration, otherwise int. If -fshort-enums is specified, then if there are
negative values it is the first of signed char, short and int that can
represent all the values, otherwise it is the first of unsigned char, unsigned
short and unsigned int that can represent all the values.

On some targets, -fshort-enums is the default; this is determined by the ABI.

"

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

* [Bug c++/107763] -Wreturn-type false-positive with fully-covered switch over enum
  2022-11-19 19:14 [Bug c/107763] New: -Wreturn-type false-positive with fully-covered switch over enum lebedev.ri at gmail dot com
  2022-11-19 19:19 ` [Bug c/107763] " pinskia at gcc dot gnu.org
@ 2022-11-19 19:30 ` lebedev.ri at gmail dot com
  2022-11-19 19:41 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: lebedev.ri at gmail dot com @ 2022-11-19 19:30 UTC (permalink / raw)
  To: gcc-bugs

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

Roman Lebedev <lebedev.ri at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c                           |c++

--- Comment #2 from Roman Lebedev <lebedev.ri at gmail dot com> ---
(In reply to Andrew Pinski from comment #1)
> >The `a` can only have value `a::b`,
> 
> NO, it has a full range of the underlying type. For GCC, see
> https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/Structures-unions-enumerations-
> and-bit-fields-implementation.html#Structures-unions-enumerations-and-bit-
> fields-implementation
> 
> "Normally, the type is unsigned int if there are no negative values in the
> enumeration, otherwise int. If -fshort-enums is specified, then if there are
> negative values it is the first of signed char, short and int that can
> represent all the values, otherwise it is the first of unsigned char,
> unsigned short and unsigned int that can represent all the values.
> 
> On some targets, -fshort-enums is the default; this is determined by the ABI.
> 
> "

Is this situation different in C++? looks like i set the component wrong.
Is this implementation-defined behavior,
or are you saying that clang is wrong here?

At run time, `a` can not have any other value other than `a::b`:
https://godbolt.org/z/hnc665755
so this really does seem like a bug.

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

* [Bug c++/107763] -Wreturn-type false-positive with fully-covered switch over enum
  2022-11-19 19:14 [Bug c/107763] New: -Wreturn-type false-positive with fully-covered switch over enum lebedev.ri at gmail dot com
  2022-11-19 19:19 ` [Bug c/107763] " pinskia at gcc dot gnu.org
  2022-11-19 19:30 ` [Bug c++/107763] " lebedev.ri at gmail dot com
@ 2022-11-19 19:41 ` pinskia at gcc dot gnu.org
  2022-11-19 19:50 ` pinskia at gcc dot gnu.org
  2022-11-19 20:03 ` lebedev.ri at gmail dot com
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-19 19:41 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
No, it is not different in C++. See PR 91950 for that.

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

* [Bug c++/107763] -Wreturn-type false-positive with fully-covered switch over enum
  2022-11-19 19:14 [Bug c/107763] New: -Wreturn-type false-positive with fully-covered switch over enum lebedev.ri at gmail dot com
                   ` (2 preceding siblings ...)
  2022-11-19 19:41 ` pinskia at gcc dot gnu.org
@ 2022-11-19 19:50 ` pinskia at gcc dot gnu.org
  2022-11-19 20:03 ` lebedev.ri at gmail dot com
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-19 19:50 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Roman Lebedev from comment #2)> 
> Is this situation different in C++? looks like i set the component wrong.
> Is this implementation-defined behavior,
> or are you saying that clang is wrong here?

Yes I think clang is wrong. The spec says: "The value is unchanged if the
original value is within the range of the enumeration values"

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

* [Bug c++/107763] -Wreturn-type false-positive with fully-covered switch over enum
  2022-11-19 19:14 [Bug c/107763] New: -Wreturn-type false-positive with fully-covered switch over enum lebedev.ri at gmail dot com
                   ` (3 preceding siblings ...)
  2022-11-19 19:50 ` pinskia at gcc dot gnu.org
@ 2022-11-19 20:03 ` lebedev.ri at gmail dot com
  4 siblings, 0 replies; 6+ messages in thread
From: lebedev.ri at gmail dot com @ 2022-11-19 20:03 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Roman Lebedev <lebedev.ri at gmail dot com> ---
Thank you.
Forwarded to https://github.com/llvm/llvm-project/issues/59085

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

end of thread, other threads:[~2022-11-19 20:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-19 19:14 [Bug c/107763] New: -Wreturn-type false-positive with fully-covered switch over enum lebedev.ri at gmail dot com
2022-11-19 19:19 ` [Bug c/107763] " pinskia at gcc dot gnu.org
2022-11-19 19:30 ` [Bug c++/107763] " lebedev.ri at gmail dot com
2022-11-19 19:41 ` pinskia at gcc dot gnu.org
2022-11-19 19:50 ` pinskia at gcc dot gnu.org
2022-11-19 20:03 ` lebedev.ri at gmail dot com

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).