public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* gcc warn C++ implicit enum conversion
@ 2019-07-01 22:40 Jonny Grant
  2019-07-02  7:47 ` Jonathan Wakely
  0 siblings, 1 reply; 3+ messages in thread
From: Jonny Grant @ 2019-07-01 22:40 UTC (permalink / raw)
  To: gcc-help

Hi
Is there any way to warn on enum conversion to int? I tried few options, 
but no warning seems possible.

Cheers, Jonny

//-O2 -Wall -Wextra -Wconversion -Werror

#include <cstddef>
typedef enum
{
     a = -1
} a_t;

a_t f()
{
     return a;
}

int main()
{
     int b = f();
     return b;
}

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

* Re: gcc warn C++ implicit enum conversion
  2019-07-01 22:40 gcc warn C++ implicit enum conversion Jonny Grant
@ 2019-07-02  7:47 ` Jonathan Wakely
  2019-07-02  9:24   ` Jonny Grant
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Wakely @ 2019-07-02  7:47 UTC (permalink / raw)
  To: Jonny Grant; +Cc: gcc-help

On Mon, 1 Jul 2019 at 23:40, Jonny Grant wrote:
>
> Hi
> Is there any way to warn on enum conversion to int?

I don't think so.

I'd just use 'enum class' so the conversion is forbidden, and insert
explicit casts where you want the conversion to compile.

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

* Re: gcc warn C++ implicit enum conversion
  2019-07-02  7:47 ` Jonathan Wakely
@ 2019-07-02  9:24   ` Jonny Grant
  0 siblings, 0 replies; 3+ messages in thread
From: Jonny Grant @ 2019-07-02  9:24 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: gcc-help



On 02/07/2019 08:47, Jonathan Wakely wrote:
> On Mon, 1 Jul 2019 at 23:40, Jonny Grant wrote:
>>
>> Hi
>> Is there any way to warn on enum conversion to int?
> 
> I don't think so.
> 
> I'd just use 'enum class' so the conversion is forbidden, and insert
> explicit casts where you want the conversion to compile.
> 

Thank you. I better update codebase to use 'enum class' to get these 
warnings.

Thanks, Jonny

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

end of thread, other threads:[~2019-07-02  9:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-01 22:40 gcc warn C++ implicit enum conversion Jonny Grant
2019-07-02  7:47 ` Jonathan Wakely
2019-07-02  9:24   ` Jonny Grant

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