Referring to my own reference document here, if you have access to the build flags, you can pass in -Wno-conversion
to disable this warning at compile time.
From my document:
Additional C and C++ build notes (ex: w/gcc
or clang
compilers):
Use -Wwarning-name
to turn ON build warning "warning-name", and -Wno-warning-name
to turn OFF build warning "warning-name". -W
turns a warning ON, and -Wno-
turns a warning OFF. Here's what gcc has to say about it (source: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html; emphasis added):
You can request many specific warnings with options beginning with -W
, for example -Wimplicit
to request warnings on implicit declarations. Each of these specific warning options also has a negative form beginning -Wno-
to turn off warnings; for example, -Wno-implicit
. This manual lists only one of the two forms, whichever is not the default.
Regarding Visual Studio Code, I do not use that IDE, but the c_cpp_properties.json
file appears to have no ability to set build flags: https://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-reference.
The tasks.json
file, however, does: https://code.visualstudio.com/docs/cpp/config-linux#_build-helloworldcpp.
Here's their example:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++ build active file",
"command": "/usr/bin/g++",
"args": ["-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}"],
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
So, it looks like you could add -Wno-conversion
to the args
list in the JSON file, like this:
"args": [
"-Wno-conversion",
"-g",
"${file}",
"-o", "${fileDirname}/${fileBasenameNoExtension}"
],
See also:
- How to include compiler flags in the Visual Studio Code debugger?