Subject: Re: [boost] suggestion on assertion macros
From: Roland Bock (rbock_at_[hidden])
Date: 2010-03-16 03:45:06


Emil Dotchevski wrote:
> On Tue, Mar 16, 2010 at 12:05 AM, Roland Bock <rbock_at_[hidden]> wrote:
>
>> So maybe (I still want to get rid of those warnings without disabling them),
>> it would be better to define a companion to assert, like this:
>>
>> #include <cassert>
>>
>> #ifdef NDEBUG
>> #define DEBUG_CODE(some_code)
>> #else
>> #define DEBUG_CODE(some_code) some_code
>> #endif
>>
>> int main()
>> {
>> DEBUG_CODE(int i = 0;)
>> assert(i);
>> }
>>
>> What do you think?
>>
>
> I think that the solution is to disable such warnings in release
> builds. They serve no purpose other than to tell you that assert did
> what it was supposed to do in release.
>
I'll take that into consideration...
> MSVC has a similar warning, the one that says "removed unreachable
> code" which tells you that the optimizer deadstripped code that could
> not be executed anyway. How would you deal with that warning, add
> casts until the optimizer is sufficiently confused? :)
>
There certainly are warnings which serve no other purposes than
bolstering the ego of the respective compiler/optimizer developer :-)

IMHO, warnings about unused variables/parameters are not usually among
them, but yes, maybe they are in case of NDEBUG being turned on.