Skip to content

COMP: Place #define _SILENCE_..._DEPRECATION_WARNING before #include#3970

Merged
dzenanz merged 1 commit intoInsightSoftwareConsortium:masterfrom
N-Dekker:_SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING-before-include
Mar 20, 2023
Merged

COMP: Place #define _SILENCE_..._DEPRECATION_WARNING before #include#3970
dzenanz merged 1 commit intoInsightSoftwareConsortium:masterfrom
N-Dekker:_SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING-before-include

Conversation

@N-Dekker
Copy link
Copy Markdown
Contributor

@N-Dekker N-Dekker commented Mar 18, 2023

Moved each _SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING macro definition upward, placing it before the very first #include statement.

Fixes Visual C++ 2022 warnings like:

warning C4996: 'std::complex::complex': warning STL4037: The effect of instantiating the template std::complex for any type other than float, double, or long double is unspecified. You can define _SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING to suppress this warning.

Follow-up to pull request #3897 commit 3a9c762
"COMP: Supress warning in MSVC for non-float complex"

(Cherry-picked from pull request #3969.)

@N-Dekker N-Dekker requested review from blowekamp and dzenanz March 18, 2023 15:49
@github-actions github-actions bot added type:Compiler Compiler support or related warnings type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct area:Core Issues affecting the Core module labels Mar 18, 2023
@N-Dekker N-Dekker marked this pull request as ready for review March 18, 2023 16:54
Copy link
Copy Markdown
Member

@blowekamp blowekamp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@N-Dekker
Copy link
Copy Markdown
Contributor Author

Thanks

You're welcome @blowekamp Just wondering, did your original PR #3897 commit 3a9c762 already suppress the warnings for you? Because at my side, I kept seeing those warnings.

@N-Dekker
Copy link
Copy Markdown
Contributor Author

For the record, here a minimal example (https://godbolt.org/z/Ks51f1bjo):

#include <complex>
// Doing the #define after the #include has no effect!
#define _SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING
std::complex<int> myComplex;

Using command-line options /W3 /std:c++17 /Bv, it has the following output:

<source>(8): warning C4996: 'std::complex<int>::complex': warning STL4037: The effect of instantiating the template std::complex for any type other than float, double, or long double is unspecified. You can define _SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING to suppress this warning.
Compiler Passes:
C:\data\msvc\14.34.31931-Pre\bin\Hostx64\arm64\cl.exe: Version 19.34.31931.0

Place the #define before the #include to suppress the warning. 😃

@N-Dekker
Copy link
Copy Markdown
Contributor Author

I just realized that the warning is not specific to C++17, it also appears when compiling with /std:c++14. The warning appears to be added to MSVC very recently.

*=========================================================================*/

#if !defined(ITK_LEGACY_REMOVE)
// Supress MSVC warnings
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall I still do an amend/force-push to adjust the comment a little bit? It has a minor typo ("Supress"). No problem, of course.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please fix the misspelling.

@N-Dekker N-Dekker marked this pull request as draft March 20, 2023 14:25
Moved each `_SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING` macro definition
upward, placing it before the very first `#include` statement.

Fixes Visual C++ 2022 warnings like:

> warning C4996: 'std::complex<char>::complex': warning STL4037: The effect of instantiating the template std::complex for any type other than float, double, or long double is unspecified. You can define _SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING to suppress this warning.

Follow-up to pull request InsightSoftwareConsortium#3897
commit 3a9c762
"COMP: Supress warning in MSVC for non-float complex"
@N-Dekker N-Dekker force-pushed the _SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING-before-include branch from 14782c4 to 51e4618 Compare March 20, 2023 14:42
@N-Dekker N-Dekker marked this pull request as ready for review March 20, 2023 14:43
@dzenanz dzenanz merged commit cd0ff94 into InsightSoftwareConsortium:master Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Core Issues affecting the Core module type:Compiler Compiler support or related warnings type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants