From: FE on
class null_t
{
public:
template<typename T>
operator T*(){return 0;}
}NULL;

int main()
{

if(*NPP)cout<<"*this"<<endl;

return 0;
}


gcc(codeblocks with) :internal compiler error: Segmentation fault


vs2008 no error but Generated Program clash

which is correct?

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Johannes Schaub (litb) on
FE wrote:

> class null_t
> {
> public:
> template<typename T>
> operator T*(){return 0;}
> }NULL;
>
> int main()
> {
>
> if(*NPP)cout<<"*this"<<endl;
>
> return 0;
> }
>
>
> gcc(codeblocks with) :internal compiler error: Segmentation fault
>
>
> vs2008 no error but Generated Program clash
>
> which is correct?
>
I think "NULL" should be "NPP" above? Then in "*NPP" you are invoking the
unary * on a class type object. You will get the following imaginary
operator function candidates for overload resolution:

For every cv-qualified or cv-unqualified object type T, there exist
candidate operator functions of the form

T& operator*(T*);

For every function type T, there exist candidate operator functions of the
form

T& operator*(T*);

By argument deduction, you will deduce "T*" each time to those destination
parameter types. Assume you know the entire set of object and function types
in existence, even those outside of the current translation unit. This can't
actually be done, but as we will later see you don't really need to create
that candidate set as you know already what the outcome of it is.

The resulting conversion sequence each time is a user defined conversion
sequence using different conversion functions used in that sequence each
time (the conversion function template specializations). However to order
two user defined conversion sequences, both must use the same conversion
function. So in the above, "*NPP" is ambiguous. As a result, overload
resolution fails and the construct is ill-formed.


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Thomas Richter on

> class null_t
> {
> public:
> template<typename T>
> operator T*(){return 0;}
> }NULL;
>
> int main()
> {
>
> if(*NPP)cout<<"*this"<<endl;
>
> return 0;
> }

This doesn't even compile. First of all, NPP is not declared. cout is
not declared, a proper include is missing, and main is not a member
function of a class, thus "*this" doesn't make any sense.

Now, please post the complete example you are trying to compile.

Greetings,
Thomas

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Ulrich Eckhardt on
FE wrote:
> class null_t
> {
> public:
> template<typename T>
> operator T*(){return 0;}
> }NULL;
>
> int main()
> {
>
> if(*NPP)cout<<"*this"<<endl;
>
> return 0;
> }
>
>
> gcc(codeblocks with) :internal compiler error: Segmentation fault
>
>
> vs2008 no error but Generated Program clash
>
> which is correct?

1. You redefine that is commonly used as a macro elsewhere (NULL).
2. You use three undefined symbols (NPP, cout, endl).

Committing suicide like GCC did was just the expression of it feeling very
sad about the given code. Not every compiler is already as numb as MS's
probably is when served fertiliser for dinner. ;^)

Uli

--
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Pete Becker on
Ulrich Eckhardt wrote:
>
> Committing suicide like GCC did was just the expression of it feeling very
> sad about the given code. Not every compiler is already as numb as MS's
> probably is when served fertiliser for dinner. ;^)
>

Umm, let's be clear here: GCC crashed. That's a bug in the compiler.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of
"The Standard C++ Library Extensions: a Tutorial and Reference"
(www.petebecker.com/tr1book)

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]