A level 4 warning shown only in release mode, not in debug mode

  • Thread starter Thread starter B.
  • Start date Start date
B

B.

We just recently move to code from VC++6 to VC++.NET 2005 and upgrade
the warning level from 3 to 4. In debug mode, we compile the
application with no warning no error, but when I build it in release
mode, there are quite few C4701 warnings and some C2679 errors. Note
that some of warning and error happens in debug mode as well and was
fixed. Anyone know why some of warning and error happens only in
release mode?
 
B. said:
We just recently move to code from VC++6 to VC++.NET 2005 and upgrade
the warning level from 3 to 4. In debug mode, we compile the
application with no warning no error, but when I build it in release
mode, there are quite few C4701 warnings and some C2679 errors. Note
that some of warning and error happens in debug mode as well and was
fixed. Anyone know why some of warning and error happens only in
release mode?

Because those warnings are emitted by the optimizer, which is disabled
during debug builds. These are typically warnings that require the compiler
to do expensive data flow analysis that isn't done if the optimizer is
disabled.

-cd
 
Carl said:
Because those warnings are emitted by the optimizer, which is disabled
during debug builds. These are typically warnings that require the compiler
to do expensive data flow analysis that isn't done if the optimizer is
disabled.

-cd

Thanks Carl, it is the same reason for error? And as I mentioned, most
of same warnings are actually caught in debug mode, just few are only
happens in release mode. Any clue?

B.
 
B. said:
Thanks Carl, it is the same reason for error? And as I mentioned, most
of same warnings are actually caught in debug mode, just few are only
happens in release mode. Any clue?

OK, I had to go look up what a C2679 error is (it helps if you post actual
error messages - few people have them memorized!).

Anyway... No, it doesn't make sense that a body of code would have a C2679
error in a release build but not in a debug build. I'd have to guess that
there's some preprocessor voodoo going on that's actually leaving out some
vital code in the release build. I'd try to construct a minimal program
that reproduces that C2679 in release builds but not debug builds. Along
the way, you'll likely figure out what's really wrong, or you'll have a nice
repro case to submit with a bug report, since barring any other explaination
(like the #ifdef scenario), that definitely sounds like a compiler bug.

The C4701 error makes perfect sense as a release-only error since detection
of uninitialized variables does in fact require data flow analysis.

-cd
 
Carl said:
OK, I had to go look up what a C2679 error is (it helps if you post actual
error messages - few people have them memorized!).

Anyway... No, it doesn't make sense that a body of code would have a C2679
error in a release build but not in a debug build. I'd have to guess that
there's some preprocessor voodoo going on that's actually leaving out some
vital code in the release build. I'd try to construct a minimal program
that reproduces that C2679 in release builds but not debug builds. Along
the way, you'll likely figure out what's really wrong, or you'll have a nice
repro case to submit with a bug report, since barring any other explaination
(like the #ifdef scenario), that definitely sounds like a compiler bug.

The C4701 error makes perfect sense as a release-only error since detection
of uninitialized variables does in fact require data flow analysis.

-cd

Hi Carl,

I should post the code for the C2679 error:
list<SomeObject>::iterator iter = NULL;
....... // do something
if (iter ==NULL)
......

Basically, we try to assign NULL to an list's iterator and compare NULL
with the iterator, both places produce a C2679 error in release mode,
but not in debug mode. error message:
error C2679: binary '=' : no operator found which takes a right-hand
operand of type 'int' (or there is no acceptable conversion)
C:\Program Files\Microsoft Visual Studio 8\VC\include\list(421): could
be 'std::list<_Ty>::_Iterator<_Secure_validation>
&std::list<_Ty>::_Iterator<_Secure_validation>::operator =(const
std::list<_Ty>::_Iterator<_Secure_validation> &)'

I am pretty sure that it is not related to preprocessor, and I can fix
it, but just don't know why the error is only in release mode.
 
B. said:
Hi Carl,

I should post the code for the C2679 error:
list<SomeObject>::iterator iter = NULL;
...... // do something
if (iter ==NULL)
.....

Basically, we try to assign NULL to an list's iterator and compare NULL
with the iterator, both places produce a C2679 error in release mode,
but not in debug mode. error message:
error C2679: binary '=' : no operator found which takes a right-hand
operand of type 'int' (or there is no acceptable conversion)
C:\Program Files\Microsoft Visual Studio 8\VC\include\list(421): could
be 'std::list<_Ty>::_Iterator<_Secure_validation>
&std::list<_Ty>::_Iterator<_Secure_validation>::operator =(const
std::list<_Ty>::_Iterator<_Secure_validation> &)'

I am pretty sure that it is not related to preprocessor, and I can fix
it, but just don't know why the error is only in release mode.

Ah ha!

Actually, it is releated to the preprocessor, but not in your code.

You cannot assign NULL to an interator, nor compare an iterators value to
NULL - whether such expressions "work" is implementation defined (i.e. not
guaranteed by the standard).

You need to re-work your code to not rely on being able to assign null to an
iterator.

-cd
 
Back
Top