public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* -pedantic-errors, ? : and ptrs to base classes
@ 1998-09-02 11:38 David C Binderman
  1998-09-06  5:27 ` Martin von Loewis
  0 siblings, 1 reply; 4+ messages in thread
From: David C Binderman @ 1998-09-02 11:38 UTC (permalink / raw)
  To: egcs-bugs

Hello there,

// I think this code should compile.

// On Linux / Alpha egcs-980824 with no flags it does.
// However, when I use flags -ansi -pedantic-errors, it does not.
//
// I think there is nothing wrong with the code,
// and so an error should not be produced.

struct B {};
struct D1 : public B {};
struct D2 : public B {};

B *
f( int i, D1 * pD1, D2 * pD2)
{
	return i ? pD1 : pD2;
};

Regards
David C Binderman MSc BSc	+44 1293 534847		dcb@pncl.co.uk



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

* Re: -pedantic-errors, ? : and ptrs to base classes
  1998-09-02 11:38 -pedantic-errors, ? : and ptrs to base classes David C Binderman
@ 1998-09-06  5:27 ` Martin von Loewis
  0 siblings, 0 replies; 4+ messages in thread
From: Martin von Loewis @ 1998-09-06  5:27 UTC (permalink / raw)
  To: dcb; +Cc: egcs-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1461 bytes --]

> struct B {};
> struct D1 : public B {};
> struct D2 : public B {};
> 
> B *
> f( int i, D1 * pD1, D2 * pD2)
> {
> 	return i ? pD1 : pD2;
> };

I believe g++ is right in rejecting this under pedantic mode.

5.16, [expr.cond]/6 defines the type of this expression:

>> After those conversions, one of the following shall hold: ...
>> - The second and third operands have pointer type, or one has
>> pointer type and the other is a null pointer constant; pointer
>> conversions (4.10) and qualification conversions (4.4) are
>> performed to bring them to their composite pointer type (5.9). The
>> result is of the composite pointer type.

Both operands have pointer type, and neither is a null pointer
constant. Now lets see what the composite type of these expressions
is, according to 5.9, [expr.rel]/2:

>> If one operand is a null pointer constant, the composite pointer
>> type is the type of the other operand. Otherwise, if one of the
>> operands has type "pointer to cv1 void", then the other has type
>> "pointer to cv2 T" and the composite pointer type is "pointer to
>> cv12 void", where cv12 is the union of cv1 and cv2. Otherwise, the
>> composite pointer type is a pointer type similar (4.4) to the type
>> of one of the operands, with a cv­qualification signature (4.4)
>> that is the union of the cv­qualification signatures of the operand
>> types.

Since pD1 and pD2 are not similar, the expression is not well-formed.

Regards,
Martin


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

* Re: -pedantic-errors, ? : and ptrs to base classes
  1998-09-06  8:32 David C Binderman
@ 1998-09-06 13:38 ` Martin von Loewis
  0 siblings, 0 replies; 4+ messages in thread
From: Martin von Loewis @ 1998-09-06 13:38 UTC (permalink / raw)
  To: dcb; +Cc: egcs-bugs

> I recommend having a look at 4.10. I think a pointer conversion is taking
> place.

4.10 tells me that a conversion from pD1 to B* is valid. It does not
say it is performed implicitly, not does any other part of the spec
say so.

To make the expression valid, you can write

   foo ? (B*)pD1 : (B*)pD2;

The conversions

Martin


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

* Re: -pedantic-errors, ? : and ptrs to base classes
@ 1998-09-06  8:32 David C Binderman
  1998-09-06 13:38 ` Martin von Loewis
  0 siblings, 1 reply; 4+ messages in thread
From: David C Binderman @ 1998-09-06  8:32 UTC (permalink / raw)
  To: Martin von Loewis; +Cc: egcs-bugs

At 02:28 PM 9/6/98 +0200, you wrote:
>>> After those conversions, one of the following shall hold: ...
>>> - The second and third operands have pointer type, or one has
>>> pointer type and the other is a null pointer constant; pointer
>>> conversions (4.10) and qualification conversions (4.4) are
>>> performed to bring them to their composite pointer type (5.9). The
>>> result is of the composite pointer type.
>
>Both operands have pointer type, and neither is a null pointer
>constant. Now lets see what the composite type of these expressions
>is, according to 5.9, [expr.rel]/2:

I recommend having a look at 4.10. I think a pointer conversion is taking
place.

Regards

David C Binderman MSc BSc	+44 1293 534847		dcb@pncl.co.uk



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

end of thread, other threads:[~1998-09-06 13:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-09-02 11:38 -pedantic-errors, ? : and ptrs to base classes David C Binderman
1998-09-06  5:27 ` Martin von Loewis
1998-09-06  8:32 David C Binderman
1998-09-06 13:38 ` Martin von Loewis

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).