int hex = colour_to_hex(10);
... then the compiler doesn't complain that 10 is not in the enum.
Why? Surely the compiler can tell.
Richard Harnden <richard.nospam@gmail.invalid> wrote or quoted:
int hex = colour_to_hex(10);
... then the compiler doesn't complain that 10 is not in the enum.
Why? Surely the compiler can tell.
I get
|
|error: enum conversion when passing argument 1 of 'colour_to_hex' is invalid in C++ [-Wc++-compat]
| |int hex = colour_to_hex(10);
| | ^~
|note: expected 'enum colour' but argument is of type 'int'
| | int colour_to_hex(enum colour colour)
| | ^~~~~~~~~~~~~
|
with
gcc -Wc++-compat
Richard Harnden <richard.nospam@gmail.invalid> wrote or quoted:
int hex = colour_to_hex(10);
... then the compiler doesn't complain that 10 is not in the enum.
Why? Surely the compiler can tell.
I get
|
|error: enum conversion when passing argument 1 of 'colour_to_hex' is invalid in C++ [-Wc++-compat]
| |int hex = colour_to_hex(10);
| | ^~
|note: expected 'enum colour' but argument is of type 'int'
| | int colour_to_hex(enum colour colour)
| | ^~~~~~~~~~~~~
|
with
gcc -Wc++-compat
int hex = colour_to_hex(10);
Em 4/5/2025 7:29 AM, Richard Harnden escreveu:
If I have:
enum colour {RED, GREEN, BLUE}
int colour_to_hex(enum colour colour)
{
switch (colour)
{
RED: return 0xff0000;
GREEN: return 0x00ff00;
// BLUE: return 0x0000ff;
}
...
}
... then the compiler will warn me that I've missed a case in the
switch statement. Which is good and very helpful.
But if I do:
int hex = colour_to_hex(10);
... then the compiler doesn't complain that 10 is not in the enum.
Why? Surely the compiler can tell.
Sometimes enums are used as bit set.
f(BIT1 | BIT2)
this situation would generate a lot of warning because BIT1|BIT2 is not
part of the enum, just BIT1 and BIT2 separately.
One way that this could be fixed is adding an attribute
[[bitset]]
enum E{ BIT1 = 2, BIT2 = 4};
Then the compiler would not generate a warning in this case.
ram@zedat.fu-berlin.de (Stefan Ram) writes:
Richard Harnden <richard.nospam@gmail.invalid> wrote or quoted:
int hex = colour_to_hex(10);
... then the compiler doesn't complain that 10 is not in the enum.
Why? Surely the compiler can tell.
I get
|
|error: enum conversion when passing argument 1 of 'colour_to_hex' is
invalid in C++ [-Wc++-compat]
| |int hex = colour_to_hex(10);
| | ^~
|note: expected 'enum colour' but argument is of type 'int'
| | int colour_to_hex(enum colour colour)
| | ^~~~~~~~~~~~~
|
with
gcc -Wc++-compat
That example exemplifies the seriously screwed up error reporting in the
gnu compiler collection.
One line of informative error message followed by 5 lines of useless
cruft to wade through. And no way to turn it off completely.
scott@slp53.sl.home (Scott Lurndal) writes:
ram@zedat.fu-berlin.de (Stefan Ram) writes:
Richard Harnden <richard.nospam@gmail.invalid> wrote or quoted:
int hex = colour_to_hex(10);
... then the compiler doesn't complain that 10 is not in the enum.
Why? Surely the compiler can tell.
I get
|
|error: enum conversion when passing argument 1 of 'colour_to_hex' is
invalid in C++ [-Wc++-compat]
| |int hex = colour_to_hex(10);
| | ^~
|note: expected 'enum colour' but argument is of type 'int'
| | int colour_to_hex(enum colour colour)
| | ^~~~~~~~~~~~~
|
with
gcc -Wc++-compat
That example exemplifies the seriously screwed up error reporting in the
gnu compiler collection.
One line of informative error message followed by 5 lines of useless
cruft to wade through. And no way to turn it off completely.
That's true, but it can be reduced to only two lines total (so only one
line more than needed), by using -fno-diagnostics-show-caret.
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
scott@slp53.sl.home (Scott Lurndal) writes:
ram@zedat.fu-berlin.de (Stefan Ram) writes:
Richard Harnden <richard.nospam@gmail.invalid> wrote or quoted:
int hex = colour_to_hex(10);
... then the compiler doesn't complain that 10 is not in the enum.
Why? Surely the compiler can tell.
I get
|
|error: enum conversion when passing argument 1 of 'colour_to_hex' is
invalid in C++ [-Wc++-compat]
| |int hex = colour_to_hex(10);
| | ^~
|note: expected 'enum colour' but argument is of type 'int'
| | int colour_to_hex(enum colour colour)
| | ^~~~~~~~~~~~~
|
with
gcc -Wc++-compat
That example exemplifies the seriously screwed up error reporting in the >>> gnu compiler collection.
One line of informative error message followed by 5 lines of useless
cruft to wade through. And no way to turn it off completely.
That's true, but it can be reduced to only two lines total (so only one
line more than needed), by using -fno-diagnostics-show-caret.
Yes, I use that. I still find that the "note:" lines clutter the
output and provide zero benefit.
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:[... gcc verbose error messages ...]
scott@slp53.sl.home (Scott Lurndal) writes:
One line of informative error message followed by 5 lines of
useless cruft to wade through. And no way to turn it off
completely.
That's true, but it can be reduced to only two lines total (so
only one line more than needed), by using
-fno-diagnostics-show-caret.
Yes, I use that. I still find that the "note:" lines clutter the
output and provide zero benefit.
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
scott@slp53.sl.home (Scott Lurndal) writes:
ram@zedat.fu-berlin.de (Stefan Ram) writes:
Richard Harnden <richard.nospam@gmail.invalid> wrote or quoted:
int hex = colour_to_hex(10);
... then the compiler doesn't complain that 10 is not in the enum.
Why? Surely the compiler can tell.
I get
|
|error: enum conversion when passing argument 1 of 'colour_to_hex' is
invalid in C++ [-Wc++-compat]
| |int hex = colour_to_hex(10);
| | ^~
|note: expected 'enum colour' but argument is of type 'int'
| | int colour_to_hex(enum colour colour)
| | ^~~~~~~~~~~~~
|
with
gcc -Wc++-compat
That example exemplifies the seriously screwed up error reporting in the >>> gnu compiler collection.
One line of informative error message followed by 5 lines of useless
cruft to wade through. And no way to turn it off completely.
That's true, but it can be reduced to only two lines total (so only one >>line more than needed), by using -fno-diagnostics-show-caret.
Yes, I use that. I still find that the "note:" lines clutter the
output and provide zero benefit.
scott@slp53.sl.home (Scott Lurndal) writes:
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
scott@slp53.sl.home (Scott Lurndal) writes:
ram@zedat.fu-berlin.de (Stefan Ram) writes:
Richard Harnden <richard.nospam@gmail.invalid> wrote or quoted:
int hex = colour_to_hex(10);
... then the compiler doesn't complain that 10 is not in the enum. >>>>>> Why? Surely the compiler can tell.
I get
|
|error: enum conversion when passing argument 1 of 'colour_to_hex' is >>>>> invalid in C++ [-Wc++-compat]
| |int hex = colour_to_hex(10);
| | ^~
|note: expected 'enum colour' but argument is of type 'int'
| | int colour_to_hex(enum colour colour)
| | ^~~~~~~~~~~~~
|
with
gcc -Wc++-compat
That example exemplifies the seriously screwed up error reporting in the >>>> gnu compiler collection.
One line of informative error message followed by 5 lines of useless
cruft to wade through. And no way to turn it off completely.
That's true, but it can be reduced to only two lines total (so only one >>>line more than needed), by using -fno-diagnostics-show-caret.
Yes, I use that. I still find that the "note:" lines clutter the
output and provide zero benefit.
Does
gcc -fcompare-debug-second -fno-diagnostics-show-caret
Ben Bacarisse <ben@bsb.me.uk> writes:...
scott@slp53.sl.home (Scott Lurndal) writes:
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
That's true, but it can be reduced to only two lines total (so only one >>>>line more than needed), by using -fno-diagnostics-show-caret.
Yes, I use that. I still find that the "note:" lines clutter the
output and provide zero benefit.
Does
gcc -fcompare-debug-second -fno-diagnostics-show-caret
We use the latter. It doesn't get rid of the 'note' sections, however.
For some reason, -fcompare-debug-second is commented out in our Makefile, but it appears that only applies in when a second compile is required.
scott@slp53.sl.home (Scott Lurndal) writes:
Ben Bacarisse <ben@bsb.me.uk> writes:
scott@slp53.sl.home (Scott Lurndal) writes:
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
...
That's true, but it can be reduced to only two lines total (so
only one line more than needed), by using
-fno-diagnostics-show-caret.
Yes, I use that. I still find that the "note:" lines clutter the
output and provide zero benefit.
Does
gcc -fcompare-debug-second -fno-diagnostics-show-caret
We use the latter. It doesn't get rid of the 'note' sections,
however.
For some reason, -fcompare-debug-second is commented out in our
Makefile, but it appears that only applies in when a second compile
is required.
It appears to have a second "side-effect" use. It removes notes
when I use it.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 546 |
Nodes: | 16 (2 / 14) |
Uptime: | 146:52:40 |
Calls: | 10,383 |
Calls today: | 8 |
Files: | 14,054 |
D/L today: |
2 files (1,861K bytes) |
Messages: | 6,417,718 |