Cannot suppress warning in template function - by Allen Barnett

Status : 

  By Design<br /><br />
		The product team believes this item works according to its intended design.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 442051 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 5/5/2009 11:29:49 AM
Access Restriction Public


I have this code to convert a double precision array to single precision:
#include <vector>
#include <algorithm>
std::vector<double> a( 100 );
std::vector<float> b( 100 );
std::copy( a.begin(), a.end(), b.begin() )
This produces the C4244 warning at all warning levels. I cannot figure out to selectively suppress this warning for this line only. /w4244 on the compile line or #pragma warning( disable : 4244 ) before the includes of <vector> and <algorithm> will disable the warning (but just plain /w on the compile line does not disable the warning). Should I not be able to do:
#pragma warning( push )
#pragma warning( disable : 4244 )
std::copy(... )
#pragma warning( pop)
Sign in to post a comment.
Posted by Microsoft on 1/6/2010 at 2:41 AM
To Allen:
Unfortunately, you can only suppress the warning from where it happens.
In your example, you have to put the #pragma around the offending header

To Malcomlm:
#pragma is a preprocessing directive, so normally it isn't aware of language features (like template).
It is true that disable the warning for a specific instantiation of template is useful. We will look at it during the development phase of a future release of Visual C++.
Thanks for your suggestion!

Visual C++ Compiler Team
Posted by MagicMal on 7/12/2009 at 6:59 PM
I think this is not really what anyone would want. In this case of a templated function or class the type is chosen at the point of its use. If the error is related to the use of a specific type, then it is there where the warning should be dealt with, and therefore there is the point the warning should be disabled. Its possible the user might want both abilities - to disable at the point of including the header file (for all cases), or just at the specific usage of the function. One would want to disable all warnings it the warning is never relevant or if there is a problem with the implementation of the templated function. It is important to correctly deal with these warnings, especially with environments which use warnings as errors and have a policy of having no warnings. I understand that this might be thought of as "by design", but the design doesn't really give us what we want - which makes much more sense in this case. If it is not a bug -0 then treated this as an improvement please
Posted by Allen Barnett on 5/12/2009 at 4:08 AM
Is it possible to suppress this warning?
Posted by Microsoft on 5/12/2009 at 12:29 AM
Thanks for your feedback.

This is by-design. The warning happens in the callee (std::copy). So using the pragma around the caller will not suppress the warning.

Visual C++ Compiler Team
Posted by Microsoft on 5/5/2009 at 11:25 PM
Thanks for your feedback.

We are escalating this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.

Thank you,
Visual Studio Product Team