I've posted this original question, but since it isn't an issue related to CMake, I'm rephrasing it:
I've this example:
#include <iostream>
#include <string>
int main()
{
std::string a("Text");
std::cout << a.c_str() << std::endl;
return 0;
}
which I'm trying to compile with ICC (icc (ICC) 19.1.1.217 20200306
, tested using GCC 4.8, 7, 8 and 9 as base) using this line:
icc -o OUT -pedantic-errors -fmax-errors=1 -march=native -Wall -Werror -Wfatal-errors -Wextra -ftree-vectorize -g -Wl,--exclude-libs,ALL -O3 -DNDEBUG -fPIC -fvisibility=hidden -Wstrict-aliasing -std=gnu++17 main.cpp
But it triggers a warning that results in an error (because of -Werror
). This is the output when using GCC 8 gcc (GCC) 8.3.1 20190311 (Red Hat 8.3.1-3)
as the base compiler:
icc: warning #10193: -vec is default; use -x and -ax to configure vectorization
/opt/rh/devtoolset-8/root/usr/include/c++/8/bits/basic_string.h(5052) (col. 50): error #2102: violation of ansi-alias rules
compilation aborted for main.cpp (code 4)
So, in order to compile, I must remove the -Wstrict-aliasing
check. And just like that, there's a whole set of other checks that triggers a similar behavior (warnings from system include files).
My concern is that I'd really like to have those checks in place for my own code, but obviously, not for libraries over which I've no control.
A suggestion was to use -isystem
or -isystem=/opt/rh/devtoolset-8/root/usr/include/c++/8
, but that only modifies the error:
icc: warning #10193: -vec is default; use -x and -ax to configure vectorization
/lib/../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
And even CMake discourages explicitly the use of -isystem on system include files.
Any ideas of another flag that turns off those warnings for system include files?
Replacing icc by gcc (g++) fixes the issue.
Thanks for your help.
question from:
https://stackoverflow.com/questions/65829714/avoid-warnings-from-system-include-files-using-intel-c-compiler 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…