variant warnings?

Does Boost.Variant require certain warnings to be disabled? The following program generates a warning for me with VC9: COMPILER INPUT: #include <boost/variant.hpp> #include <iostream> struct vis : public boost::static_visitor<> { void operator()( int & ) const { std::cout << "int" << std::endl; } void operator()( std::string & ) const { std::cout << "string" << std::endl; } }; int main( int, char * ) { boost::variant< int, std::string > v; boost::apply_visitor( vis(), v ); return 0; } COMPILER OUTPUT: 1>Compiling... 1>variant_basic.cpp 1>J:\work\ext\boost_ext\boost/variant/variant.hpp(894) : warning C4512: 'boost::detail::variant::invoke_visitor<Visitor>' : assignment operator could not be generated 1> with 1> [ 1> Visitor=const vis 1> ] 1> J:\work\ext\boost_ext\boost/variant/variant.hpp(1771) : see reference to class template instantiation 'boost::detail::variant::invoke_visitor<Visitor>' being compiled 1> with 1> [ 1> Visitor=const vis 1> ] 1> J:\work\ext\boost_ext\boost/variant/detail/apply_visitor_unary.hpp(72) : see reference to function template instantiation 'void boost::variant<T0_,T1>::apply_visitor<const Visitor>(Visitor &)' being compiled 1> with 1> [ 1> T0_=int, 1> T1=std::string, 1> Visitor=vis 1> ] 1> ..\indep\variant_basic.cpp(11) : see reference to function template instantiation 'void boost::apply_visitor<vis,boost::variant<T0_,T1>>(const Visitor &,Visitable &)' being compiled 1> with 1> [ 1> T0_=int, 1> T1=std::string, 1> Visitor=vis, 1> Visitable=boost::variant<int,std::string> 1> ]

AMDG hfye-wila@spamex.com wrote:
Does Boost.Variant require certain warnings to be disabled? The following program generates a warning for me with VC9:
Warning 4512 is almost always harmless. It's usually caused by structs containing reference members. You're best off disabling it. In Christ, Steven Watanabe

Does Boost.Variant require certain warnings to be disabled? The following
As recommended (thanks Steve!), I have disabled VC9's C4512 warning to get a canonical Boost.Variant example to compile (in VC9) without warnings: #pragma warning( push ) #pragma warning( disable : 4512 ) #include <boost/variant.hpp> #pragma warning( pop ) #include <iostream> using namespace std; struct vis : public boost::static_visitor<> { void operator()( int & ) const { cout << "int" << endl; } void operator()( string & ) const { cout << "string" << endl; } }; int main( int, char * ) { boost::variant< int, string > v; boost::apply_visitor( vis(), v ); return 0; } *If* this warning is truly harmless, should this be considered a bug in Boost.Variant? Shouldn't Boost.Variant disable benign warnings in a compiler-independent way? Or at least shouldn't the Boost.Variant docs be updated? Or is this warning part of Boost.Variant's design? If so is there any way I can change my code above to compile without warnings other without explicitly suppressing warnings? Any Boost.Variant authors/maintainers care to comment? John Fearnside -----Original Message----- AMDG hfye-wila@spamex.com wrote: program generates a warning for me with VC9:
Warning 4512 is almost always harmless. It's usually caused by structs containing reference members. You're best off disabling it. In Christ, Steven Watanabe

AMDG hfye-wila@spamex.com wrote:
*If* this warning is truly harmless, should this be considered a bug in Boost.Variant?
I consider this a low priority bug.
Shouldn't Boost.Variant disable benign warnings in a compiler-independent way?
This warning is Visual Studio specific. In Christ, Steven Watanabe

I agree with Steve that the C4512 warning is a low-priority bug: it is easily worked around and it's only a level 4 warning. But, I must not be understanding Boost.Variant (1.35.1) because the following simple example generates several other VC9 warnings: C4345 (level 2) and C4100 (level 4): #include <boost/config.hpp> #ifdef BOOST_MSVC # pragma warning( push ) # pragma warning( disable : 4512 ) #endif #include <boost/variant.hpp> #ifdef BOOST_MSVC # pragma warning( pop ) #endif #include <iostream> using namespace std; struct C1 {}; struct C2 {}; struct vis : public boost::static_visitor<> { void operator()( C1 & ) const { cout << "C1" << endl; } void operator()( C2 & ) const { cout << "C2" << endl; } }; int main( int, char * ) { boost::variant< C1, C2 > v; boost::apply_visitor( vis(), v ); return 0; } Disabling these in the manner above works but I'm hoping one of its authors/maintainers can comment on intended usage of Boost.Variant with VC9? I'm wary of disabling each warning I encounter. That makes it difficult for me to know which warnings are known to be harmless and which indicate errors in my code. BTW: By "compiler-independent way" I mean using <boost/config.hpp> macros to wrap compiler-specific pragmas (as above). John Fearnside -----Original Message----- AMDG hfye-wila@spamex.com wrote:
*If* this warning is truly harmless, should this be considered a bug in Boost.Variant?
I consider this a low priority bug.
Shouldn't Boost.Variant disable benign warnings in a compiler-independent way?
This warning is Visual Studio specific. In Christ, Steven Watanabe _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

AMDG hfye-wila@spamex.com wrote:
C4345 is a backwards compatibility warning. The compiler is issuing a warning because it treats new int() correctly using value-initialization! You can ignore this unless you care about compatibility with VC6. C4100 (unused variable) is a legitimate warning, but it fires for this: tempate<class T> void destory(T& t) { t.~T(); } even though t is used. It should be safe to disable it for Boost headers. In Christ, Steven Watanabe
participants (2)
-
hfye-wila@spamex.com
-
Steven Watanabe