public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/95156] New: -Wtautological-compare warns in C but not C++
@ 2020-05-15 22:11 simon.marchi at polymtl dot ca
2020-05-15 23:49 ` [Bug c++/95156] " msebor at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: simon.marchi at polymtl dot ca @ 2020-05-15 22:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95156
Bug ID: 95156
Summary: -Wtautological-compare warns in C but not C++
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: simon.marchi at polymtl dot ca
Target Milestone: ---
Any reason why this code:
volatile unsigned short insn;
int main()
{
if ((insn & 0xffb0) == 0xe950) {
return 1;
} else {
return 0;
}
}
warns when compiled with gcc:
$ gcc-10 test.c -c -Wall
test.c: In function ‘main’:
test.c:5:23: warning: bitwise comparison always evaluates to false
[-Wtautological-compare]
5 | if ((insn & 0xffb0) == 0xe950) {
|
but not when compiled with g++:
$ g++-10 test.c -c -Wall
<nothing>
?
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug c++/95156] -Wtautological-compare warns in C but not C++
2020-05-15 22:11 [Bug c++/95156] New: -Wtautological-compare warns in C but not C++ simon.marchi at polymtl dot ca
@ 2020-05-15 23:49 ` msebor at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-05-15 23:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95156
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Version|unknown |11.0
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
CC| |msebor at gcc dot gnu.org
Known to fail| |10.1.0, 11.0, 9.2.0
Keywords| |diagnostic
Last reconfirmed| |2020-05-15
--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
In C mode the warning function, warn_tautological_bitwise_comparison (const
op_location_t &loc, tree_code code, tree lhs, tree rhs), gets a BIT_AND_EXPR
while in C++ mode it's passed a NOP_EXPR that casts the result of the same
BIT_AND_EXPR as in C to int. The cast seems pointless since the type of the
BIT_AND_EXPR already is int.
I couldn't find a version where G++ did issue the expected warning so it's not
a regression.
(As an aside, the volatile qualifier isn't necessary to reproduce the bug.)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-05-15 23:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-15 22:11 [Bug c++/95156] New: -Wtautological-compare warns in C but not C++ simon.marchi at polymtl dot ca
2020-05-15 23:49 ` [Bug c++/95156] " msebor at gcc dot gnu.org
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).