Suppressing warning C4996: why not working?
Asked Answered
M

2

8

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?

Misadvise answered 14/5, 2019 at 14:36 Comment(7)
When defining those warning disablement macros, they were before any inclusion of the eigen headers (such as the first lines of your pch header, or even in the preprocessor macro section of your vcprojx settings/c++/preprocessor project config (option 4 of the linked question)? I only ask because those are the places I'll generally use them, and have never had the problem you seem to be experiencing.Doreendorelia
WhozCraig: first line of the header file, before inclusion of eigen. And it still gives the warning if I copy the problematic partial_sum directly to my code.Misadvise
And you're not using a pch also including eigen (such as typical stdafx.h)? Dropping it in the project-wide proeprocessor config of the vcprojx generally eliminates that potential hole unless the pch has its own preprocessor settings (which wouldn't work that well, so usually not a problem). Odd, if you're tried that as well.Doreendorelia
You solved it: I do not include eigen there directly, but I include some other headers and apparently at least one is including it. Putting the define there worked. I am such an idiot. Thanks!Misadvise
Note the problem with that is that it is, in fact, project wide. It will affect both eigen and everything else. You may want to consider potential alternatives, but regardless, glad it helped.Doreendorelia
Do you experience the warning with the most recent version of Eigen? If so consider reporting a bug (but provide a minimal reproducible example, which in general you should do here as well).Pentatomic
Please consider closing (or self-answer) this question to avoid other people take the time to read it as open.Publia
M
1

Solved thanks to WhozCraig

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

Misadvise answered 13/12, 2019 at 7:27 Comment(0)
B
2

@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"

Blotto answered 18/3, 2020 at 17:54 Comment(6)
That feels wrong to me, unless either 1) you have a header somewhere that's doing #pragma warning(enable: 4996) 2) somehow the PCH mechanism is forgetting the warning disables, which would be a bug, or somehow didn't update when you added the disable to the top of stdafx.h - can you try rebuilding stdafx.cpp?Pokey
I've searched the entire solution for pragma and for 4996 - can't find anything unexpected. I don't know enough about PCH, but I am doing Clean and Rebuild after each change (and stdafx.cpp is compiled each time). I can get rid of warnings for each and any combination of 3 .cpp files by moving the #pragma warning(disable : 4996) from before to after the #include "stdafx.h" in the respective .cpp file. I think I'm out of my depth!Blotto
Right, yes: everything before the #include "stdafx.h" is ignored. You'd need to put the warning change at the top of stdafx.h instead.Pokey
Wow! Didn't know even to suspect that! Thanks. Wonder why no warning?Blotto
:-) I think PCH has tripped up everyone at some point. Yes, warnings for any actual non-comments before the #include would be sensible. I can't see any real reason for not doing that, even for compatibility with old source and other compilers when they rolled out PCH in the first place (in the 90s?)Pokey
@Pokey Thx for the back-to-zero upvote (yours, I presume). No idea why I was down-voted in the first place!Blotto
M
1

Solved thanks to WhozCraig

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

Misadvise answered 13/12, 2019 at 7:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.