Topic: expression statements and operator void()
Author: kevlin@wslint.demon.co.uk (Kevlin Henney)
Date: Mon, 18 Apr 1994 09:18:53 +0000 Raw View
In article <JASON.94Apr15181458@deneb.cygnus.com>
jason@cygnus.com "Jason Merrill" writes:
>> class Avoidable
>> {
>> public:
>> operator void() { cout << "Avoidable" << endl; }
>> };
>
>The current Working Paper disallows this code:
>
>"If conversion-type-id is void or cv-qualified void, the program is
>ill-formed."
>
>So explicitly casting to void cannot differ semantically from simply
>ignoring the value.
>
>Jason
>
Thanks for this information. It should stop a lot of unnecessary 'fun'.
--
Kevlin Henney
Author: kevlin@wslint.demon.co.uk (Kevlin Henney)
Date: Fri, 15 Apr 1994 13:48:01 +0000 Raw View
In a nutshell, is a discarded value in an expression statement
considered to be implicitly cast to void, as in Algol-68, or not?
#include <iostream.h>
class Avoidable
{
public:
operator void() { cout << "Avoidable" << endl; }
};
int main()
{
Avoidable thing;
(void) thing; // 1
thing; // 2
return 0;
}
So are statements 1 and 2 equivalent? Trial by compiler(s) says they are
not, but is this truly the case or an oversight? The ARM does not seem
to mention how discarded values are treated.
--
Kevlin Henney
Author: jason@cygnus.com (Jason Merrill)
Date: Sat, 16 Apr 1994 01:14:58 GMT Raw View
>>>>> Kevlin Henney <kevlin@wslint.demon.co.uk> writes:
> class Avoidable
> {
> public:
> operator void() { cout << "Avoidable" << endl; }
> };
The current Working Paper disallows this code:
"If conversion-type-id is void or cv-qualified void, the program is
ill-formed."
So explicitly casting to void cannot differ semantically from simply
ignoring the value.
Jason