public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/14802] New: [3.3/3.4/3.5 Regression] Conditional expression with throw and void fails to compile
@ 2004-03-31 22:13 alexis at ortsa dot com
  2004-03-31 22:53 ` [Bug c++/14802] " bangerth at dealii dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: alexis at ortsa dot com @ 2004-03-31 22:13 UTC (permalink / raw)
  To: gcc-bugs

This code does not compile with recent versions of g++-3.3:

int main() { 0 ? (void) 0: throw 0; }

It produces the following error:
error: void value not ignored as it ought to be

The standard, as included in the comments of gcc/gcc/cp/call.c states:
[expr.cond]
  If either the second or the third operand has type (possibly
  cv-qualified) void, then the lvalue-to-rvalue (_conv.lval_),
  array-to-pointer (_conv.array_), and function-to-pointer
  (_conv.func_) standard conversions are performed on the second
  and third operands. 

  One of the following shall hold:
  --The second or the third operand (but not both) is a
    throw-expression (_except.throw_); the result is of the
    type of the other and is an rvalue.
  --Both the second and the third operands have type void; the
    result is of type void and is an rvalue.

As I understand it, both cases hold in this example, and so the result is of
type void and is an rvalue. The resulting value is not used, so I think that the
code is valid.

I believe that the behavior changed because of this patch:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/call.c.diff?cvsroot=gcc&r1=1.461&r2=1.462
that fixed bug 14083. The example compiles correctly on a version of g++-3.3.3
dating around February (I don't have the exact version, sorry), as it does with
g++-3.2.3.

The following patch should eliminate the compilation error without breaking the fix:
--- call.c.orig 2004-03-31 22:23:57.000000000 +0200
+++ call.c.new  2004-03-31 22:28:40.000000000 +0200
@@ -3182,14 +3182,16 @@
       if (TREE_CODE (arg2) == THROW_EXPR
          && TREE_CODE (arg3) != THROW_EXPR)
        {
-         arg3 = force_rvalue (arg3);
+         if (!VOID_TYPE_P (arg3_type))
+           arg3 = force_rvalue (arg3);
          arg3_type = TREE_TYPE (arg3);
          result_type = arg3_type;
        }
       else if (TREE_CODE (arg2) != THROW_EXPR
               && TREE_CODE (arg3) == THROW_EXPR)
        {
-         arg2 = force_rvalue (arg2);
+         if (!VOID_TYPE_P (arg2_type))
+           arg2 = force_rvalue (arg2);
          arg2_type = TREE_TYPE (arg2);
          result_type = arg2_type;
        }

It seems that force_rvalue returns an error when given an argument of type void.
I don't know if this behavior is correct, but it's easy to contourn in this case.



Sorry for my english, I hope everything is understandable.

-- 
           Summary: [3.3/3.4/3.5 Regression] Conditional expression with
                    throw and void fails to compile
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: alexis at ortsa dot com
                CC: gcc-bugs at gcc dot gnu dot org


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


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

* [Bug c++/14802] [3.3/3.4/3.5 Regression] Conditional expression with throw and void fails to compile
  2004-03-31 22:13 [Bug c++/14802] New: [3.3/3.4/3.5 Regression] Conditional expression with throw and void fails to compile alexis at ortsa dot com
@ 2004-03-31 22:53 ` bangerth at dealii dot org
  2004-03-31 23:16 ` alexis at ortsa dot com
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: bangerth at dealii dot org @ 2004-03-31 22:53 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-03-31 22:53 -------
That seems about right. I can reproduce this with a 3.3.4 snapshot of 
20030223 and a mainline snapshot of 20040307, but not with a 3.4 snapshot 
of 20030319, so it may already be fixed. Which gcc versino did you use? 
 
W. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING


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


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

* [Bug c++/14802] [3.3/3.4/3.5 Regression] Conditional expression with throw and void fails to compile
  2004-03-31 22:13 [Bug c++/14802] New: [3.3/3.4/3.5 Regression] Conditional expression with throw and void fails to compile alexis at ortsa dot com
  2004-03-31 22:53 ` [Bug c++/14802] " bangerth at dealii dot org
