public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/50835] New: [4.7 Regression] Lvalue-ness of conditional operator results is incorrect in a function template
@ 2011-10-23  2:10 mimomorin at gmail dot com
  2011-10-23 11:47 ` [Bug c++/50835] " daniel.kruegler at googlemail dot com
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: mimomorin at gmail dot com @ 2011-10-23  2:10 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50835

             Bug #: 50835
           Summary: [4.7 Regression] Lvalue-ness of conditional operator
                    results is incorrect in a function template
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: mimomorin@gmail.com


Created attachment 25578
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25578
Test case (which incorrectly fails to be compiled on gcc-4.7)

Suppose we have the following class

    template<typename T>
    struct rvalue_probe
    {
        explicit rvalue_probe(T &t) : value(t) {}

        operator T ()       { return value; }
        operator T&() const { return value; }

        T& value;
    };

Then, 

    // std::vector<int> v;
    true ? rvalue_probe<std::vector<int> >(v) : v

should be evaluated to an lvalue. 
But in a function template, this is incorrectly evaluated to an rvalue. 

Tested on gcc-4.7.0 20111022 (in a C++03 mode).


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/50835] [4.7 Regression] Lvalue-ness of conditional operator results is incorrect in a function template
  2011-10-23  2:10 [Bug c++/50835] New: [4.7 Regression] Lvalue-ness of conditional operator results is incorrect in a function template mimomorin at gmail dot com
@ 2011-10-23 11:47 ` daniel.kruegler at googlemail dot com
  2011-10-23 11:50 ` daniel.kruegler at googlemail dot com
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2011-10-23 11:47 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50835

--- Comment #1 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2011-10-23 11:47:19 UTC ---
Simplified test case:

//---
template<typename>
struct vector {};

template<typename T>
struct rvalue_probe
{
    explicit rvalue_probe(T &t) : value(t) {}

    operator T&() const { return value; }

    T& value;
};

template <typename T>
void should_be_lvalue(T&)
{
}

template <typename>
void f()
{
    vector<int> v;
    should_be_lvalue(true ? rvalue_probe<vector<int> >(v) : v); // Error
}
//---

The problem exists in C++0x mode as well.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/50835] [4.7 Regression] Lvalue-ness of conditional operator results is incorrect in a function template
  2011-10-23  2:10 [Bug c++/50835] New: [4.7 Regression] Lvalue-ness of conditional operator results is incorrect in a function template mimomorin at gmail dot com
  2011-10-23 11:47 ` [Bug c++/50835] " daniel.kruegler at googlemail dot com
@ 2011-10-23 11:50 ` daniel.kruegler at googlemail dot com
  2011-10-23 12:24 ` daniel.kruegler at googlemail dot com
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2011-10-23 11:50 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50835

--- Comment #2 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2011-10-23 11:50:17 UTC ---
Further simplification:

//---
struct vector {};

template<typename T>
struct rvalue_probe
{
    explicit rvalue_probe(T &t) : value(t) {}

    operator T&() const { return value; }

    T& value;
};

template <typename T>
void should_be_lvalue(T&)
{
}

template <typename>
void f()
{
    vector v;
    should_be_lvalue(true ? rvalue_probe<vector>(v) : v); // Error
}
//---


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/50835] [4.7 Regression] Lvalue-ness of conditional operator results is incorrect in a function template
  2011-10-23  2:10 [Bug c++/50835] New: [4.7 Regression] Lvalue-ness of conditional operator results is incorrect in a function template mimomorin at gmail dot com
  2011-10-23 11:47 ` [Bug c++/50835] " daniel.kruegler at googlemail dot com
  2011-10-23 11:50 ` daniel.kruegler at googlemail dot com
@ 2011-10-23 12:24 ` daniel.kruegler at googlemail dot com
  2011-10-27  9:23 ` rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2011-10-23 12:24 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50835

--- Comment #3 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2011-10-23 12:23:41 UTC ---
Removing as much templates as possible:

//---
struct A {};

struct B
{
    explicit B(A &t) : value(t) {}
    operator A&() const { return value; }
    A& value;
};

void should_be_lvalue(A&)
{
}

template <typename>
void f()
{
    A v;
    should_be_lvalue(true ? B(v) : v);
}
//---

