Boost logo

Boost :

From: John Maddock (john_at_[hidden])
Date: 2007-02-14 07:28:20


Michael Marcin wrote:
> Paul A Bristow wrote:
>>> From experience producing code that compiles cleanly MSVC 8.0 at
>>> level 4,
>>
>> may I suggest that none of these are helpful warnings and should be
>> suppressed:
>>
>> # pragma warning(disable: 4127) // conditional expression is
>> constant
>
> Really?
>
> I would tend to take that as a sign that the code in question could be
> written differently to avoid the conditional, perhaps using SFINAE
> overloads if its controlled by a template parameter's value.

Depends, the main cases I have are things like:

if(std::numeric_limits<T>::has_infinity)
{
  // case A
}
else
{
  // case B
}

Where cases A and B are tiny one-liners that are a small part of the overall
function. You could factor it out, but it makes the code more rather than
less obfuscated.

My gut feeling is that sometimes it's just not worth the hassle to refactor
code like this, even though I was once rather obsessive about doing so!

I also have a few cases where there is something like:

if(foo<T>() > 0)

where sometimes foo<T>() gets inline-expanded to an integral constant
expression, and sometimes not (depends on T), so the warning may only appear
for certain compilers, with certain types T, for certain optimisation
settings :-(

John.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk