Home Dashboard Directory Help
Search

#pragma warning( disable : 4996) - does not work by Mariusz102102


Status: 

Closed
 as By Design Help for as By Design


1
0
Sign in
to vote
Type: Bug
ID: 561095
Opened: 5/24/2010 8:30:45 AM
Access Restriction: Public
1
Workaround(s)
view
1
User(s) can reproduce this bug

Description

VisualStudioExpress 2010 solution attached
It is regression compare to VisualStudioExpress 2008
Details
Sign in to post a comment.
Posted by Microsoft on 6/22/2010 at 1:40 PM
Hi Mariusz102102,
To disable the warning in that particular function there is a workaround available. In your case the warning is not being issued by compiler.Its being issued on template instantiation in usage of std::transform method. This issue is by design.

You will have to transform the result array or pointer into unchecked array iterator and pass it to the function.

You need to do following changes in the function

#include <iterator>
int _tmain(int /*argc*/, _TCHAR* /*argv*/[])
{
    int a [] = {1, 2, 3};
    int* b = new int[3];
    std::transform(a, a + 3, stdext::make_unchecked_array_iterator(b), [](int n)-> int { return n;}); // C4996
    delete b;
    return 0;
}

This should disable the warning for that particular function.Let me know if this does not help you. You can reach me at rsarwar@microsoft.com for any questions directly.

Thanks
Rashid Sarwar
Posted by Mariusz102102 on 5/31/2010 at 10:44 AM
I am so sorry but I think that this is not expected behaviour.
Below some arguments:
1. It is regression compare to VS2008
2. I would like disable this warning only in particular function. i.e.
#pragma warning( push )
#pragma warning( disable : 4996 )
void f()
{
    int a [] = {1, 2, 3};
    int* b = new int[3];
    std::transform(a, a + 3, b, [](int n)-> int { return n;}); // C4996
    delete b;
}
#pragma warning( pop )
Proposed solution works per project or file:
Project Properties--> Configuration Properties-->C/C++-->Command Line-->Additional Options
Could you send me solution disabling warning per function?
3. From pragma documentation: disable- Do not issue the specified warning message(s).
4. Below workarounds works. So #pragma warning( disable : 4996) can disable this warning. But below workarounds disable warnings for all header....

#pragma warning( push )
#pragma warning( disable : 4996)
#include <algorithm>
#pragma warning( pop )

Posted by Microsoft on 5/26/2010 at 7:42 PM
Hi Mariusz102102 ,
Thanks for reporting the issue. This is the expected behaviour of the product. You need to define following macro under Project Properties--> Configuration Properties-->C/C++-->Command Line-->Additional Options

-D_SCL_SECURE_NO_WARNINGS

You will get rid of the build issues. If you have any other issues kindly let us know.Thanks for playing with our product.

Regards
Rashid Sarwar
Windows C++ Team
Posted by Microsoft on 5/24/2010 at 10:22 PM
Thank you for reporting this issue.
We are routing 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.
Posted by Microsoft on 5/24/2010 at 5:04 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
Posted by Viorel_ on 5/24/2010 at 10:59 PM
Move the #pragma to stdafx.h file and put it before the #include directives related to STL.
File Name Submitted By Submitted On File Size  
PragmaWarning.zip 5/24/2010 4 KB