473,320 Members | 1,817 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,320 software developers and data experts.

VS.NET 7.1 Internal compiler error on inline template method??

Hi

I have taken the liberty to cross-post this. It appeared on c.l.c++.m
but the ICE is regarding VS.NET 7.1 C++ compiler.

post follows:

==============================================
John Torjo wrote:

Thus, I suggest you send the smallest example that fails to compile
(or a link to it)


John,

Thank you for the response. We've managed to capture a small snippet
of
code that generates the Internal compiler error. It is as follows:

#include <memory>

class Key { };

class NullKey : public Key { };

class SortList { };

template <typename T> class SortOrder : public SortList {
public:
SortOrder() { }
};
class obj { typedef NullKey KeyType; };
class PersistenceManager {
//public:
// PersistenceManager() { }
public:
template <typename T> void loadSet(const Key &key = NullKey(),
const SortOrder<T>
&sort =
SortOrder<T>());
};

template <typename T>
void PersistenceManager::loadSet(const Key &key,
const SortOrder<T> &sort) {

}

void main() {
PersistenceManager pm;
pm.loadSet<obj>();
}

Beyond this, if the default constructor for PersistenceManager is
uncommented, the INTERNAL COMPILER ERROR disappears and is replaced by
a
standard compiler error, which also does not make sense:

d:\Documents and Settings\mpetter\My
Documents\Projects\test2\test2.cpp(25): error C2440: 'default
argument' :
cannot convert from 'SortOrder<T>' to 'const SortOrder<T> &'
with
[
T=obj
]
If the compiler can convert the NullKey to a const NullKey &, why
can't it
do the same for SortOrder<T>? They are parallel cases, except that
SortOrder is templated.
Furthermore, both the INTERNAL COMPILER ERROR and the conversion error
can
be alleviated by moving the function's implementation inline into the
class
declaration as shown in Figure 2:

Figure 2: Error-free Code:
----------------------------------------------------------------------------------------------------------------------------

#include <memory>
class Key { };

class NullKey : public Key { };
class SortList { };

template <typename T> class SortOrder : public SortList {
public:
SortOrder() { }
};
class obj { typedef NullKey KeyType; };
class PersistenceManager {
//public:
// PersistenceManager() { }
public:
template <typename T> void loadSet(const Key &key = NullKey(),
const SortOrder<T>
&sort =
SortOrder<T>())//;
{ }
};

/*template <typename T>
void PersistenceManager::loadSet(const Key &key,
const SortOrder<T> &sort) {

}*/

void main() {
PersistenceManager pm;
pm.loadSet<obj>();
}

----------------------------------------------------------------------------------------------------------------------------

Any explanations to this erratic behavior are appreciated.

Thanks again.

John
================================================

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Nov 17 '05 #1
5 1649
In article <53**************************@posting.google.com >, dilip
ranganathan <rd*****@gmail.com> writes
void main() {
PersistenceManager pm;
pm.loadSet<obj>();
}

----------------------------------------------------------------------------------------------------------------------------

Any explanations to this erratic behavior are appreciated.


I think your real problem is probably a compiler one, but you also have
an error that all the compilers I have tried identify; main returns int.
Once a compiler has accepted void main() it is free to do anything it
likes because it is no longer in conforming C++ mode.
--
Francis Glassborow ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Nov 17 '05 #2
Hi all,
Thank you for the response. We've managed to capture a small snippet
of
code that generates the Internal compiler error. It is as follows:


[snip]

Hard to follow, so I stripped it a little bit:
// ********** CODE START **************
template <typename T>
class SortOrder {};

class PersistenceManager
{
public:
//PersistenceManager() { } // (1)
template <typename T>
void loadSet(const SortOrder<T> &sort = SortOrder<T>() ); // (2)
};

template <typename T> inline
void PersistenceManager::loadSet(const SortOrder<T> &sort) {} // (3)

int main()
{
PersistenceManager pm;
pm.loadSet<int>();

return 0;
}
// ********** CODE END **************

-This code here is still bailing out with internal compiler error.

