Hi,
I'm using MS VC 6.0.
The compiler has a fatal error on the program below.
If the destructor is removed, the compilation succeeded.

Does anyone have an idea why?
Is it a correct C++ program?

Thanks,
Erez.

The Program:
------------
class Cl {
public:
~Cl();
};

Cl::~Cl(){
}

Cl getCl() {
return Cl();
}

void main() {
static Cl &cl = getCl(); // Simplified version which cause the fatal error
//static ClBase &clBase = getCl(); // The real case. Cl derived from ClBase
}

The compiler output:
---------------------
Compiling...
testRef1.cpp
fatal error C1001: INTERNAL COMPILER ERROR
(compiler file 'E:\8966\vc98\p2\src\P2\main.c', line 494)
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
Error executing cl.exe.

testRef1.exe - 1 error(s), 0 warning(s)

Re: Compiler internal error by Gianni

Gianni
Sun Feb 08 12:58:33 CST 2004

Erez wrote:
> Hi,
> I'm using MS VC 6.0.
> The compiler has a fatal error on the program below.
> If the destructor is removed, the compilation succeeded.
>
> Does anyone have an idea why?

Unless I had the source code of the compiler, there is no way of knowing
why - by definition this is an *INTERNAL* compiler error.

> Is it a correct C++ program?

No.

static Cl &cl = getCl();

getCl returns an object hence it requires somewhere to put it.

Another popular compiler (gcc 3.4pr) gives these error messages.

