By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,812 Members | 1,665 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,812 IT Pros & Developers. It's quick & easy.

Bug in VC 7.1

P: n/a
This code causes the compiler to allocade a *lot* of memory *very*
fast, and even when I hit ctrl+break it still takes about a minute for
my system to recover and start responding to user input again.

What is more strange is the workarounds that prevent this compiler bug
from occuring.

For example, making the 'l' object a type (by adding a typedef at the
beginning of the last line) inhibits the bug.

Giving a name to the nameless namespace that contains the c1, c2, c3
and c4 classes also inhibits the problem.

So does removing the const modifier of c2 (!) in the last line.

I hope these clues will help fixing the issue. A friend of mine from
Microsoft also tried this code on the new 8.0 compiler and reported
that it causes the same issues.

<c++>

struct nil;

template <class T,class U=nil>
struct cons
{
typedef T head;
typedef U tail;
};

template <class T,class L>
struct cut_list
{
typedef cons<T,typename cut_list<typename L::head,typename
L::tail>::list > list;
};

template <class L>
struct cut_list<nil,L>
{
typedef nil list;
};

template <
class T1=nil,
class T2=nil,
class T3=nil,
class T4=nil,
class T5=nil,
class T6=nil>
struct makelist
{
typedef typename
cut_list<T1,
cons<T2,
cons<T3,
cons<T4,
cons<T5,
cons<T6
> > >::list list;

};

namespace
{
class c1;
class c2;
class c3;
class c4;
}

makelist<c1 const,c2 const,c3 const,c4 const> l;

//Some workarounds that (individually) inhibit the bug (replace the
line above)
//typedef makelist<c1 const,c2 const,c3 const,c4 const> l;
//makelist<c1 const,c2,c3 const,c4 const> l;

</c++>
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
I was unable to reproduce the behavior you describe. After fixing formatting problems introduced by the newsgroup, the code I tried is:

struct nil;

template <class T,class U=nil>
struct cons
{
typedef T head;
typedef U tail;
};

template <class T,class L>
struct cut_list
{
typedef cons<T,typename cut_list<typename L::head,typename L::tail>::list > list;
};

template <class L>
struct cut_list<nil,L>
{
typedef nil list;
};

template <
class T1=nil,
class T2=nil,
class T3=nil,
class T4=nil,
class T5=nil,
class T6=nil>
struct makelist
{
typedef typename
cut_list<T1,
cons<T2,
cons<T3,
cons<T4,
cons<T5,
cons<T6> > > > > > ::list list;
};

namespace
{
class c1;
class c2;
class c3;
class c4;
}

makelist<c1 const,c2 const,c3 const,c4 const> l;

//Some workarounds that (individually) inhibit the bug (replace the line above)
//typedef makelist<c1 const,c2 const,c3 const,c4 const> l;
//makelist<c1 const,c2,c3 const,c4 const> l;
Compiling this with cl -c does nothing unusual. Presumably, something I "fixed" also fixed the problem - perhaps you could post (attach) a file that reproduces the problem, along with the compiler options (or a matcihng .vcproj file) you're using?

-cd
Emil Dotchevski wrote:
This code causes the compiler to allocade a *lot* of memory *very*
fast, and even when I hit ctrl+break it still takes about a minute for
my system to recover and start responding to user input again.

What is more strange is the workarounds that prevent this compiler bug
from occuring.

For example, making the 'l' object a type (by adding a typedef at the
beginning of the last line) inhibits the bug.

Giving a name to the nameless namespace that contains the c1, c2, c3
and c4 classes also inhibits the problem.

So does removing the const modifier of c2 (!) in the last line.

I hope these clues will help fixing the issue. A friend of mine from
Microsoft also tried this code on the new 8.0 compiler and reported
that it causes the same issues.

<c++>

struct nil;

template <class T,class U=nil>
struct cons
{
typedef T head;
typedef U tail;
};

template <class T,class L>
struct cut_list
{
typedef cons<T,typename cut_list<typename L::head,typename
L::tail>::list > list;
};

template <class L>
struct cut_list<nil,L>
{
typedef nil list;
};

template <
class T1=nil,
class T2=nil,
class T3=nil,
class T4=nil,
class T5=nil,
class T6=nil>
struct makelist
{
typedef typename
cut_list<T1,
cons<T2,
cons<T3,
cons<T4,
cons<T5,
cons<T6
>>>>> list list;

};

namespace
{
class c1;
class c2;
class c3;
class c4;
}

makelist<c1 const,c2 const,c3 const,c4 const> l;

//Some workarounds that (individually) inhibit the bug (replace the
line above)
//typedef makelist<c1 const,c2 const,c3 const,c4 const> l;
//makelist<c1 const,c2,c3 const,c4 const> l;

</c++>

Nov 16 '05 #2

P: n/a
Emil Dotchevski wrote:
This code causes the compiler to allocade a *lot* of memory *very*
fast, and even when I hit ctrl+break it still takes about a minute for
my system to recover and start responding to user input again.


Someone from the VC team confirmed to me that this is indeed a bug and it
should be fixed in a future release.

-cd
Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.