https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91993
Bug ID: 91993
Summary: Spurious -Wconversion warning with
-fsanitize=undefined
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: TonyELewis at hotmail dot com
Target Milestone: ---
Compiling:
auto fn( const unsigned char &a,
const unsigned char &b,
const unsigned char &c ) {
return static_cast<unsigned char>(
static_cast<unsigned char>(
a << 1U
)
|
b
)
|
c;
}
...with:
g++ -fsanitize=undefined -Werror -Wconversion -std=c++17 -fsyntax-only a.cpp
...I get:
a.cpp: In function ‘auto fn(const unsigned char&, const unsigned char&, const
unsigned char&)’:
a.cpp:4:11: error: conversion from ‘int’ to ‘unsigned char’ may change value
[-Werror=conversion]
4 | return static_cast<unsigned char>(
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
5 | static_cast<unsigned char>(
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~
6 | a << 1U
| ~~~~~~~
7 | )
| ~
8 | |
| ~
9 | b
| ~
10 | )
| ~
cc1plus: all warnings being treated as errors
...which I think is spurious. Interestingly, the warning goes away if I remove
`-fsanitize=undefined` (and I can't persuade clang-tidy or `clang -Weverything`
to complain about it).
I'm seeing this on g++ (GCC) 9.2.0 (Ubuntu 18.04.3 LTS, Linux
4.15.0-65-generic) but I've registered it as 10.0 because I see the same
behaviour on GCC master on Godbolt.
The closest to an active duplicate that I can see is
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91179 but that doesn't mention
`-fsanitize=undefined` so I suspect that's different.