Bug 92159 - -Wenum-conversion for C++
Summary: -Wenum-conversion for C++
Status: RESOLVED WORKSFORME
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 10.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2019-10-19 14:26 UTC by Jonny Grant
Modified: 2019-11-21 09:17 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2019-10-21 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jonny Grant 2019-10-19 14:26:10 UTC
Bug 60591 added -Wenum-conversion for C

Could this be added for C++ too?


#1 with x86-64 gcc (trunk)
cc1plus: error: command-line option '-Wenum-conversion' is valid for C/ObjC but not for C++ [-Werror]
cc1plus: all warnings being treated as errors
Compiler returned: 1


Test case

enum xpto
{
  A = 0,
  B = 1,
  X = 512
};

extern void print (unsigned int);

unsigned char bar (enum xpto a)
{
   return a;
}
Comment 1 Jonathan Wakely 2019-10-21 10:33:44 UTC
Your testcase doesn't warn for C.
Comment 2 Jonathan Wakely 2019-10-21 10:41:38 UTC
(In reply to Jonny Grant from comment #0)
> Bug 60591 added -Wenum-conversion for C

I think you mean Bug 78736, and the C option doesn't warn for your testcase. It warns for conversions from one enumeration type to another enumeration type, which is already ill-formed in C++. Adding a warning for something that doesn't compile anyway is useless.

Please clarify exactly what you're asking for.
Comment 3 Jonathan Wakely 2019-10-21 10:46:25 UTC
This doesn't seem to warn with Clang or Clang++ either.
Comment 4 Jonny Grant 2019-10-22 15:53:26 UTC
My apologies, I tested with the correct test case and it already does not compile in C++ as desired, so no -Wenum-conversion required.


#include <stdio.h>

typedef enum {brandon, jon, mitch} name_t;
typedef enum {fred, dog, cat} name2_t;
name2_t name = brandon;
name_t hik = 3;


int hal_entry(void)
{

    if (hik < name)

        return(0);
    return 1;
}

int main ()
{
	printf ("%d\n", hal_entry());
	return 0;
}
Comment 5 Jonathan Wakely 2019-10-22 16:23:14 UTC
Thanks, let's close this then.