[Bug c++/70610] [6 regression] error: invalid initialization of non-const reference of type

2016-07-11 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70610

Andrew Pinski  changed:

   What|Removed |Added

   Target Milestone|--- |6.0

[Bug c++/70610] [6 regression] error: invalid initialization of non-const reference of type

2016-04-12 Thread ppalka at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70610

Patrick Palka  changed:

   What|Removed |Added

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

--- Comment #8 from Patrick Palka  ---
Fixed.

[Bug c++/70610] [6 regression] error: invalid initialization of non-const reference of type

2016-04-12 Thread ppalka at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70610

--- Comment #7 from Patrick Palka  ---
Author: ppalka
Date: Wed Apr 13 00:06:51 2016
New Revision: 234926

URL: https://gcc.gnu.org/viewcvs?rev=234926=gcc=rev
Log:
Fix PR c++/70610 (wrong overload resolution during template processing)

gcc/cp/ChangeLog:

PR c++/70610
* tree.c (lvalue_kind) [NON_DEPENDENT_EXPR]: Unconditionally
recurse into it.
* typeck.c (build_x_conditional_expr): Unconditionally remember
that the result is an lvalue or xvalue.

gcc/testsuite/ChangeLog:

PR c++/70610
* g++.dg/template/pr70610.C: New test.
* g++.dg/template/pr70610-2.C: New test.
* g++.dg/template/pr70610-3.C: New test.
* g++.dg/template/pr70610-4.C: New test.


Added:
trunk/gcc/testsuite/g++.dg/template/pr70610-2.C
trunk/gcc/testsuite/g++.dg/template/pr70610-3.C
trunk/gcc/testsuite/g++.dg/template/pr70610-4.C
trunk/gcc/testsuite/g++.dg/template/pr70610.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/tree.c
trunk/gcc/cp/typeck.c
trunk/gcc/testsuite/ChangeLog

[Bug c++/70610] [6 regression] error: invalid initialization of non-const reference of type

2016-04-11 Thread ppalka at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70610

--- Comment #6 from Patrick Palka  ---
uhhh... here: https://gcc.gnu.org/ml/gcc-patches/2016-04/msg00482.html

[Bug c++/70610] [6 regression] error: invalid initialization of non-const reference of type

2016-04-11 Thread ppalka at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70610

Patrick Palka  changed:

   What|Removed |Added

 Status|UNCONFIRMED |ASSIGNED
   Last reconfirmed||2016-04-11
   Assignee|unassigned at gcc dot gnu.org  |ppalka at gcc dot 
gnu.org
 Ever confirmed|0   |1

--- Comment #5 from Patrick Palka  ---
Patch

[Bug c++/70610] [6 regression] error: invalid initialization of non-const reference of type

2016-04-11 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70610

Jakub Jelinek  changed:

   What|Removed |Added

 CC||jakub at gcc dot gnu.org,
   ||jason at gcc dot gnu.org

--- Comment #4 from Jakub Jelinek  ---
#c3 changed behavior (started to be rejected) with r181174.

[Bug c++/70610] [6 regression] error: invalid initialization of non-const reference of type

2016-04-10 Thread ppalka at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70610

--- Comment #3 from Patrick Palka  ---
Not limited to operator overloads either:

void bar (const int &, int &);
void bar (int &, const int &);
void bar (const int &, const int &);

int a, b;

template 
void
foo ()
{
  bar (a + 1, b + 2);
}

[Bug c++/70610] [6 regression] error: invalid initialization of non-const reference of type

2016-04-10 Thread ppalka at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70610

--- Comment #2 from Patrick Palka  ---
This general issue about the unconditional lvalue-ness of NON_DEPENDENT_EXPR
existed before my patch for PR c++/21802 though.  For example, ere's a test
case that should compile cleanly but doesn't since at least g++ 4.4 (-std=c++98
is required) for basically the same reason:

struct A { };

void operator+ (const A &, A &);
void operator+ (A &, const A &);
void operator+ (const A &, const A &);

template 
void
foo ()
{
  A () + A ();
}

unary_plus.C: In function ‘void foo()’:
unary_plus.C:11:8: error: ambiguous overload for ‘operator+’ (operand types are
‘A’ and ‘A’)
   A () + A ();
   ~^~
unary_plus.C:3:6: note: candidate: void operator+(const A&, A&)
 void operator+ (const A &, A &);
  ^~~~
unary_plus.C:4:6: note: candidate: void operator+(A&, const A&)
 void operator+ (A &, const A &);
  ^~~~
unary_plus.C:5:6: note: candidate: void operator+(const A&, const A&)
 void operator+ (const A &, const A &);
  ^~~~

[Bug c++/70610] [6 regression] error: invalid initialization of non-const reference of type

2016-04-10 Thread ppalka at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70610

--- Comment #1 from Patrick Palka  ---
The problem is that during template processing we think the operand to the
unary + is an lvalue (because it's wrapped in a NON_DEPENDENT_EXPR node) and so
during overload resolution we select the non-const overload of operator+.  Then
during instantiation, since the operand is actually an rvalue we reject the
function call since it requires the operand to be an lvalue.