如何禁用来自VS-Code GCC编译器的警告?(不使用#pragma) [英] How to disable warning from VS-Code GCC Compiler? (not use #pragma)

查看:167
本文介绍了如何禁用来自VS-Code GCC编译器的警告?(不使用#pragma)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从'int'到u16_t {aka'short unsigned int'}的转换可能会更改[-Wconversion]

我不希望VSCode向我显示那些警告.但是我无权编辑源代码.那么,是否可以通过在c_cpp_properties.json文件中添加一些arg来禁用那些警告呢?

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?

推荐答案

参考

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.

从我的文档中

其他C和C ++构建说明(例如:w/ gcc clang 编译器):

Additional C and C++ build notes (ex: w/gcc or clang compilers):

  1. 使用 -Wwarning-name 打开构建警告"warning-name",并使用 -Wno-warning-name 关闭构建警告"warning-name";警告名称". -W 打开警告,而 -Wno-关闭警告.这就是gcc对此要说的话(来源: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html; 强调):

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

您可以使用以 -W 开头的选项来请求许多特定的警告,例如,使用 -Wimplicit 来请求有关隐式声明的警告.每个特定的警告选项还具有负形式,以 -Wno-开头以关闭警告.例如 -Wno-implicit .本手册仅列出两种形式之一,默认为不是.

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.

关于Visual Studio代码,我不使用该IDE,但是 c_cpp_properties.json 文件似乎无法设置构建标记:

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.

tasks.json 文件确实可以:这是他们的例子:

{
  "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
      }
    }
  ]
}

因此,看起来您可以将 -Wno-conversion 添加到JSON文件中的 args 列表中,如下所示:

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}"
],

另请参见:

  1. 如何包括在Visual Studio代码调试器中使用编译器标志?

这篇关于如何禁用来自VS-Code GCC编译器的警告?(不使用#pragma)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