-Uncommenting (1) results in:
error C2514: 'SortOrder<T>' : class has no constructors
funny :)

-moving the default arguments from (2) to (3) - voilà, it compiles
(I have to look in the standard)
same with or without (1)

Regards,
Patrick

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Nov 17 '05 #3
Ups sorry, next post.

I was able to strip even further still getting an internal compiler error:
template <typename T> class CFoo {};

template <typename T> void foo( CFoo<T> = CFoo<T>() );
template <typename T> void foo( CFoo<T> ) {}; // <----watch this semicolon

int main()
{
foo<int>();
return 0;
}

removing the semicolon results in a differnt error message (LOL):
'CFoo<T>' : class has no constructors
which I mentioned in the other posting.

putting the default argument in the function body works fine (g++ refuses
this), as well as simple overloading. The first case should not work in my
opinion regarding:
"8.3.6 Default arguments
4
For non-template functions, default arguments can be added in later
declarations of a function in the same scope."
Hmm, not 100% but nearly. Seems MS is wrong.

Another interessting cite (obviously more important):
"14.7.1 Implicit instantiation
11
If a function template f is called in a way that requires a default argument
expression to be used, the dependant names are looked up, the semantics
constraints are checked, and the instantiation of any template used in the
default argument expression is done as if the default argument expression
had been an expression used in a function template specialization with the
same scope, the same template parameters and the same access as that of the
function template f used at that point. This analysis is called default
argument instantiation. The instantiated default argument is then used as
the argument of f."

what means IMO that MSVC has a small bug.

That would mean for the OP, if there are no doubts, put the function inline
inside the class and you are fine with most of the compilers.

Regards,
Patrick

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

Nov 17 '05 #4
>Can you submit it as a bug report against VS2005 B1 at:

http://lab.msdn.microsoft.com/produc...k/default.aspx


.... and if you do (please do, or let me know you can't), can you post
the link to the report back here and I'll add a vote to it.

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

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Nov 17 '05 #5
Since there's no sign that anyone has bugged it against VS2005, I've
done it:

http://lab.msdn.microsoft.com/produc...0-338b70a60cd8

Dave

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

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

Similar topics

0
by: sks_cpp | last post by:
I am trying to wrap the map iterator for keys and values. However, I seem to run into problems with the values for const_iterator - it works for all other combinations. Below I list my code and...
19
by: Alf P. Steinbach | last post by:
// As usual the error message directs one to the report the bug. // // And as usual there is absolutely no way to do so without paying for // the privilege... // // Or using three or four hours...
11
by: Alf P. Steinbach | last post by:
// As usual the error message directs one to the report the bug. // // And as usual there is absolutely no way to do so without paying for // the privilege... // // Or using three or four hours...
7
by: Matthew Del Buono | last post by:
Don't try to solve the problem. I've found a way -- around or fixing it. I'm just curious as to whether this is Microsoft's problem in their compiler or if there's a standard saying this is to be...
19
by: Martin Oddman | last post by:
Hi, I have a compiling problem. Please take a look at the code below. I have an application that is built upon three tiers: one data tier (Foo.DataManager), one business tier (Foo.Kernel) and...
2
by: Michael Stembera | last post by:
Here is a very simple piece of code to repro this bug. template<typename T, int N> inline bool foo( void ) { return true; } template<typename T> inline bool foo<T, 1>( void ) { return...
2
by: Itjalve | last post by:
This gives me a fatal error. I'm using .NET VC7.1 and made a win32 consol app, I have no problems with VC6. Debug build. I have removed nearly all my code this is whats left. From the beginning...
1
by: Madhu Gopinathan | last post by:
Hi, I am getting the following Internal compiler error : fatal error C1001: INTERNAL COMPILER ERROR (compiler file 'msc1.cpp', line 2701) as detailed below in VC 7.0 while using compiling...
9
by: Christof Warlich | last post by:
Hi, consider this: template<typename Tclass X { public: void doSomething(T t); }; int main(void) { X<intx;
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.