How to disable warning from VS-Code GCC Compiler? (not use #pragma)
Asked Answered
T

1

1

I'm working on VS-Code with C/C++ intellisense[gcc-arm]. When I do compile , The VS-Code show me hundred of warning like that:

Conversion from 'int' to u16_t{aka 'short unsigned int'} may change value [-Wconversion]

I do not want the VSCode show me those warning. But I have no permission to edit the source code. So, Is the any way to disable those warning by adding some arg to c_cpp_properties.json file?

Tristichous answered 19/12, 2020 at 3:51 Comment(0)
R
3

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):

  1. 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:

  1. How to include compiler flags in the Visual Studio Code debugger?
Rejoice answered 19/12, 2020 at 4:0 Comment(1)
I'd like to add, that without code snippet and/or current configuration it's hard to tell, if that's a bogus warning, like mentioned here: https://mcmap.net/q/831755/-gcc-and-wconversionPasadis

© 2022 - 2024 — McMap. All rights reserved.