static_temporary.cpp:14: error: `main' must return `int'
static_temporary.cpp:14: error: return type for `main' changed to `int'
static_temporary.cpp: In function `int main(...)':
static_temporary.cpp:15: error: invalid initialization of non-const
reference of type 'Cl&' from a temporary of type 'Cl'


It's interesting that the MSVC++ 7.1 compiler does not complain at all.

The Comeau compiler gives this:
(http://www.comeaucomputing.com/tryitout/)

Comeau C/C++ 4.3.3 (Aug 6 2003 15:13:37) for ONLINE_EVALUATION_BETA1
Copyright 1988-2003 Comeau Computing. All rights reserved.
MODE:strict errors C++

"ComeauTest.c", line 13: error: return type of function "main" must be "int"
So use int main() OR int main(int argc, char *argv[])
void main() {
^

"ComeauTest.c", line 14: error: initial value of reference to non-const
must be an
lvalue
static Cl &cl = getCl(); // Simplified version which cause the
fatal error
^

2 errors detected in the compilation of "ComeauTest.c".



... in general it's a good idea to try other compilers on a code snippet
like this because where one compiler is lax, other compilers may be better.



Re: Compiler internal error by Deming

Deming
Sun Feb 08 12:58:29 CST 2004

Erez <erez@sivron.com> wrote in message
news:c6ca9fe2.0402080844.6d0501ca@posting.google.com...
> Hi,
> I'm using MS VC 6.0.
> The compiler has a fatal error on the program below.
> If the destructor is removed, the compilation succeeded.
>
> Does anyone have an idea why?
> Is it a correct C++ program?
>
> Thanks,
> Erez.
>
> The Program:
> ------------
> class Cl

> public:
> ~Cl();
> };
>
> Cl::~Cl(){
> }
>
> Cl getCl() {
> return Cl();
> }

First, never call a constructor explicitly.
Second, where is a storage for an object of Cl created?



Re: Compiler internal error by Gianni

Gianni
Sun Feb 08 13:07:49 CST 2004

Deming He wrote:
> Erez <erez@sivron.com> wrote in message
> news:c6ca9fe2.0402080844.6d0501ca@posting.google.com...
>

>
> First, never call a constructor explicitly.

Why ? It this case the way getCl is used is a common way of
initializing an object.

Cl x = getCl()

Will probably be optimized to an in place initialization of x.

> Second, where is a storage for an object of Cl created?

A temporary in the caller.


Re: Compiler internal error by Alexander

Alexander
Sun Feb 08 15:00:18 CST 2004

Try VC with language extensions disabled.

"Gianni Mariani" <gianni@mariani.ws> wrote in message
news:ejaZOWn7DHA.2656@TK2MSFTNGP11.phx.gbl...
> Erez wrote:
> > Hi,
> > I'm using MS VC 6.0.
> > The compiler has a fatal error on the program below.
> > If the destructor is removed, the compilation succeeded.
> >
> > Does anyone have an idea why?
>
> Unless I had the source code of the compiler, there is no way of knowing
> why - by definition this is an *INTERNAL* compiler error.
>
> > Is it a correct C++ program?
>
> No.
>
> static Cl &cl = getCl();
>
> getCl returns an object hence it requires somewhere to put it.
>
> Another popular compiler (gcc 3.4pr) gives these error messages.
>
> static_temporary.cpp:14: error: `main' must return `int'
> static_temporary.cpp:14: error: return type for `main' changed to `int'
> static_temporary.cpp: In function `int main(...)':
> static_temporary.cpp:15: error: invalid initialization of non-const
> reference of type 'Cl&' from a temporary of type 'Cl'
>
>
> It's interesting that the MSVC++ 7.1 compiler does not complain at all.
>
> The Comeau compiler gives this:
> (http://www.comeaucomputing.com/tryitout/)
>
> Comeau C/C++ 4.3.3 (Aug 6 2003 15:13:37) for ONLINE_EVALUATION_BETA1
> Copyright 1988-2003 Comeau Computing. All rights reserved.
> MODE:strict errors C++
>
> "ComeauTest.c", line 13: error: return type of function "main" must be
"int"
> So use int main() OR int main(int argc, char *argv[])
> void main() {
> ^
>
> "ComeauTest.c", line 14: error: initial value of reference to non-const
> must be an
> lvalue
> static Cl &cl = getCl(); // Simplified version which cause the
> fatal error
> ^
>
> 2 errors detected in the compilation of "ComeauTest.c".
>
>
>
> ... in general it's a good idea to try other compilers on a code snippet
> like this because where one compiler is lax, other compilers may be
better.
>
>



Re: Compiler internal error by Deming

Deming
Sun Feb 08 22:34:25 CST 2004

Gianni Mariani <gianni@mariani.ws> wrote in message
news:u7xzZbn7DHA.3704@tk2msftngp13.phx.gbl...
> Deming He wrote:
> > Erez <erez@sivron.com> wrote in message
> > news:c6ca9fe2.0402080844.6d0501ca@posting.google.com...
> >
>
> >
> > First, never call a constructor explicitly.
>
> Why ? It this case the way getCl is used is a common way of
> initializing an object.
>
Oops, that was my wrong interpretation of OP's code. The OP's getCl() was
intended to create an unnamed temp. object and return it.

Then later in main(), in statement:
static Cl &cl = getCl();
The OP tried to do an assignment for the returned object to reference cl...

To keep cl, do this:
Cl o = getCl();
static Cl& cl = o;

> void main() {
> static Cl &cl = getCl(); // Simplified version which cause the fatal
error
> // Static ClBase &clBase = getCl(); // The real case. Cl derived from
ClBase
> }
>
This should be altered as follows. Otherwise it's illegal according to C++
Standard, though some compilers (versions?) let get by.

int main(){
...
return 0;
}







Re: Compiler internal error by adebaene

adebaene
Mon Feb 09 06:46:32 CST 2004

"Deming He" <deming.he@worldnet.att.net> wrote in message >
> > void main() {
>>
> This should be altered as follows. Otherwise it's illegal according to C++
> Standard, though some compilers (versions?) let get by.
>
> int main(){
> ...
> return 0;
> }

Gee, the "main" return value troll one more time :-(

If you really want to be standard-picky, the "return 0" is not
mandatory although the "int main" is (which is rather silly, but
that's another debate).

Arnaud
MVP - VC

Re: Compiler internal error by Jacky

Jacky
Tue Feb 10 00:37:01 CST 2004

I think you need a prototype in the definition of the class.
Jack

"Erez" <erez@sivron.com>
???????:c6ca9fe2.0402080844.6d0501ca@posting.google.com...
> Hi,
> I'm using MS VC 6.0.
> The compiler has a fatal error on the program below.
> If the destructor is removed, the compilation succeeded.
>
> Does anyone have an idea why?
> Is it a correct C++ program?
>
> Thanks,
> Erez.
>
> The Program:
> ------------
> class Cl {
> public:
> ~Cl();
> };
>
> Cl::~Cl(){
> }
>
> Cl getCl() {
> return Cl();
> }
>
> void main() {
> static Cl &cl = getCl(); // Simplified version which cause the fatal
error
> //static ClBase &clBase = getCl(); // The real case. Cl derived from
ClBase
> }
>
> The compiler output:
> ---------------------
> Compiling...
> testRef1.cpp
> fatal error C1001: INTERNAL COMPILER ERROR
> (compiler file 'E:\8966\vc98\p2\src\P2\main.c', line 494)
> Please choose the Technical Support command on the Visual C++
> Help menu, or open the Technical Support help file for more
information
> Error executing cl.exe.
>
> testRef1.exe - 1 error(s), 0 warning(s)



Re: Compiler internal error by Jacky

Jacky
Tue Feb 10 00:54:56 CST 2004

of the constructor

"Jacky Luk" <jwhluk@bps-group.net> ¼¶¼g©ó¶l¥ó·s»D
:enTH9A67DHA.2540@TK2MSFTNGP11.phx.gbl...
> I think you need a prototype in the definition of the class.
> Jack
>
> "Erez" <erez@sivron.com>
> ???????:c6ca9fe2.0402080844.6d0501ca@posting.google.com...
> > Hi,
> > I'm using MS VC 6.0.
> > The compiler has a fatal error on the program below.
> > If the destructor is removed, the compilation succeeded.
> >
> > Does anyone have an idea why?
> > Is it a correct C++ program?
> >
> > Thanks,
> > Erez.
> >
> > The Program:
> > ------------
> > class Cl {
> > public:
> > ~Cl();
> > };
> >
> > Cl::~Cl(){
> > }
> >
> > Cl getCl() {
> > return Cl();
> > }
> >
> > void main() {
> > static Cl &cl = getCl(); // Simplified version which cause the fatal
> error
> > //static ClBase &clBase = getCl(); // The real case. Cl derived from
> ClBase
> > }
> >
> > The compiler output:
> > ---------------------
> > Compiling...
> > testRef1.cpp
> > fatal error C1001: INTERNAL COMPILER ERROR
> > (compiler file 'E:\8966\vc98\p2\src\P2\main.c', line 494)
> > Please choose the Technical Support command on the Visual C++
> > Help menu, or open the Technical Support help file for more
> information
> > Error executing cl.exe.
> >
> > testRef1.exe - 1 error(s), 0 warning(s)
>
>