public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96675] New: tautological-compare warning emitted for NTTP bitwise comparison
@ 2020-08-18 10:50 ed at catmur dot uk
2020-08-18 16:29 ` [Bug c++/96675] [10/11 Regression] " mpolacek at gcc dot gnu.org
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: ed at catmur dot uk @ 2020-08-18 10:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96675
Bug ID: 96675
Summary: tautological-compare warning emitted for NTTP bitwise
comparison
Product: gcc
Version: 10.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: ed at catmur dot uk
Target Milestone: ---
template<char c>
constexpr bool f(char d) {
return 'a' <= c && c <= 'z' ? (d | 0x20) == c :
'A' <= c && c <= 'Z' ? (d & ~0x20) == c :
d == c;
}
static_assert(f<'p'>('P'));
In instantiation of 'constexpr bool f(char) [with char c = 'p']':
<source>:7:21: required from here
<source>:4:44: warning: bitwise comparison always evaluates to false
[-Wtautological-compare]
4 | 'A' <= c && c <= 'Z' ? (d & ~0x20) == c :
| ~~~~~~~~~~~~^~~~
Per godbolt, this happened somewhere between 10.1.0 and 10.2.0.
Motivation is
https://github.com/capnproto/capnproto/commit/c38629e5a4b8ce9561b81cb23ea5fc39cbd93eb7
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/96675] [10/11 Regression] tautological-compare warning emitted for NTTP bitwise comparison
2020-08-18 10:50 [Bug c++/96675] New: tautological-compare warning emitted for NTTP bitwise comparison ed at catmur dot uk
@ 2020-08-18 16:29 ` mpolacek at gcc dot gnu.org
2020-10-12 12:32 ` rguenth at gcc dot gnu.org
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-08-18 16:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96675
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
Last reconfirmed| |2020-08-18
CC| |mpolacek at gcc dot gnu.org
Target Milestone|--- |10.3
Summary|tautological-compare |[10/11 Regression]
|warning emitted for NTTP |tautological-compare
|bitwise comparison |warning emitted for NTTP
| |bitwise comparison
Ever confirmed|0 |1
Status|UNCONFIRMED |ASSIGNED
Keywords| |diagnostic
--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Started with my r11-155.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/96675] [10/11 Regression] tautological-compare warning emitted for NTTP bitwise comparison
2020-08-18 10:50 [Bug c++/96675] New: tautological-compare warning emitted for NTTP bitwise comparison ed at catmur dot uk
2020-08-18 16:29 ` [Bug c++/96675] [10/11 Regression] " mpolacek at gcc dot gnu.org
@ 2020-10-12 12:32 ` rguenth at gcc dot gnu.org
2020-10-28 21:30 ` cvs-commit at gcc dot gnu.org
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-10-12 12:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96675
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/96675] [10/11 Regression] tautological-compare warning emitted for NTTP bitwise comparison
2020-08-18 10:50 [Bug c++/96675] New: tautological-compare warning emitted for NTTP bitwise comparison ed at catmur dot uk
2020-08-18 16:29 ` [Bug c++/96675] [10/11 Regression] " mpolacek at gcc dot gnu.org
2020-10-12 12:32 ` rguenth at gcc dot gnu.org
@ 2020-10-28 21:30 ` cvs-commit at gcc dot gnu.org
2020-10-28 21:31 ` [Bug c++/96675] [10 " mpolacek at gcc dot gnu.org
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-10-28 21:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96675
--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:976e7ef1a2d54f46021f74d071d9fdb9631298f8
commit r11-4501-g976e7ef1a2d54f46021f74d071d9fdb9631298f8
Author: Marek Polacek <polacek@redhat.com>
Date: Sat Oct 24 15:26:27 2020 -0400
c++: Prevent warnings for value-dependent exprs [PR96742]
Here, in r11-155, I changed the call to uses_template_parms to
type_dependent_expression_p_push to avoid a crash in C++98 in
value_dependent_expression_p on a non-constant expression. But that
prompted a host of complaints that we now warn for value-dependent
expressions in templates. Those warnings are technically valid, but
people still don't want them because they're awkward to avoid. This
patch uses value_dependent_expression_p or type_dependent_expression_p.
But make sure that we don't ICE in value_dependent_expression_p by
checking potential_constant_expression first.
gcc/cp/ChangeLog:
PR c++/96675
PR c++/96742
* pt.c (tsubst_copy_and_build): Call value_dependent_expression_p
or
type_dependent_expression_p instead of
type_dependent_expression_p_push.
But only call value_dependent_expression_p for expressions that are
potential_constant_expression.
gcc/testsuite/ChangeLog:
PR c++/96675
PR c++/96742
* g++.dg/warn/Wdiv-by-zero-3.C: Turn dg-warning into dg-bogus.
* g++.dg/warn/Wtautological-compare3.C: New test.
* g++.dg/warn/Wtype-limits5.C: New test.
* g++.old-deja/g++.pt/crash10.C: Remove dg-warning.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/96675] [10 Regression] tautological-compare warning emitted for NTTP bitwise comparison
2020-08-18 10:50 [Bug c++/96675] New: tautological-compare warning emitted for NTTP bitwise comparison ed at catmur dot uk
` (2 preceding siblings ...)
2020-10-28 21:30 ` cvs-commit at gcc dot gnu.org
@ 2020-10-28 21:31 ` mpolacek at gcc dot gnu.org
2020-12-04 8:42 ` giorgio.audrito at gmail dot com
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-10-28 21:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96675
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[10/11 Regression] |[10 Regression]
|tautological-compare |tautological-compare
|warning emitted for NTTP |warning emitted for NTTP
|bitwise comparison |bitwise comparison
--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed on trunk so far.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/96675] [10 Regression] tautological-compare warning emitted for NTTP bitwise comparison
2020-08-18 10:50 [Bug c++/96675] New: tautological-compare warning emitted for NTTP bitwise comparison ed at catmur dot uk
` (3 preceding siblings ...)
2020-10-28 21:31 ` [Bug c++/96675] [10 " mpolacek at gcc dot gnu.org
@ 2020-12-04 8:42 ` giorgio.audrito at gmail dot com
2020-12-04 10:52 ` giorgio.audrito at gmail dot com
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: giorgio.audrito at gmail dot com @ 2020-12-04 8:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96675
Giorgio Audrito <giorgio.audrito at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |giorgio.audrito at gmail dot com
--- Comment #4 from Giorgio Audrito <giorgio.audrito at gmail dot com> ---
I am having a similar problem (10.2.0) with a situation like this:
template <int O>
using foo = std::integral_constant<bool, (O&1)==1>;
....
foo<1> ... foo<0>...
I read this issue will be fixed in 10.3, I guess my situation will be fixed
also?
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/96675] [10 Regression] tautological-compare warning emitted for NTTP bitwise comparison
2020-08-18 10:50 [Bug c++/96675] New: tautological-compare warning emitted for NTTP bitwise comparison ed at catmur dot uk
` (4 preceding siblings ...)
2020-12-04 8:42 ` giorgio.audrito at gmail dot com
@ 2020-12-04 10:52 ` giorgio.audrito at gmail dot com
2020-12-04 20:12 ` mpolacek at gcc dot gnu.org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: giorgio.audrito at gmail dot com @ 2020-12-04 10:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96675
--- Comment #5 from Giorgio Audrito <giorgio.audrito at gmail dot com> ---
I add that a very similar problem happens with -Wtype-limits, I found this
minimal example:
template <unsigned x>
struct foo {
bool bar(unsigned y) {
return y < x;
}
};
int main() {
return foo<0>{}.bar(10);
}
I don't know if that has been addressed as well (should it be a separate bug
report?).
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/96675] [10 Regression] tautological-compare warning emitted for NTTP bitwise comparison
2020-08-18 10:50 [Bug c++/96675] New: tautological-compare warning emitted for NTTP bitwise comparison ed at catmur dot uk
` (5 preceding siblings ...)
2020-12-04 10:52 ` giorgio.audrito at gmail dot com
@ 2020-12-04 20:12 ` mpolacek at gcc dot gnu.org
2021-01-05 21:32 ` cvs-commit at gcc dot gnu.org
2021-01-05 21:36 ` mpolacek at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-12-04 20:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96675
--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
(In reply to Giorgio Audrito from comment #5)
> I add that a very similar problem happens with -Wtype-limits, I found this
> minimal example:
>
> template <unsigned x>
> struct foo {
> bool bar(unsigned y) {
> return y < x;
> }
> };
>
> int main() {
> return foo<0>{}.bar(10);
> }
>
> I don't know if that has been addressed as well (should it be a separate bug
> report?).
This is fixed on trunk and will be fixed in 10.3 too (I haven't backported the
patch to 10 yet.)
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/96675] [10 Regression] tautological-compare warning emitted for NTTP bitwise comparison
2020-08-18 10:50 [Bug c++/96675] New: tautological-compare warning emitted for NTTP bitwise comparison ed at catmur dot uk
` (6 preceding siblings ...)
2020-12-04 20:12 ` mpolacek at gcc dot gnu.org
@ 2021-01-05 21:32 ` cvs-commit at gcc dot gnu.org
2021-01-05 21:36 ` mpolacek at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-01-05 21:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96675
--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Marek Polacek
<mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:6fd09a6e8bcadaa69e1fdca09263990cc1c5245f
commit r10-9208-g6fd09a6e8bcadaa69e1fdca09263990cc1c5245f
Author: Marek Polacek <polacek@redhat.com>
Date: Sat Oct 24 15:26:27 2020 -0400
c++: Prevent warnings for value-dependent exprs [PR96742]
Here, in r11-155, I changed the call to uses_template_parms to
type_dependent_expression_p_push to avoid a crash in C++98 in
value_dependent_expression_p on a non-constant expression. But that
prompted a host of complaints that we now warn for value-dependent
expressions in templates. Those warnings are technically valid, but
people still don't want them because they're awkward to avoid. This
patch uses value_dependent_expression_p or type_dependent_expression_p.
But make sure that we don't ICE in value_dependent_expression_p by
checking potential_constant_expression first.
gcc/cp/ChangeLog:
PR c++/96675
PR c++/96742
* pt.c (tsubst_copy_and_build): Call value_dependent_expression_p
or
type_dependent_expression_p instead of
type_dependent_expression_p_push.
But only call value_dependent_expression_p for expressions that are
potential_constant_expression.
gcc/testsuite/ChangeLog:
PR c++/96675
PR c++/96742
* g++.dg/warn/Wdiv-by-zero-3.C: Turn dg-warning into dg-bogus.
* g++.dg/warn/Wtautological-compare3.C: New test.
* g++.dg/warn/Wtype-limits5.C: New test.
* g++.old-deja/g++.pt/crash10.C: Remove dg-warning.
(cherry picked from commit 976e7ef1a2d54f46021f74d071d9fdb9631298f8)
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/96675] [10 Regression] tautological-compare warning emitted for NTTP bitwise comparison
2020-08-18 10:50 [Bug c++/96675] New: tautological-compare warning emitted for NTTP bitwise comparison ed at catmur dot uk
` (7 preceding siblings ...)
2021-01-05 21:32 ` cvs-commit at gcc dot gnu.org
@ 2021-01-05 21:36 ` mpolacek at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-01-05 21:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96675
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #8 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2021-01-05 21:36 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-18 10:50 [Bug c++/96675] New: tautological-compare warning emitted for NTTP bitwise comparison ed at catmur dot uk
2020-08-18 16:29 ` [Bug c++/96675] [10/11 Regression] " mpolacek at gcc dot gnu.org
2020-10-12 12:32 ` rguenth at gcc dot gnu.org
2020-10-28 21:30 ` cvs-commit at gcc dot gnu.org
2020-10-28 21:31 ` [Bug c++/96675] [10 " mpolacek at gcc dot gnu.org
2020-12-04 8:42 ` giorgio.audrito at gmail dot com
2020-12-04 10:52 ` giorgio.audrito at gmail dot com
2020-12-04 20:12 ` mpolacek at gcc dot gnu.org
2021-01-05 21:32 ` cvs-commit at gcc dot gnu.org
2021-01-05 21:36 ` mpolacek 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).