This code is still rejected in either C++03 or C++11 mode:

"error: invalid initialization of non-const reference of type 'A&' from an
rvalue of type 'A'"
"error: in passing argument 1 of 'void should_be_lvalue(A&)'"


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/50835] [4.7 Regression] Lvalue-ness of conditional operator results is incorrect in a function template
  2011-10-23  2:10 [Bug c++/50835] New: [4.7 Regression] Lvalue-ness of conditional operator results is incorrect in a function template mimomorin at gmail dot com
                   ` (2 preceding siblings ...)
  2011-10-23 12:24 ` daniel.kruegler at googlemail dot com
@ 2011-10-27  9:23 ` rguenth at gcc dot gnu.org
  2011-10-27 11:36 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-10-27  9:23 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50835

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |4.7.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/50835] [4.7 Regression] Lvalue-ness of conditional operator results is incorrect in a function template
  2011-10-23  2:10 [Bug c++/50835] New: [4.7 Regression] Lvalue-ness of conditional operator results is incorrect in a function template mimomorin at gmail dot com
                   ` (3 preceding siblings ...)
  2011-10-27  9:23 ` rguenth at gcc dot gnu.org
@ 2011-10-27 11:36 ` rguenth at gcc dot gnu.org
  2011-11-08 17:14 ` jason at gcc dot gnu.org
  2011-11-08 17:31 ` jason at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-10-27 11:36 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50835

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
           Priority|P3                          |P1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2011-10-27
      Known to work|                            |4.6.2
     Ever Confirmed|0                           |1

--- Comment #4 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-10-27 11:35:18 UTC ---
Confirmed.  EDG also accepts this.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/50835] [4.7 Regression] Lvalue-ness of conditional operator results is incorrect in a function template
  2011-10-23  2:10 [Bug c++/50835] New: [4.7 Regression] Lvalue-ness of conditional operator results is incorrect in a function template mimomorin at gmail dot com
                   ` (4 preceding siblings ...)
  2011-10-27 11:36 ` rguenth at gcc dot gnu.org
@ 2011-11-08 17:14 ` jason at gcc dot gnu.org
  2011-11-08 17:31 ` jason at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu.org @ 2011-11-08 17:14 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50835

--- Comment #5 from Jason Merrill <jason at gcc dot gnu.org> 2011-11-08 17:10:16 UTC ---
Author: jason
Date: Tue Nov  8 17:10:09 2011
New Revision: 181174

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=181174
Log:
    PR c++/50835
    * typeck.c (build_x_conditional_expr): Preserve lvalue/xvalueness.
    * tree.c (lvalue_kind) [NON_DEPENDENT_EXPR]: Return clk_ordinary
    in C++98.

Added:
    trunk/gcc/testsuite/g++.dg/template/lvalue2.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/tree.c
    trunk/gcc/cp/typeck.c
    trunk/gcc/testsuite/ChangeLog


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/50835] [4.7 Regression] Lvalue-ness of conditional operator results is incorrect in a function template
  2011-10-23  2:10 [Bug c++/50835] New: [4.7 Regression] Lvalue-ness of conditional operator results is incorrect in a function template mimomorin at gmail dot com
                   ` (5 preceding siblings ...)
  2011-11-08 17:14 ` jason at gcc dot gnu.org
@ 2011-11-08 17:31 ` jason at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu.org @ 2011-11-08 17:31 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50835

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED

--- Comment #6 from Jason Merrill <jason at gcc dot gnu.org> 2011-11-08 17:28:58 UTC ---
Fixed.


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-11-08 17:30 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-23  2:10 [Bug c++/50835] New: [4.7 Regression] Lvalue-ness of conditional operator results is incorrect in a function template mimomorin at gmail dot com
2011-10-23 11:47 ` [Bug c++/50835] " daniel.kruegler at googlemail dot com
2011-10-23 11:50 ` daniel.kruegler at googlemail dot com
2011-10-23 12:24 ` daniel.kruegler at googlemail dot com
2011-10-27  9:23 ` rguenth at gcc dot gnu.org
2011-10-27 11:36 ` rguenth at gcc dot gnu.org
2011-11-08 17:14 ` jason at gcc dot gnu.org
2011-11-08 17:31 ` jason at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).