]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: fix propagating REF_PARENTHESIZED_P [PR116379]
authorMarek Polacek <polacek@redhat.com>
Thu, 13 Feb 2025 20:56:16 +0000 (15:56 -0500)
committerMarek Polacek <polacek@redhat.com>
Fri, 14 Feb 2025 13:08:53 +0000 (08:08 -0500)
commitb01664a6197f57615d3c62594037c575dfdd9035
tree2d22f44449a8cd7c1134b653190aef0f6906d7f5
parent74ea20e16cf18b42071557b71a42ea31c8192425
c++: fix propagating REF_PARENTHESIZED_P [PR116379]

Here we have:

  template<typename T>
  struct X{
      T val;
      decltype(auto) value(){
  return (val);
      }
  };

where the return type of value should be 'int &' since '(val)' is an
expression, not a name, and decltype(auto) performs the type deduction
using the decltype rules.

The problem is that we weren't propagating REF_PARENTHESIZED_P
correctly: the return value of finish_non_static_data_member in this
test was a REFERENCE_REF_P, so we didn't set the flag.  We should
use force_paren_expr like below.

PR c++/116379

gcc/cp/ChangeLog:

* pt.cc (tsubst_expr) <COMPONENT_REF>: Use force_paren_expr to set
REF_PARENTHESIZED_P.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1y/decltype-auto9.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/pt.cc
gcc/testsuite/g++.dg/cpp1y/decltype-auto9.C [new file with mode: 0644]