M
Matthew Del Buono
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 true (not necessarily an internal
compiler error, but still an error)
This may just a bit OT, but I decided to post it here instead of Microsoft
because my question is more directed towards standards...
Of course, any other day I would have been on my Linux computer with GCC,
but today I didn't have that option. I have the following function. I tried
to standarize it (CList => vector) but just about every function is
different. Basically, type T and A are about the same (the type of the
vector). The functions are somewhat self explanatory... A POSITION is
basically an index; not exactly, but for our purposes we will say that it
is...
template <class T, class A>
CList<T, A>& copyList(CList<T, A>& mod, const CList<T, A>& orig)
{
POSITION curpos;
// Make sure mod is empty
while (!mod.IsEmpty())
mod.RemoveHead();
#pragma warning(disable:4706)
if (!(curpos = orig.GetHeadPosition()))
return mod;
else
mod.AddHead(const_cast<CList<T, A>&>(orig).GetAt(curpos));
orig.GetNext(curpos);
while (curpos)
{
mod.AddHead(const_cast<CList<T, A>&>(orig).GetAt(curpos));
orig.GetNext(curpos);
};
// Do one more...
mod.AddHead(const_cast<CList<T, A>&>(orig).GetAt(curpos));
orig.GetNext(curpos);
return mod;
}
I get the following error:
fatal error C1001: INTERNAL COMPILER ERROR
Trying to compile with option /Bd (which is supposed to help you locate
where the internal error occurs) ends up crashing the compiler, instead of
yielding a C1001. I've found out that the problem lies in the #pragma
warning(disable:4706).
By placing the #pragma warning(disable:4706) outside of the template, the
template works fine. Is there a practical reason for this? Or is it just one
of the many bugs that M$ produces every year...
Microsoft Visual C++ 6.0 using MFC
------------------------------------------
On an unrelated note, actually, I have one more question about ANSI
standards. In the same block of code, there is a messy line (which you
probably all yelled at when you read it) which reads
mod.AddHead(const_cast<CList<T, A>&>(orig).GetAt(curpos));
(similar ones follow)
Of course nobody likes to use a const_cast. The problem was that I was
getting a warning, stating that a non-standard extention was being used. I
try to make my programs as standard as possible. When compiling the (I
thought) pratical line:
mod.AddHead(orig.GetAt(curpos));
I got the following warning:
c:\program files\microsoft visual
studio\myprojects\digitaldarkroom\stdafx.h(53) : warning C4239: nonstandard
extension used : 'argument' : conversion from 'class CFilter' to 'class
CFilter &'
A reference that is not to 'const' cannot be bound to a non-lvalue
That line struck me: "A reference that is not to 'const' cannot be bound to
a non-lvalue." Why exactly is that? It seems like it's just another
compilcation in the midst of C++... I don't see any practical purpose for
not being able to bind a non-lvalue to reference to a non-const. In fact, it
almost makes more sense. Obviously the line a = 4 is legal, but taking out
the reference, it is exactly the same thing. A non-const (but not a
reference) is being bound by a non-lvalue (obviously you can't write 4 = a).
Thus, I was forced to "de-const" the paramter to make it standardized.
Surely, the line
mod.AddHead(const_cast<CList<T, A>&>(orig).GetAt(curpos));
is much uglier, but at least it's standardized. Certainly nobody ever likes
to run with const_casts in their programs. It's almost as bad as a
reinterpret_cast and completely oversteps the point of a type-strict
language. Of course there are other ways around it, too, but this was the
easiest to code, in my opinion.
So why exactly is it there? Makes absolutely no sense to me...
-- Matt
just curious as to whether this is Microsoft's problem in their compiler or
if there's a standard saying this is to be true (not necessarily an internal
compiler error, but still an error)
This may just a bit OT, but I decided to post it here instead of Microsoft
because my question is more directed towards standards...
Of course, any other day I would have been on my Linux computer with GCC,
but today I didn't have that option. I have the following function. I tried
to standarize it (CList => vector) but just about every function is
different. Basically, type T and A are about the same (the type of the
vector). The functions are somewhat self explanatory... A POSITION is
basically an index; not exactly, but for our purposes we will say that it
is...
template <class T, class A>
CList<T, A>& copyList(CList<T, A>& mod, const CList<T, A>& orig)
{
POSITION curpos;
// Make sure mod is empty
while (!mod.IsEmpty())
mod.RemoveHead();
#pragma warning(disable:4706)
if (!(curpos = orig.GetHeadPosition()))
return mod;
else
mod.AddHead(const_cast<CList<T, A>&>(orig).GetAt(curpos));
orig.GetNext(curpos);
while (curpos)
{
mod.AddHead(const_cast<CList<T, A>&>(orig).GetAt(curpos));
orig.GetNext(curpos);
};
// Do one more...
mod.AddHead(const_cast<CList<T, A>&>(orig).GetAt(curpos));
orig.GetNext(curpos);
return mod;
}
I get the following error:
fatal error C1001: INTERNAL COMPILER ERROR
Trying to compile with option /Bd (which is supposed to help you locate
where the internal error occurs) ends up crashing the compiler, instead of
yielding a C1001. I've found out that the problem lies in the #pragma
warning(disable:4706).
By placing the #pragma warning(disable:4706) outside of the template, the
template works fine. Is there a practical reason for this? Or is it just one
of the many bugs that M$ produces every year...
Microsoft Visual C++ 6.0 using MFC
------------------------------------------
On an unrelated note, actually, I have one more question about ANSI
standards. In the same block of code, there is a messy line (which you
probably all yelled at when you read it) which reads
mod.AddHead(const_cast<CList<T, A>&>(orig).GetAt(curpos));
(similar ones follow)
Of course nobody likes to use a const_cast. The problem was that I was
getting a warning, stating that a non-standard extention was being used. I
try to make my programs as standard as possible. When compiling the (I
thought) pratical line:
mod.AddHead(orig.GetAt(curpos));
I got the following warning:
c:\program files\microsoft visual
studio\myprojects\digitaldarkroom\stdafx.h(53) : warning C4239: nonstandard
extension used : 'argument' : conversion from 'class CFilter' to 'class
CFilter &'
A reference that is not to 'const' cannot be bound to a non-lvalue
That line struck me: "A reference that is not to 'const' cannot be bound to
a non-lvalue." Why exactly is that? It seems like it's just another
compilcation in the midst of C++... I don't see any practical purpose for
not being able to bind a non-lvalue to reference to a non-const. In fact, it
almost makes more sense. Obviously the line a = 4 is legal, but taking out
the reference, it is exactly the same thing. A non-const (but not a
reference) is being bound by a non-lvalue (obviously you can't write 4 = a).
Thus, I was forced to "de-const" the paramter to make it standardized.
Surely, the line
mod.AddHead(const_cast<CList<T, A>&>(orig).GetAt(curpos));
is much uglier, but at least it's standardized. Certainly nobody ever likes
to run with const_casts in their programs. It's almost as bad as a
reinterpret_cast and completely oversteps the point of a type-strict
language. Of course there are other ways around it, too, but this was the
easiest to code, in my opinion.
So why exactly is it there? Makes absolutely no sense to me...
-- Matt