public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/7503] (x < Y ? X : Y) as an lvalue and assignment
       [not found] <20020805221601.7503.moore_mn@cobra.cs.mercer.edu>
@ 2003-08-19  4:13 ` pinskia at gcc dot gnu dot org
  2003-08-19  7:02 ` falk at debian dot org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-08-19  4:13 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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


pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2003-05-03 00:00:00         |2003-08-19 04:13:37
               date|                            |


------- Additional Comments From pinskia at gcc dot gnu dot org  2003-08-19 04:13 -------
Related to bug 11427.  I think this extension should be removed as the C front-end 
rejects this.


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

* [Bug c++/7503] (x < Y ? X : Y) as an lvalue and assignment
       [not found] <20020805221601.7503.moore_mn@cobra.cs.mercer.edu>
  2003-08-19  4:13 ` [Bug c++/7503] (x < Y ? X : Y) as an lvalue and assignment pinskia at gcc dot gnu dot org
@ 2003-08-19  7:02 ` falk at debian dot org
  2003-08-19  8:23 ` moore_mn at cobra dot cs dot mercer dot edu
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: falk at debian dot org @ 2003-08-19  7:02 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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



------- Additional Comments From falk at debian dot org  2003-08-19 07:02 -------
It's not an extension, the C++ language allows this.


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

* [Bug c++/7503] (x < Y ? X : Y) as an lvalue and assignment
       [not found] <20020805221601.7503.moore_mn@cobra.cs.mercer.edu>
  2003-08-19  4:13 ` [Bug c++/7503] (x < Y ? X : Y) as an lvalue and assignment pinskia at gcc dot gnu dot org
  2003-08-19  7:02 ` falk at debian dot org
@ 2003-08-19  8:23 ` moore_mn at cobra dot cs dot mercer dot edu
  2003-08-19  8:58 ` schwab at suse dot de
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: moore_mn at cobra dot cs dot mercer dot edu @ 2003-08-19  8:23 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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



------- Additional Comments From moore_mn at cobra dot cs dot mercer dot edu  2003-08-19 08:23 -------
Subject:  (x < Y ? X : Y) as an lvalue and assignment

I believe that C allows it too.
I also believe that C99 allows all of
the short-cut versions ( ?> and friends).

I might have made an attempt to fix it
myself (in g++) if it could easily be converted
to an equivalent if/else stmt, but that gets
complex and I don't know the internals well
enough.  Converting it to evaluate to a
reference to the "winner" would break
for register variables.  Always converting
(with or without the assignment) would
break if there were a constant as one of
the contestants (contestants meaning possible
results of the ?: ).
I think that ?: and friends are almost more
trouble than they are worth, with conditional
exacution and conditional assignments.
What still bothers me is that the second
test program I sent works(or did when I sent it),
while the first didn't.  The only real difference
was that the result of the operation in the version
that didn't work could be determined at compile
time while the other asks for input which is used
to determine the outcome.
It probably should be disabled and an error issued
because there may be some code somewhere out there
that uses this and expects it to work, since it
compiles without a hitch.  Well, either people
are assuming that it works (and their code behaves
badly, but not such that they notice) or they are
not using it.  Either way, an error should be reported
if it might be broken.  (my guess, no one is using it
except for CS students and professors, and then in
test code to see if it works)

Nathan Moore


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

* [Bug c++/7503] (x < Y ? X : Y) as an lvalue and assignment
       [not found] <20020805221601.7503.moore_mn@cobra.cs.mercer.edu>
                   ` (2 preceding siblings ...)
  2003-08-19  8:23 ` moore_mn at cobra dot cs dot mercer dot edu
@ 2003-08-19  8:58 ` schwab at suse dot de
  2004-05-23 21:52 ` [Bug c++/7503] (x < Y ? X : Y) used for assignment causes wrong code pinskia at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: schwab at suse dot de @ 2003-08-19  8:58 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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



------- Additional Comments From schwab at suse dot de  2003-08-19 08:58 -------
In C the result of ?: is never an lvalue.


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

* [Bug c++/7503] (x < Y ? X : Y) used for assignment causes wrong code
       [not found] <20020805221601.7503.moore_mn@cobra.cs.mercer.edu>
                   ` (3 preceding siblings ...)
  2003-08-19  8:58 ` schwab at suse dot de
@ 2004-05-23 21:52 ` pinskia at gcc dot gnu dot org
  2004-06-20 15:17 ` pinskia at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-05-23 21:52 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-05-22 22:55 -------
The problem is how MAX_EXPR is expanded, as (x < 0) ? X : Y = 1 works.

-- 


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


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

* [Bug c++/7503] (x < Y ? X : Y) used for assignment causes wrong code
       [not found] <20020805221601.7503.moore_mn@cobra.cs.mercer.edu>
                   ` (4 preceding siblings ...)
  2004-05-23 21:52 ` [Bug c++/7503] (x < Y ? X : Y) used for assignment causes wrong code pinskia at gcc dot gnu dot org
@ 2004-06-20 15:17 ` pinskia at gcc dot gnu dot org
  2004-06-21 15:01 ` bangerth at dealii dot org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-06-20 15:17 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-06-20 15:17 -------
*** Bug 16102 has been marked as a duplicate of this bug. ***

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ofiravni99 at walla dot co
                   |                            |dot il


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


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

* [Bug c++/7503] (x < Y ? X : Y) used for assignment causes wrong code
       [not found] <20020805221601.7503.moore_mn@cobra.cs.mercer.edu>
                   ` (5 preceding siblings ...)
  2004-06-20 15:17 ` pinskia at gcc dot gnu dot org
@ 2004-06-21 15:01 ` bangerth at dealii dot org
  2004-06-21 15:56 ` schwab at suse dot de
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: bangerth at dealii dot org @ 2004-06-21 15:01 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-06-21 15:01 -------
One (possibly good) question: does a ?: operator involve sequence 
points? If we have an expression like 
  (a>b ? a : b) = 1; 
with a,b being references, then we use some of the variables both 
for evaluation and for assignment, and the question is if any of these 
operations need to be ordered. 
 
W. 

-- 


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


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

* [Bug c++/7503] (x < Y ? X : Y) used for assignment causes wrong code
       [not found] <20020805221601.7503.moore_mn@cobra.cs.mercer.edu>
                   ` (6 preceding siblings ...)
  2004-06-21 15:01 ` bangerth at dealii dot org
@ 2004-06-21 15:56 ` schwab at suse dot de
  2004-09-12  5:38 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: schwab at suse dot de @ 2004-06-21 15:56 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From schwab at suse dot de  2004-06-21 15:56 -------
