Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppressing warning C4996: why not working?

Context: I am playing around with spline fitting module of Eigen library. The fit works nice enough, but I do get some warnings (in Visual Studio 2013).

The question: Why am I able to disable some warnings whereas other persist even after they should have been supressed?

More context:
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
#define _CRT_SECURE_NO_WARNINGS

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


Why is that? 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?

like image 303
Mori Avatar asked May 14 '19 14:05

Mori


People also ask

How do I ignore a warning in C++?

To disable a set of warnings for a given piece of code, you have to start with a “push” pre-processor instruction, then with a disabling instruction for each of the warning you want to suppress, and finish with a “pop” pre-processor instruction.

How do you suppress warnings in VS code?

Choose Build, and go to the Errors and warnings subsection. In the Suppress warnings or Suppress specific warnings box, specify the error codes of the warnings that you want to suppress, separated by semicolons.


1 Answers

Solved thanks to WhozCraig

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

like image 77
Mori Avatar answered Oct 18 '22 11:10

Mori