Reputation: 1
The following code causes in Visual Studio 2015 fatal error C1060: compiler is out of heap space. If I use 64 bit version of compiler It eat more than 25Gb of ram for this sample. Visual Studio 2012 and 2010 works fine. This is a compiler error?
class Test
{
public:
Test() :
m_val1(0),
m_val2(0)
{
}
Test(Test *val1) :
m_val1(val1),
m_val2(0)
{
}
Test(Test *val1, Test *val2) :
m_val1(val1),
m_val2(val2)
{
}
~Test()
{
if (m_val1)
delete m_val1;
if (m_val2)
delete m_val2;
}
private:
Test* m_val1;
Test* m_val2;
};
int main()
{
Test t(new Test(new Test(new Test(new Test(new Test(new Test(new Test(new Test(new Test(
new Test(new Test(new Test),
new Test(new Test(new Test(new Test(new Test(new Test(),
new Test()),
new Test(new Test(),
new Test(new Test(new Test(new Test(new Test(new Test(new Test(new Test(new Test(new Test(new Test(),
new Test())))))))))))
)))))))))))))));
return 0;
}
Upvotes: 0
Views: 969
Reputation: 4808
This is a bug. The minimal code is below.
If the number of functions is small enough, the compiler issues two warnings: main::A a(...prototyped function not called (was a variable definition intended?)
and 'a': unreferenced local variable
; else, on my computer, it hangs.
If you replace the parenthesis with braces, to remove the ambiguity, everything is fine.
int main()
{
class A {};
A a( A( A( A( A( A( A( A( A( A( A( A( A( A( A( A( A( A( A( A( A( A( A( A( ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) );
// fine: A a{ A{ A{ A{ A{ A{ A{ A{ A{ A{ A{ A{ A{ A{ A{ A{ A{ A{ A{ A{ A{ A{ A{ A{} } } } } } } } } } } } } } } } } } } } } } } };
return 0;
}
Upvotes: 0