c++ template custom warning -
i'm working c++11 , have code equivalent to
template<typename t1, typename t2> auto add_func( const t1& lhs, const t2& rhs ) { return lhs + rhs; } when compile code using float , int t1 , t2 respectively warnings mentioning conversion might cause loss of data, natural.
my problem every instance of warning point line return lhs + rhs; makes warning pretty useless.
is there way (ideally portable way) re-throw these warning function called instead of inside template?
i'm working visual studio 2012 portable way preferable
edit:
to more clear: know warning correct , caused misuse of code, issue compiler find me places such misuse done. right now, if warning appears, have validate hand each call add_func, not seem maintainable me.
i hope makes more sense now
hooking compiler's warning system seems non-starter me. instead, seems need find more information warning.
i assume building inside of visual studio. if so, switch error list output window , should see following:
1>add_fun.cpp(31): warning c4244: 'return' : conversion 'const float' 'int', possible loss of data 1> add_fun.cpp(38) : see reference function template instantiation 't1 add_func<int,float>(const t1 &,const t2 &)' being compiled 1> 1> [ 1> t1=int, 1> t2=float 1> ] the operative line here "add_fun.cpp(38) : see reference function template instantiation", tell template being instantiated.
this visual c++-specific, compilers should include similar information in full error test.
Comments
Post a Comment