[BUG] ICE cause by template class with constructor-like declaration with name of different class and

S

Sven Groot

This was posted by someone in comp.lang.c++, and later in
microsoft.public.vstudio.general, but since I know Carl is in this group,
and he's the one that should read this, I've reposted it here. I've also
minimalised the code that causes the bug.

The bug is that the following syntax causes an Internal Compiler Error. The
code is not correct, but should produce a warning or error message, not an
ICE. It occurs when a template class mistakenly names its constructor after
a different class, and in addition uses a template type parameter followed
by 'const'. See 'example below'. The code is complete.

----CODE SAMPLE----
class SomeClassA
{
};

template<typename X>
class SomeClassB
{
public:
SomeClassA(X const &n) { }; // *
};

int main()
{
return 0;
}
----END CODE SAMPLE----

----COMPILER OUTPUT----
test2.cpp
d:\My Documents\Visual Studio Projects\cpptest\test2.cpp(9) : fatal error
C1001: INTERNAL COMPILER ERROR
(compiler file 'msc1.cpp', line 2701)
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
----END COMPILER OUTPUT----

The error occurs in the line marked // *. Remove the 'const' and the code
correctly fails to compile because it sees SomeClassA as a typename, but at
least in this situation it gives proper error messages, not an ICE. Remove
class SomeClassA, and the code compiles with "warning C4183: 'SomeClassA':
missing return type; assumed to be a member function returning 'int'".
Change the 'X' on line * into 'int', and the code compiles with the same
warning.

I'm not certain if code like this is supposed to compile according to the
standard with such a warning, or if it's supposed to fail like when the
const is removed, but I do know it shouldn't give an ICE.
 
S

Sven Groot

Sven said:
The bug is that the following syntax causes an Internal Compiler
Error. The code is not correct, but should produce a warning or error
message, not an ICE. It occurs when a template class mistakenly names
its constructor after a different class, and in addition uses a
template type parameter followed by 'const'. See 'example below'. The
code is complete.

I forgot to mention that this happens in Visual Studio .Net 2003.
 
C

Carl Daniel [VC++ MVP]

Sven said:
This was posted by someone in comp.lang.c++, and later in
microsoft.public.vstudio.general, but since I know Carl is in this
group, and he's the one that should read this, I've reposted it here.
I've also minimalised the code that causes the bug.

I guess I'm the official VC++ bug reporter now ;-) (seriously though -
there's lots of people, including VC team members, that read this NG and can
handle this kind of thing just as well as I).
The bug is that the following syntax causes an Internal Compiler
Error. The code is not correct, but should produce a warning or error
message, not an ICE. It occurs when a template class mistakenly names
its constructor after a different class, and in addition uses a
template type parameter followed by 'const'. See 'example below'. The
code is complete.

I'm quite sure this is a known bug. Of course, in the ideal world, nothing
should result in an ICE. In this case, the code is ill-formed, and at least
according to the standard, an ICE is just as valid a message from the
compiler as a "proper" error message would be. Of course, to end-users, the
story is different!
I'm not certain if code like this is supposed to compile according to
the standard with such a warning, or if it's supposed to fail like
when the const is removed, but I do know it shouldn't give an ICE.

The code is ill-formed with or without the const. Note that "implicit int",
which VC supports, but which is not a part of the C++ standard, confuses
situations like this quite a bit.

-cd
 
A

Ayman Shoukry [MSFT]

Thanks Sven for reporting the issue. It could be a known issue but I logged
it as issue# 583177 anyways.

I also made sure that it is currently fixed using the most recent compiler
builds. With the current compiler bits, meaningful erros are reported.

--------------------
| From: "Sven Groot" <[email protected]>
| Subject: [BUG] ICE cause by template class with constructor-like
declaration with name of different class and template const parameters
| Date: Thu, 6 May 2004 21:47:15 +0200
| Lines: 55
| MIME-Version: 1.0
| Content-Type: text/plain;
| format=flowed;
| charset="iso-8859-1";
| reply-type=original
| Content-Transfer-Encoding: 7bit
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2120
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2120
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.languages.vc
| NNTP-Posting-Host: 26-192.surfsnel.dsl.internl.net 145.99.192.26
| Path:
cpmsftngxa10.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10
.phx.gbl
| Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.languages.vc:36535
| X-Tomcat-NG: microsoft.public.dotnet.languages.vc
|
| This was posted by someone in comp.lang.c++, and later in
| microsoft.public.vstudio.general, but since I know Carl is in this group,
| and he's the one that should read this, I've reposted it here. I've also
| minimalised the code that causes the bug.
|
| The bug is that the following syntax causes an Internal Compiler Error.
The
| code is not correct, but should produce a warning or error message, not
an
| ICE. It occurs when a template class mistakenly names its constructor
after
| a different class, and in addition uses a template type parameter
followed
| by 'const'. See 'example below'. The code is complete.
|
| ----CODE SAMPLE----
| class SomeClassA
| {
| };
|
| template<typename X>
| class SomeClassB
| {
| public:
| SomeClassA(X const &n) { }; // *
| };
|
| int main()
| {
| return 0;
| }
| ----END CODE SAMPLE----
|
| ----COMPILER OUTPUT----
| test2.cpp
| d:\My Documents\Visual Studio Projects\cpptest\test2.cpp(9) : fatal error
| C1001: INTERNAL COMPILER ERROR
| (compiler file 'msc1.cpp', line 2701)
| Please choose the Technical Support command on the Visual C++
| Help menu, or open the Technical Support help file for more information
| ----END COMPILER OUTPUT----
|
| The error occurs in the line marked // *. Remove the 'const' and the code
| correctly fails to compile because it sees SomeClassA as a typename, but
at
| least in this situation it gives proper error messages, not an ICE.
Remove
| class SomeClassA, and the code compiles with "warning C4183:
'SomeClassA':
| missing return type; assumed to be a member function returning 'int'".
| Change the 'X' on line * into 'int', and the code compiles with the same
| warning.
|
| I'm not certain if code like this is supposed to compile according to the
| standard with such a warning, or if it's supposed to fail like when the
| const is removed, but I do know it shouldn't give an ICE.
|
| --
| Sven Groot
|
| http://unforgiven.bloghorn.com
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top