There is a sequence point after the evaluation of the condition (6.5.15#4). 

-- 


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


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

* [Bug c++/7503] (x < Y ? X : Y) used for assignment causes wrong code
       [not found] <20020805221601.7503.moore_mn@cobra.cs.mercer.edu>
                   ` (7 preceding siblings ...)
  2004-06-21 15:56 ` schwab at suse dot de
@ 2004-09-12  5:38 ` pinskia at gcc dot gnu dot org
  2004-09-21 16:20 ` cvs-commit at gcc dot gnu dot org
  2004-09-21 18:43 ` pinskia at gcc dot gnu dot org
  10 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-09-12  5:38 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-09-12 05:38 -------
Patch posted here: <http://gcc.gnu.org/ml/gcc-patches/2004-09/msg01130.html>.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch


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


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

* [Bug c++/7503] (x < Y ? X : Y) used for assignment causes wrong code
       [not found] <20020805221601.7503.moore_mn@cobra.cs.mercer.edu>
                   ` (8 preceding siblings ...)
  2004-09-12  5:38 ` pinskia at gcc dot gnu dot org
@ 2004-09-21 16:20 ` cvs-commit at gcc dot gnu dot org
  2004-09-21 18:43 ` pinskia at gcc dot gnu dot org
  10 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2004-09-21 16:20 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2004-09-21 16:20 -------
Subject: Bug 7503

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	sayle@gcc.gnu.org	2004-09-21 16:20:12

Modified files:
	gcc/cp         : ChangeLog tree.c typeck.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/opt: pr7503-1.C pr7503-2.C pr7503-3.C 
	                          pr7503-4.C pr7503-5.C 

Log message:
	PR c++/7503
	* tree.c (lvalue_p_1):  Disallow MIN_EXPR and MAX_EXPR as lvalues
	if either operand has side-effects.
	* typeck.c (rationalize_conditional_expr): Assert that neither
	operand of MIN_EXPR or MAX_EXPR has side-effects.
	(build_modify_expr):  Add support for MIN_EXPR and MAX_EXPR.
	Check that the "lhs" is a valid lvalue, i.e. that neither operand
	of a MIN_EXPR or MAX_EXPR has a side-effect.
	
	* g++.dg/opt/pr7503-1.C: New testcase for COND_EXPR lvalues.
	* g++.dg/opt/pr7503-2.C: New testcase for <? and >? lvalues.
	* g++.dg/opt/pr7503-3.C: New testcase for invalid <? lvalue errors.
	* g++.dg/opt/pr7503-4.C: New testcase for <?= and >?= assignments.
	* g++.dg/opt/pr7503-5.C: New testcase for side-effects with <?=.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4371&r2=1.4372
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/tree.c.diff?cvsroot=gcc&r1=1.410&r2=1.411
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&r1=1.577&r2=1.578
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4325&r2=1.4326
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/opt/pr7503-1.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/opt/pr7503-2.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/opt/pr7503-3.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/opt/pr7503-4.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/opt/pr7503-5.C.diff?cvsroot=gcc&r1=NONE&r2=1.1



-- 


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


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

* [Bug c++/7503] (x < Y ? X : Y) used for assignment causes wrong code
       [not found] <20020805221601.7503.moore_mn@cobra.cs.mercer.edu>
                   ` (9 preceding siblings ...)
  2004-09-21 16:20 ` cvs-commit at gcc dot gnu dot org
@ 2004-09-21 18:43 ` pinskia at gcc dot gnu dot org
  10 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-09-21 18:43 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-09-21 18:43 -------
Fixed for 4.0.0.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.0.0


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


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

end of thread, other threads:[~2004-09-21 18:43 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20020805221601.7503.moore_mn@cobra.cs.mercer.edu>
2003-08-19  4:13 ` [Bug c++/7503] (x < Y ? X : Y) as an lvalue and assignment pinskia at gcc dot gnu dot org
2003-08-19  7:02 ` falk at debian dot org
2003-08-19  8:23 ` moore_mn at cobra dot cs dot mercer dot edu
2003-08-19  8:58 ` schwab at suse dot de
2004-05-23 21:52 ` [Bug c++/7503] (x < Y ? X : Y) used for assignment causes wrong code pinskia at gcc dot gnu dot org
2004-06-20 15:17 ` pinskia at gcc dot gnu dot org
2004-06-21 15:01 ` bangerth at dealii dot org
2004-06-21 15:56 ` schwab at suse dot de
2004-09-12  5:38 ` pinskia at gcc dot gnu dot org
2004-09-21 16:20 ` cvs-commit at gcc dot gnu dot org
2004-09-21 18:43 ` pinskia at gcc dot gnu dot 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).