Boost logo

Boost :

From: Reece Dunn (msclrhd_at_[hidden])
Date: 2004-01-01 16:23:23


Kris Braun wrote:

>When compiling a lexical_cast< int >( foo ) call using MSVC 7.1 with /W4, I
>get a
>C4701 "unreferenced variable" warning. This is because the compiler doesn't
>know that
>the throw_exception function never returns. This warning can be fixed by
>adding
>"__declspec( noreturn )" before "void throw_exception". I would generate a
>patch,
>but I'm unsure how long noreturn has been supported by the compiler, so I
>don't know what kind of conditional to use.

I get 3 types of warnings:

[1] C4511: copy constructor could not be generated; C4512 assignment
operator could not be generated
   at lexical_cast.hpp(181)

This is fixample by replacing line 125 with:
+ class lexical_stream: public boost::noncopyable
- class lexical_stream

and adding
+ #include <boost/noncopyable.hpp>
at the top of the file.

[2] C4701: local variable 'result' may be used without having been
initialized
   at lexical_cast.hpp(191)

This is the warning I think you are referring to. I don't understand your
fix -- adding __declspec(noreturn) to the throw_exception function does
nothing. The warning is referring to the line:
   Target result;
where the variable result has not been given a value.
   Target result = Target();
will remove the warning (since Target result(); results in a function
decleration, not variable initialization!)

[3] C4127: conditional expression is constant
   at lexical_cast.hpp(131)
   at lexical_cast.hpp(133)

The only way around this one is to wrap the lines around the following:

#if defined(BOOST_MSVC)
# pragma warning( push )
# pragma warning( disable : 4127 ) // conditional expression is constant
#endif

   // ...

#if defined(BOOST_MSVC)
# pragma warning( pop )
#endif

HTH,
Reece

_________________________________________________________________
Send a funky Messenger Christmas card http://www.msn.co.uk/christmascard


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