Bug in VC 7.1

E

Emil Dotchevski

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};

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++>
 
C

Carl Daniel [VC++ MVP]

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
 
C

Carl Daniel [VC++ MVP]

Emil said:
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
 

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