c++: Fix decltype(auto) deduction with rvalue ref [PR78209]
Here's a small deficiency in decltype(auto). [dcl.type.auto.deduct]/5: If the placeholder-type-specifier is of the form decltype(auto), [...] the type deduced for T is determined [...] as though E had been the operand of the decltype. So: int &&i = 0; decltype(auto) j = i; // should behave like int &&j = i; error We deduce j's type in do_auto_deduction via finish_decltype_type which takes an 'id' argument. Currently we compute 'id' as false, because stripped_init is *i (a REFERENCE_REF_P). But it seems to me we should rather set 'id' to true here, by looking through the REFERENCE_REF_P, so that finish_decltype_type DTRT. gcc/cp/ChangeLog: PR c++/78209 * pt.c (do_auto_deduction): If init is REFERENCE_REF_P, use its first operand. gcc/testsuite/ChangeLog: PR c++/78209 * g++.dg/cpp1y/decltype-auto1.C: New test.
This commit is contained in:
parent
1d87302a8e
commit
e6fd02cc6d
2 changed files with 10 additions and 0 deletions
|
@ -29278,6 +29278,8 @@ do_auto_deduction (tree type, tree init, tree auto_node,
|
|||
else if (AUTO_IS_DECLTYPE (auto_node))
|
||||
{
|
||||
tree stripped_init = tree_strip_any_location_wrapper (init);
|
||||
if (REFERENCE_REF_P (stripped_init))
|
||||
stripped_init = TREE_OPERAND (stripped_init, 0);
|
||||
bool id = (DECL_P (stripped_init)
|
||||
|| ((TREE_CODE (init) == COMPONENT_REF
|
||||
|| TREE_CODE (init) == SCOPE_REF)
|
||||
|
|
8
gcc/testsuite/g++.dg/cpp1y/decltype-auto1.C
Normal file
8
gcc/testsuite/g++.dg/cpp1y/decltype-auto1.C
Normal file
|
@ -0,0 +1,8 @@
|
|||
// PR c++/78209
|
||||
// { dg-do compile { target c++14 } }
|
||||
|
||||
int main()
|
||||
{
|
||||
int &&i = 0;
|
||||
decltype(auto) j = i; // { dg-error "cannot bind rvalue reference" }
|
||||
}
|
Loading…
Add table
Reference in a new issue