[Bug c++/93862] [10 Regression] ICE on static_cast of rvalue-reference-to-array of unknown bound [P0338] to its known static bound

2020-02-26 Thread wjwray at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93862

--- Comment #8 from Will Wray  ---
OK. I'll try to get full confirmation and clarification on legality,
with links to wording if possible, then open a new bug if valid.

[Bug c++/93862] [10 Regression] ICE on static_cast of rvalue-reference-to-array of unknown bound [P0338] to its known static bound

2020-02-26 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93862

--- Comment #7 from Marek Polacek  ---
Oof, curious.  Could you please create a new PR for that?

[Bug c++/93862] [10 Regression] ICE on static_cast of rvalue-reference-to-array of unknown bound [P0338] to its known static bound

2020-02-26 Thread wjwray at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93862

--- Comment #6 from Will Wray  ---
Thanks for the quick work.
However, I'm not sure that (2) and (3) _are_ invalid.

(Sorry, I didn't have time to follow the email thread).
I should have provided this link to an exchange with Richard Smith.
I'd waited for his response before filing the bug. He says:
"In both cases, it's valid to use static_cast to recover the original type."

https://cpplang.slack.com/archives/C2PQKRWJU/p1579186047347300

zygoloid  Feb 20
Lifetime extension applies; the lifetime extension rules don't care about
qualification conversions. Another example: const int *const  =
static_cast(nullptr); performs lifetime extension even though the type
of the temporary object (int*) has been lost (mutability-erased) in the
reference binding.

zygoloid  Feb 20
In both cases, it's valid to use static_cast to recover the original type.

willw  Feb 20
Thanks for the confirmation. That makes sense.

willw  Feb 21
I filed the gcc bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93862

[Bug c++/93862] [10 Regression] ICE on static_cast of rvalue-reference-to-array of unknown bound [P0338] to its known static bound

2020-02-26 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93862

Marek Polacek  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #5 from Marek Polacek  ---
Fixed.

[Bug c++/93862] [10 Regression] ICE on static_cast of rvalue-reference-to-array of unknown bound [P0338] to its known static bound

2020-02-26 Thread cvs-commit at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93862

--- Comment #4 from CVS Commits  ---
The master branch has been updated by Marek Polacek :

https://gcc.gnu.org/g:4a305fa2fd4c9d553b26efa00f868aa1e4416a9f

commit r10-6867-g4a305fa2fd4c9d553b26efa00f868aa1e4416a9f
Author: Marek Polacek 
Date:   Mon Feb 24 14:43:48 2020 -0500

c++: Fix ICE with static_cast when converting from int[] [PR93862]

This ICEs since my patch for P0388, which allowed conversions to arrays
of unknown bound, but not the reverse, so these two static_casts are
ill-formed.

[expr.static.cast]/3 says that "cv1 T1" and "cv2 T2" have to be
reference-compatible and the comment in build_static_cast_1 says it too
but then we actually use reference_related_p...  Fixed thus.

2020-02-26  Marek Polacek  

PR c++/93862 - ICE with static_cast when converting from int[].
* call.c (reference_compatible_p): No longer static.
* cp-tree.h (reference_compatible_p): Declare.
* typeck.c (build_static_cast_1): Use reference_compatible_p instead
of reference_related_p.

* g++.dg/cpp0x/rv-cast7.C: New test.

[Bug c++/93862] [10 Regression] ICE on static_cast of rvalue-reference-to-array of unknown bound [P0338] to its known static bound

2020-02-24 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93862

--- Comment #3 from Marek Polacek  ---
I have a patch but both (2) and (3) are invalid, see
.  (icc also rejects
it.)

[Bug c++/93862] [10 Regression] ICE on static_cast of rvalue-reference-to-array of unknown bound [P0338] to its known static bound

2020-02-20 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93862

--- Comment #2 from Marek Polacek  ---
In build_static_cast_1:
 7397   tree lref = cp_build_reference_type (TREE_TYPE (type), false);
 7398   result = (perform_direct_initialization_if_possible
 7399 (lref, expr, c_cast_p, complain));
 7400   result = build1 (NON_LVALUE_EXPR, type, result);
result is NULL_TREE so we create a bogus NON_LVALUE_EXPR<>.  Need to figure out
why perform_direct_initialization_if_possible returns a null tree.

clang++ trunk crashes on this code too.

[Bug c++/93862] [10 Regression] ICE on static_cast of rvalue-reference-to-array of unknown bound [P0338] to its known static bound

2020-02-20 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93862

Marek Polacek  changed:

   What|Removed |Added

   Priority|P3  |P1
 Status|UNCONFIRMED |ASSIGNED
   Last reconfirmed||2020-02-21
 CC||mpolacek at gcc dot gnu.org
   Assignee|unassigned at gcc dot gnu.org  |mpolacek at gcc dot 
gnu.org
   Target Milestone|--- |10.0
Summary|ICE on static_cast of   |[10 Regression] ICE on
   |rvalue-reference-to-array   |static_cast of
   |of unknown bound [P0338] to |rvalue-reference-to-array
   |its known static bound  |of unknown bound [P0338] to
   ||its known static bound
 Ever confirmed|0   |1

--- Comment #1 from Marek Polacek  ---
Thanks for the report Will.  As expected, started with

commit 89e0a492af5bec8ffa2ec5d99c4858df50d22c16
Author: Marek Polacek 
Date:   Wed Oct 9 20:58:00 2019 +

Implement C++20 P0388R4, DR 1307, and DR 330.

and so mine.