views:

492

answers:

5

I'm consistently running into an internal compiler error while attempting to switch from MSVC6 to MSVC 2008. After much work commenting out different parts of the program, I've traced the error to two lines of code in two different CPP files. Both of these CPP files compile successfully, yet somehow have an effect on whether or not the error manifests in other files.

Both of those lines involve instantianting several complex, nested templates. They also appear to be the only places in the app that use an abstract class as one of the template parameters. That said, I'm far from certain that the issue involves either abstract classes or templates, it's just the most obvious thing I've noticed. I can't even be sure that these lines are significant at all. Here's what they look like, though:

m_phDSAttributes = new SObjDict<RWCString, SIDataSource>(&RWCString::hash);

So we've got SObjDict, a templatized dictionary class, SIDataSource, an abstract interface, and the parameter is a pointer to a static member function of RWCString.

I've been playing around with the code some, and I can occasionally get the error to move from one CPP file to another (for instance, I changed a bunch of template declarations from using class to typename), but I can't find any rhyme or reason to it.

I'm at a loss as to how to debug this issue further. The exact error output by the compiler (with the name of my source file changed) is below. There is no mention of it anywhere on the internet. I'm pretty desperate for any advice on how to proceed. I don't expect someone to say "oh, you just need to do XYZ", but a pointer on how to debug this sort of issue would be greatly appreciated.

1>d:\Dev\webapi.cpp : fatal error C1001: An internal error has occurred in the compiler.
1>(compiler file 'f:\dd\vctools\compiler\utc\src\p2\p2symtab.c', line 5905)
A: 

This typically happens with template instantiation. Unfortunately it could be caused by many things, but 99% of the time your code is subtly invoking undefined behavior.

rlbond
A: 

Start breaking it down into smaller parts. My first guess is the pointer to the static function is going to be the problem. Can you make a dummy non-template class with the same parameter in the constructor? Does it compile if you don't use an abstract class in the template?

Looks like I'm sending you in the wrong direction, the following compiles fine in 2008:

class thing {
public:
    static void hash( short sht ) {
    }

    void hash( long lng ) {
    }
};

class thing2 {
public:
    thing2( void (short ) ){}
};

int _tmain(int argc, _TCHAR* argv[])
{
    thing2* t = new thing2( &thing::hash );
    delete t;
    return 0;
}

The principle remains though, remove/replace complex elements until you have code that compiles and you'll know what is causing the problem.

Patrick
that the function pointer is the problem is something I hadn't considered. I just noticed there are 2 functions called hash() inside RWCString. One is static, the other is a member function. They have different signatures though... is there any way for me to manually disambiguate them so I can be sure that isn't tripping up the compiler?
rmeador
If you have control over RWCString then change the name obviously, if not create a dummy class with two similar functions just to check if that is your problem. I expect there is something you can do with function pointers to disambiguate (a function pointer has a signature after all), if not wrap the RWCString class and have one static member function called hash2 that calls the original static function... not very elegant but would defintely do the trick.
Patrick
A: 

It's a reasonable bet to assume that p2symtab.c is (part of) the symbol table code. This would immediately explain how the upgrade caused it; this code has been rewritten. (Remember the 255 character length warnings of VC6?)

In this case, there is no new entry in the symbol table, so it's likely a lookup in the symbol table failing spectactularly. It would be interesting to see if the context in which th name lookup happens affects the result. For instance, what happens if you change the code to

typedef SObjDict<RWCString, SIDataSource> SObjDict_RWCString_SIDataSource;
m_phDSAttributes = new SObjDict_RWCString_SIDataSource(&RWCString::hash);

This will force another symbol table entry to be created, for SObjDict_RWCString_SIDataSource. This entry is sort of a symbolic link to the template instantiation. The new name can (and must) be looked up on its own.

MSalters
I tried implementing your suggestion and it didn't change the results. It's really too bad, since your idea seems sound and plausible.
rmeador
A: 

fatal error C1001: An internal error has occurred in the compiler. 1>(compiler file 'f:\dd\vctools\compiler\utc\src\p2\p2symtab.c

i also observed the same error when i try to build my vs 2005 code to vs 2008. but it happen till i have not installed Service pack of VS 2008...

have you installed Service pack... i think this will resolved your issue....

Kasma
I have installed service pack 1, which is the newest available as far as I know.
rmeador
A: 

I feel somewhat bad putting an answer on my own question and accepting it, but I guess it's the right thing to do... I solved my problem, at least temporarily. The trick seems to be disabling precompiled headers. I have no idea why that solves the problem, and it's very unfortunate since my build time for the affected project has gone from less than 30 secs to nearly 5 minutes, but at least I can progress forward... If anyone comes up with a more permanent solution, I'd be more than happy to mark their answer as Accepted.

rmeador