@ 2004-03-31 23:16 ` alexis at ortsa dot com
  2004-03-31 23:27 ` [Bug c++/14802] [3.3/3.4 " pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: alexis at ortsa dot com @ 2004-03-31 23:16 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From alexis at ortsa dot com  2004-03-31 23:16 -------
I produced the error with gcc version 3.3.3 (Debian 20040321) and gcc version
3.4.0 20040314 (prerelease).

But I made the diff using call.c from the CVS, so if something got fixed it must
be in force_rvalue, and the change occured between the 14th and the 19th of March.

-- 


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


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

* [Bug c++/14802] [3.3/3.4 Regression] Conditional expression with throw and void fails to compile
  2004-03-31 22:13 [Bug c++/14802] New: [3.3/3.4/3.5 Regression] Conditional expression with throw and void fails to compile alexis at ortsa dot com
  2004-03-31 22:53 ` [Bug c++/14802] " bangerth at dealii dot org
  2004-03-31 23:16 ` alexis at ortsa dot com
@ 2004-03-31 23:27 ` pinskia at gcc dot gnu dot org
  2004-03-31 23:35 ` [Bug c++/14802] [3.3 " pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-03-31 23:27 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-03-31 23:27 -------
I also cannot reproduce it on the mainline built last night.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |3.5.0 3.4.0
            Summary|[3.3/3.4/3.5 Regression]    |[3.3/3.4 Regression]
                   |Conditional expression with |Conditional expression with
                   |throw and void fails to     |throw and void fails to
                   |compile                     |compile


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


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

* [Bug c++/14802] [3.3 Regression] Conditional expression with throw and void fails to compile
  2004-03-31 22:13 [Bug c++/14802] New: [3.3/3.4/3.5 Regression] Conditional expression with throw and void fails to compile alexis at ortsa dot com
                   ` (2 preceding siblings ...)
  2004-03-31 23:27 ` [Bug c++/14802] [3.3/3.4 " pinskia at gcc dot gnu dot org
@ 2004-03-31 23:35 ` pinskia at gcc dot gnu dot org
  2004-04-01  0:29 ` alexis at ortsa dot com
  2004-05-17 13:18 ` gdr at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-03-31 23:35 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-03-31 23:35 -------
Fixed in 3.4 and 3.5.0 by: <http://gcc.gnu.org/ml/gcc-patches/2004-03/msg01568.html>.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |NEW
     Ever Confirmed|                            |1
           Keywords|                            |rejects-valid
   Last reconfirmed|0000-00-00 00:00:00         |2004-03-31 23:35:21
               date|                            |
            Summary|[3.3/3.4 Regression]        |[3.3 Regression] Conditional
                   |Conditional expression with |expression with throw and
                   |throw and void fails to     |void fails to compile
                   |compile                     |
   Target Milestone|---                         |3.3.4
            Version|unknown                     |3.3.4


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


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

* [Bug c++/14802] [3.3 Regression] Conditional expression with throw and void fails to compile
  2004-03-31 22:13 [Bug c++/14802] New: [3.3/3.4/3.5 Regression] Conditional expression with throw and void fails to compile alexis at ortsa dot com
                   ` (3 preceding siblings ...)
  2004-03-31 23:35 ` [Bug c++/14802] [3.3 " pinskia at gcc dot gnu dot org
@ 2004-04-01  0:29 ` alexis at ortsa dot com
  2004-05-17 13:18 ` gdr at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: alexis at ortsa dot com @ 2004-04-01  0:29 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From alexis at ortsa dot com  2004-04-01 00:29 -------
It seems that I got the wrong version of call.c from the CVS, sorry.
So I guess you should just apply the same patch on 3.3?

Anyway, it seems that I was correct and 2 weeks late, I promiss do be more
careful next time.

-- 


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


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

* [Bug c++/14802] [3.3 Regression] Conditional expression with throw and void fails to compile
  2004-03-31 22:13 [Bug c++/14802] New: [3.3/3.4/3.5 Regression] Conditional expression with throw and void fails to compile alexis at ortsa dot com
                   ` (4 preceding siblings ...)
  2004-04-01  0:29 ` alexis at ortsa dot com
@ 2004-05-17 13:18 ` gdr at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: gdr at gcc dot gnu dot org @ 2004-05-17 13:18 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From gdr at gcc dot gnu dot org  2004-05-16 22:59 -------
Patch applied.

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


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


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

end of thread, other threads:[~2004-05-16 23:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-31 22:13 [Bug c++/14802] New: [3.3/3.4/3.5 Regression] Conditional expression with throw and void fails to compile alexis at ortsa dot com
2004-03-31 22:53 ` [Bug c++/14802] " bangerth at dealii dot org
2004-03-31 23:16 ` alexis at ortsa dot com
2004-03-31 23:27 ` [Bug c++/14802] [3.3/3.4 " pinskia at gcc dot gnu dot org
2004-03-31 23:35 ` [Bug c++/14802] [3.3 " pinskia at gcc dot gnu dot org
2004-04-01  0:29 ` alexis at ortsa dot com
2004-05-17 13:18 ` gdr 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).