473,387 Members | 1,470 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

[BUG] ICE when using templated user-specified cast operator

Greetings,

I'm seeing an odd problem while implementing a template user-specified cast
operator for one of my objects which frequently gets static_cast<>ed around.

The following test case demonstrates the problem, producing an Internal
Compiler Error on the line marked. I'm fairly sure this is valid C++, but I
could be wrong. (g++ at least, chows down on this without complaint.)

--- snip ---
#include <stdio.h>

class Foo
{
public:

template <typename _T> operator const _T*() const
{
return static_cast<const _T*>(this);
}
};

class FooX : public Foo
{
};

int main()
{
FooX f;

const FooX *foox = &f;
const Foo *foo = *foox; // boom!

return 0;
}
--- snip ---

Any ways around this would be appreciated, as are beatings around the head
for missing some obvious C++ legalism. :-)

Cheers,

-- Dan

Nov 16 '05 #1
4 1169
Oh, and I neglected to mention that I'm using VC++ 7.1, aka VS .NET 2K3.

Cheers,

-- Dan

"Dan Plimak" <da**@systematik.bogusbit.co.nz> wrote in message
news:ev****************@TK2MSFTNGP12.phx.gbl...
Greetings,

I'm seeing an odd problem while implementing a template user-specified cast operator for one of my objects which frequently gets static_cast<>ed around.
The following test case demonstrates the problem, producing an Internal
Compiler Error on the line marked. I'm fairly sure this is valid C++, but I could be wrong. (g++ at least, chows down on this without complaint.)

--- snip ---
#include <stdio.h>

class Foo
{
public:

template <typename _T> operator const _T*() const
{
return static_cast<const _T*>(this);
}
};

class FooX : public Foo
{
};

int main()
{
FooX f;

const FooX *foox = &f;
const Foo *foo = *foox; // boom!

return 0;
}
--- snip ---

Any ways around this would be appreciated, as are beatings around the head
for missing some obvious C++ legalism. :-)

Cheers,

-- Dan

Nov 16 '05 #2
>I'm seeing an odd problem while implementing a template user-specified cast
operator for one of my objects which frequently gets static_cast<>ed around.

The following test case demonstrates the problem, producing an Internal
Compiler Error on the line marked. I'm fairly sure this is valid C++, but I
could be wrong. (g++ at least, chows down on this without complaint.)


Dan,

I don't know whether the code is in any way suspect - it looks
reasonable to me, but a fairly reliable test is the online Comeau
compiler which also seems to think it's OK.

The ICE reproduces with the Whidbey compiler too, so I'll report it to
MS.

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
Nov 16 '05 #3
I've been fiddling with trying to get the compiler to accept it, but it
looks like no amount of de-constifying, adding random keywords like 'inline'
makes this ICE go away. Looks like it's due to a fundamental inability to
handle this type of template scenario, and it's back to doing static_cast<>s
all over the place for me...

Mind you, the below scenario does get accepted, but my actual code -- which
uses the same template construct, but somewhat more levels of inheritance --
still causes the compiler to bomb.

class Foo
{
public:

template <typename _T> operator const _T*() const
{
return static_cast<const _T*>(this);
}
};

class FooX : public Foo
{
};

int main()
{
FooX f;

const Foo *foo = &f;
const FooX *foox = *foo;

return 0;
}

-- Dan

"David Lowndes" <da****@mvps.org> wrote in message
news:u0********************************@4ax.com...
I'm seeing an odd problem while implementing a template user-specified castoperator for one of my objects which frequently gets static_cast<>ed around.
The following test case demonstrates the problem, producing an Internal
Compiler Error on the line marked. I'm fairly sure this is valid C++, but Icould be wrong. (g++ at least, chows down on this without complaint.)


Dan,

I don't know whether the code is in any way suspect - it looks
reasonable to me, but a fairly reliable test is the online Comeau
compiler which also seems to think it's OK.

The ICE reproduces with the Whidbey compiler too, so I'll report it to
MS.

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq

Nov 16 '05 #4

"Dan Plimak" <da**@systematik.bogusbit.co.nz> skrev i meddelandet
news:ex**************@TK2MSFTNGP12.phx.gbl...
Oh, and I neglected to mention that I'm using VC++ 7.1, aka VS .NET

2K3.

You are not allowed to use names starting with the combination of
underscore and uppercase letter. Those names are all reserved to the
implementer. Microsoft has already used _T as macro name in tchar.h !
Bo Persson

Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Rich | last post by:
Hi, I have a query regarding VC6 and its handling of templated copy constructors. Here goes: Take a look at the following code sample... template<class _Ty, size_t t_uiSize = 10 > class...
1
by: Koen | last post by:
Hi all, I created a little database to manage my e-books. The program will synchronize a table with the contents of a directory. Works great. Because I keep additional info (like keywords) to...
9
by: Guy | last post by:
I have extended the datetimepicker control to incorporate a ReadOnly property. I have used the new keyword to implement my own version of the value property, so that if readonly == true then it...
5
by: Hendrik Schober | last post by:
Hi, I had originally suspected this to be a bug in the std lib, that's why I started a thred in the STL newsgroup. However, it seems as if it is a compiler bug, so I'm transfering it to here....
102
by: Xah Lee | last post by:
i had the pleasure to read the PHP's manual today. http://www.php.net/manual/en/ although Pretty Home Page is another criminal hack of the unix lineage, but if we are here to judge the quality...
28
by: NewToCPP | last post by:
Hi, I am just trying to find out if there is any strong reason for not using Templates. When we use Templates it is going to replicate the code for different data types, thus increasing the...
14
by: aaragon | last post by:
Hi everyone, I've been writing some code and so far I have all the code written in the .h files in order to avoid the linker errors. I'm using templates. I wanted to move the implementations to...
20
by: tshad | last post by:
I had posted this problem earlier and just noticed that the Hyperlink is the problem. Apparently, it doesn't figure out the path correctly. It uses the path of the file it is in, even if it is...
3
by: nick4ng | last post by:
If I have a templated constructor, there is a way to know, at compile time, the instance when compiling the destructor? To be clearer my problem is that I have a templated constructor that is...
12
by: Juan T. Llibre | last post by:
re: !I found an MSDN document that explains why what I'm trying to do should work Lee, From : http://www.w3.org/TR/REC-xml/ "A special attribute named xml:lang may be inserted in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.