简体   繁体   中英

Suppressing warning C4996: why not working?

: I am playing around with spline fitting module of Eigen library.:我正在使用 Eigen 库的样条拟合模块。 The fit works nice enough, but I do get some warnings (in Visual Studio 2013).

: Why am I able to disable some warnings whereas other persist even after they should have been supressed?:为什么我能够禁用某些警告,而其他警告即使在它们应该被抑制之后仍然存在?

:
The "well behaved" warning I get is

warning C4714: function 'const Eigen::Matrix Eigen::DenseBase::eval(void) const' marked as __forceinline not inlined

After a bit of research I learned that this indeed comes with using eigen code. As I prefer not to produce warnings,

#pragma warning(disable : 4714)

works nicely to suppress it.

The "naughty" warning is

warning C4996: 'std::_Partial_sum2': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'
originating in ChordLengths function of eigen. This one, however, does not let itself be suppressed with
#pragma warning(disable : 4996) 
(and I am quite sure there is no problem in spacing or such as the above 4714 works nicely), neither does work

#define _SCL_SECURE_NO_WARNINGS \n#define _CRT_SECURE_NO_WARNINGS 

or anything from this thread or all the other similar threads.


Do I overlook something obvious?

For now I 'solved' the issue in a rather ugly way: I have rewritten the ChordLengths function into my code replacing the problematic line

std::partial_sum(chord_lengths.data(), chord_lengths.data()+n,chord_lengths.data()); 

with a version of my own. I dislike this approach, but it solves the problem. Still, I would prefer to understand why nothing I tried to suppress the warning worked.

Bonus: How do I actually supress the warning?

Solved thanks to WhozCraig

Solution: The warning suppression needs to be placed before any includes, as some of them apparently include eigen too.

@Mori (Sorry, it seems I have too few reputation points to add a comment!)

For me, having trouble with sprintf (etc.) warnings, #pragma warning(disable : 4996) needs to be placed after #include "stdafx.h"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM