* [Bug c++/95242] [10/11 Regression] spurious "warning: zero as null pointer constant [-Wzero-as-null-pointer-constant]" on comparisons with -std=c++2a
2020-05-20 18:24 [Bug c++/95242] New: [10 Regression] spurious "warning: zero as null pointer constant [-Wzero-as-null-pointer-constant]" on comparisons with -std=c++2a gcc at mattwhitlock dot name
@ 2020-05-22 6:08 ` rguenth at gcc dot gnu.org
2020-05-26 21:21 ` jason at gcc dot gnu.org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-05-22 6:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95242
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to work| |9.3.0
Keywords| |diagnostic
Summary|[10 Regression] spurious |[10/11 Regression] spurious
|"warning: zero as null |"warning: zero as null
|pointer constant |pointer constant
|[-Wzero-as-null-pointer-con |[-Wzero-as-null-pointer-con
|stant]" on comparisons with |stant]" on comparisons with
|-std=c++2a |-std=c++2a
Target Milestone|--- |10.2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/95242] [10/11 Regression] spurious "warning: zero as null pointer constant [-Wzero-as-null-pointer-constant]" on comparisons with -std=c++2a
2020-05-20 18:24 [Bug c++/95242] New: [10 Regression] spurious "warning: zero as null pointer constant [-Wzero-as-null-pointer-constant]" on comparisons with -std=c++2a gcc at mattwhitlock dot name
2020-05-22 6:08 ` [Bug c++/95242] [10/11 " rguenth at gcc dot gnu.org
@ 2020-05-26 21:21 ` jason at gcc dot gnu.org
2020-05-26 23:13 ` redi at gcc dot gnu.org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: jason at gcc dot gnu.org @ 2020-05-26 21:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95242
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |ASSIGNED
Ever confirmed|0 |1
Assignee|unassigned at gcc dot gnu.org |jason at gcc dot gnu.org
CC| |jason at gcc dot gnu.org,
| |jwakely.gcc at gmail dot com
Last reconfirmed| |2020-05-26
--- Comment #1 from Jason Merrill <jason at gcc dot gnu.org> ---
Yes, in C++20 mode the < comparison uses operator<=> to produce a
std::strong_ordering, and then compares that to literal 0 to produce a boolean
value. The operator< has an rhs type of 'std::__cmp_cat::__unspec', which has
a single constructor taking a pointer to itself, which is designed to only
accept null pointer constants, but this causes problems with this warning.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/95242] [10/11 Regression] spurious "warning: zero as null pointer constant [-Wzero-as-null-pointer-constant]" on comparisons with -std=c++2a
2020-05-20 18:24 [Bug c++/95242] New: [10 Regression] spurious "warning: zero as null pointer constant [-Wzero-as-null-pointer-constant]" on comparisons with -std=c++2a gcc at mattwhitlock dot name
2020-05-22 6:08 ` [Bug c++/95242] [10/11 " rguenth at gcc dot gnu.org
2020-05-26 21:21 ` jason at gcc dot gnu.org
@ 2020-05-26 23:13 ` redi at gcc dot gnu.org
2020-05-27 5:21 ` daniel.kruegler at googlemail dot com
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2020-05-26 23:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95242
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Another way to implement the __unspec constructor would be:
consteval __unspec(int __n) { if (__n != 0) throw __n; }
But I think I discussed this with Richard Smith in Prague and we realised there
was a problem with it, but I might be misremembering.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/95242] [10/11 Regression] spurious "warning: zero as null pointer constant [-Wzero-as-null-pointer-constant]" on comparisons with -std=c++2a
2020-05-20 18:24 [Bug c++/95242] New: [10 Regression] spurious "warning: zero as null pointer constant [-Wzero-as-null-pointer-constant]" on comparisons with -std=c++2a gcc at mattwhitlock dot name
` (2 preceding siblings ...)
2020-05-26 23:13 ` redi at gcc dot gnu.org
@ 2020-05-27 5:21 ` daniel.kruegler at googlemail dot com
2020-05-27 6:59 ` redi at gcc dot gnu.org
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2020-05-27 5:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95242
--- Comment #3 from Daniel Krügler <daniel.kruegler at googlemail dot com> ---
(In reply to Jonathan Wakely from comment #2)
> Another way to implement the __unspec constructor would be:
>
> consteval __unspec(int __n) { if (__n != 0) throw __n; }
>
> But I think I discussed this with Richard Smith in Prague and we realised
> there was a problem with it, but I might be misremembering.
Remember that we need to ensure that this __unspec constructor needs to be
noexcept (See bug 94565), so this function could only do a terminate-like
action.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/95242] [10/11 Regression] spurious "warning: zero as null pointer constant [-Wzero-as-null-pointer-constant]" on comparisons with -std=c++2a
2020-05-20 18:24 [Bug c++/95242] New: [10 Regression] spurious "warning: zero as null pointer constant [-Wzero-as-null-pointer-constant]" on comparisons with -std=c++2a gcc at mattwhitlock dot name
` (3 preceding siblings ...)
2020-05-27 5:21 ` daniel.kruegler at googlemail dot com
@ 2020-05-27 6:59 ` redi at gcc dot gnu.org
2020-05-27 8:07 ` daniel.kruegler at googlemail dot com
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2020-05-27 6:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95242
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
It's consteval, the throw is there to make it not a constant expression and
give an error if anything except 0 is used. i.e. it can never throw, it either
compiles or it doesn't.
But I've remembered the problem with this technique, it allows non-literal
zeros:
constexpr int zero = 0;
auto c = (1 <=> 1) == zero; // should be ill-formed.
This compiles OK, and isn't *obviously* wrong when reviewing the code.
The advantage of the current definition using a pointer is that nobody can
declare a constant of type __unspec without obviously using a reserved name and
venturing into undefined territory.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/95242] [10/11 Regression] spurious "warning: zero as null pointer constant [-Wzero-as-null-pointer-constant]" on comparisons with -std=c++2a
2020-05-20 18:24 [Bug c++/95242] New: [10 Regression] spurious "warning: zero as null pointer constant [-Wzero-as-null-pointer-constant]" on comparisons with -std=c++2a gcc at mattwhitlock dot name
` (4 preceding siblings ...)
2020-05-27 6:59 ` redi at gcc dot gnu.org
@ 2020-05-27 8:07 ` daniel.kruegler at googlemail dot com
2020-05-27 8:20 ` redi at gcc dot gnu.org
2020-05-27 14:15 ` jason at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2020-05-27 8:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95242
--- Comment #5 from Daniel Krügler <daniel.kruegler at googlemail dot com> ---
(In reply to Jonathan Wakely from comment #4)
> It's consteval, the throw is there to make it not a constant expression and
> give an error if anything except 0 is used. i.e. it can never throw, it
> either compiles or it doesn't.
Sure, I understand that, but that should still result in a failure of a static
assertion testing for noexcept, e.g. consider:
struct __unspec
{
consteval __unspec(int __n) { if (__n != 0) throw __n; }
};
static_assert(noexcept(__unspec(0)));
int main()
{
}
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/95242] [10/11 Regression] spurious "warning: zero as null pointer constant [-Wzero-as-null-pointer-constant]" on comparisons with -std=c++2a
2020-05-20 18:24 [Bug c++/95242] New: [10 Regression] spurious "warning: zero as null pointer constant [-Wzero-as-null-pointer-constant]" on comparisons with -std=c++2a gcc at mattwhitlock dot name
` (5 preceding siblings ...)
2020-05-27 8:07 ` daniel.kruegler at googlemail dot com
@ 2020-05-27 8:20 ` redi at gcc dot gnu.org
2020-05-27 14:15 ` jason at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2020-05-27 8:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95242
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
It was just a sketch to show the idea.
Obviously the real thing would need noexcept, but we have a regression test for
that. How to construct it is what's relevant here.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/95242] [10/11 Regression] spurious "warning: zero as null pointer constant [-Wzero-as-null-pointer-constant]" on comparisons with -std=c++2a
2020-05-20 18:24 [Bug c++/95242] New: [10 Regression] spurious "warning: zero as null pointer constant [-Wzero-as-null-pointer-constant]" on comparisons with -std=c++2a gcc at mattwhitlock dot name
` (6 preceding siblings ...)
2020-05-27 8:20 ` redi at gcc dot gnu.org
@ 2020-05-27 14:15 ` jason at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: jason at gcc dot gnu.org @ 2020-05-27 14:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95242
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #7 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed for 10.2/11.
r11-663-g6c66c692043d680a5efcd9616b94f9629c417038
r10-8190-gfac77bd88dc450f6bcc8f5945186990c094b5cfc
^ permalink raw reply [flat|nested] 9+ messages in thread