C++/CLI: "Equals" as enum class member causes C1060

P

Phil Davidson

/*
(Posted to microsoft.public.dotnet.languages.vc)

In C++/CLI under Visual Studio 2005, creating an "enum class" member
called "Equals" can cause compiler error C1060 (out of memory) and C1063
(internal error). See the following example program, a CLR console app.

Of course the obvious workaround is to refrain from using "Equals". But
does that really violate the specification of the language or the CLR?
And can the compiler be changed to at least give an explicit warning,
and not slow to a snail's pace?

phil -at- ivorycc.com
*/

#include "stdafx.h"

using namespace System;

namespace Problem {
// It's the Equals member that makes us vulnerable to
// compiler errors C1060 and C1063 below.
public enum class Symbol { Equals, GreaterThan, LessThan };

ref class cl {
public:
static bool IsGreater(Symbol^ sym) {

// The following statement causes compiler errors C1060
// and C1063:
// if (sym->Equals(Symbol::GreaterThan))

if (sym == Symbol::GreaterThan) // This statement never
// reports equality.
{
return true;
}
return false;
}
};
};

int main(array<System::String ^> ^args)
{
bool bResult1 =
Problem::cl::IsGreater(Problem::Symbol::GreaterThan);
Console::WriteLine(L"bResult1 is " + bResult1 +
" and should be True");

bool bResult2 = Problem::cl::IsGreater(Problem::Symbol::LessThan);
Console::WriteLineL"bResult2 is " + bResult2 +
" and should be False");

Console::WriteLine(L"Press Enter to continue");
Console::ReadLine();

return 0;
}
 
C

Carl Daniel [VC++ MVP]

Phil Davidson said:
/*
(Posted to microsoft.public.dotnet.languages.vc)

In C++/CLI under Visual Studio 2005, creating an "enum class" member
called "Equals" can cause compiler error C1060 (out of memory) and C1063
(internal error). See the following example program, a CLR console app.

Of course the obvious workaround is to refrain from using "Equals". But
does that really violate the specification of the language or the CLR?
And can the compiler be changed to at least give an explicit warning,
and not slow to a snail's pace?

I'd suggest posting a bug report for this - anything that causes unbounded
recursion in the compiler (which is likely what happened) is definitely a
bug, regardless of the language spec.

http://connect.microsoft.com/feedback/default.aspx?SiteID=210

-cd
 
B

Ben Voigt

Phil Davidson said:
/*
(Posted to microsoft.public.dotnet.languages.vc)

In C++/CLI under Visual Studio 2005, creating an "enum class" member
called "Equals" can cause compiler error C1060 (out of memory) and C1063
(internal error). See the following example program, a CLR console app.

Of course the obvious workaround is to refrain from using "Equals". But
does that really violate the specification of the language or the CLR?
And can the compiler be changed to at least give an explicit warning,
and not slow to a snail's pace?

phil -at- ivorycc.com
*/

#include "stdafx.h"

using namespace System;

namespace Problem {
// It's the Equals member that makes us vulnerable to
// compiler errors C1060 and C1063 below.
public enum class Symbol { Equals, GreaterThan, LessThan };

ref class cl {
public:
static bool IsGreater(Symbol^ sym) {

Internal compiler error should be reported to MS like Carl said.

With an eye toward fixing your code, though, an enum class is a value type,
and therefore you can, and usually should, use it without the tracking
reference (^).
 

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