VC++: Unable to selectively disable C4505 warnings using #pragma warning

Source: Microsoft Support

RAPID PUBLISHING

RAPID PUBLISHING ARTICLES PROVIDE INFORMATION DIRECTLY FROM WITHIN THE MICROSOFT SUPPORT ORGANIZATION. THE INFORMATION CONTAINED HEREIN IS CREATED IN RESPONSE TO EMERGING OR UNIQUE TOPICS, OR IS INTENDED SUPPLEMENT OTHER KNOWLEDGE BASE INFORMATION.

Action



When using #pragma warning(disable:4505) to disable the warning around a dead function then set it back to default using #pragma warning(default:4505)   or a push/pop, it will set the entire cpp file to default C4505 warnings. 



 //#pragma warning(push)











#pragma warning(disable:4505)











static void test0()











{











}











#pragma warning(default:4505) 











//#pragma warning(pop)









static void test1()











{











}









static void test2()











{











}









int _tmain()











{











      return 0;











}

Result

When setting #pragma warning(default:4505) to reset the warning, it would enable C4505 warning for the entire CPP file even though it was disabled previsously.

Cause

This is by design.  The C4505 warning applies to a region of code not to a specific function.  The warning is actually tested for at the end of the compilation unit so selectively disabling ths warning will not work.



 









Resolution



By design, this C4505 warning cannot be selectively disabled.

DISCLAIMER

MICROSOFT AND/OR ITS SUPPLIERS MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY, RELIABILITY OR ACCURACY OF THE INFORMATION CONTAINED IN THE DOCUMENTS AND RELATED GRAPHICS PUBLISHED ON THIS WEBSITE (THE “MATERIALS”) FOR ANY PURPOSE. THE MATERIALS MAY INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS AND MAY BE REVISED AT ANY TIME WITHOUT NOTICE.


TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, MICROSOFT AND/OR ITS SUPPLIERS DISCLAIM AND EXCLUDE ALL REPRESENTATIONS, WARRANTIES, AND CONDITIONS WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO REPRESENTATIONS, WARRANTIES, OR CONDITIONS OF TITLE, NON INFRINGEMENT, SATISFACTORY CONDITION OR QUALITY, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, WITH RESPECT TO THE MATERIALS.
מאפיינים:

מזהה פריט: 947783 - סקירה אחרונה: 13 במאי 2008 - תיקון: 1

משוב