how to suppress warnings that C/C++ functions hava no parameters in vscode with clangd?

Advertisements

description

I try to use vscode and clangd to write C/C++, but for those functions whose parameters are empty, vscode will give "A function declaration without a prototype is deprecated in all versions of C (fix available)" warnings, looks like that:
vscode-warning
and suggested that add a void to the parameter explicitly.
I want to suppress this warning, how should I do it?

environment

vscode

Version: 1.76.0-insider
Commit: c7930ca55d072608625ba76c13b5f9baaf9a2136
Date: 2023-02-10T16:24:38.605Z
Electron: 19.1.9
Chromium: 102.0.5005.194
Node.js: 16.14.2
V8: 10.2.154.23-electron.0
OS: Darwin arm64 22.2.0
Sandboxed: Yes

clangd

v0.1.23

related info

config about clangd in vscode settings.json:

"clangd.path": "/opt/homebrew/opt/llvm/bin/clangd",
    "clangd.arguments": [
        "--log=verbose",
        "--pretty",
        "--all-scopes-completion",
        "--completion-style=bundled",
        "--cross-file-rename",
        "--header-insertion=iwyu",
        "--header-insertion-decorators",
        "--background-index",
        "--clang-tidy",
        "--clang-tidy-checks=cppcoreguidelines-*,performance-*,bugprone-*,portability-*,modernize-*,google-*",
        "--fallback-style=Google",
        "-j=2",
        "--pch-storage=memory",
        "--function-arg-placeholders=true",
        "--compile-commands-dir=${workspaceFolder}/build",
        "--completion-parse=auto",
        "--enable-config",
        "--ranking-model=decision_forest",
        "--query-driver=/opt/homebrew/opt/llvm/bin"
    ],
    "clangd.fallbackFlags": [
        "-pedantic",
        "-Wall",
        "-Wextra",
        "-Wcast-align",
        "-Wdouble-promotion",
        "-Wformat=2",
        "-Wimplicit-fallthrough",
        "-Wmisleading-indentation",
        "-Wnon-virtual-dtor",
        "-Wnull-dereference",
        "-Wold-style-cast",
        "-Woverloaded-virtual",
        "-Wpedantic",
        "-Wshadow",
        "-Wunused",
        "-pthread",
        "-fuse-ld=lld",
        "-fsanitize=address",
        "-fsanitize=undefined",
        "-stdlib=libc++",
        "-std=c++17",
    ],
    "clangd.checkUpdates": true,
    "clangd.onConfigChanged": "prompt",
    "clangd.serverCompletionRanking": true,
    "clangd.detectExtensionConflicts": true,
    "editor.suggest.snippetsPreventQuickSuggestions": false

I guess it has something to do with --clang-tidy but don’t know how to set.
Please help me with a clue or a solution, thanks a lot.

>Solution :

As it follows from the warning

"A function declaration without a prototype is deprecated in all
versions of C (fix available)"

you have a C program where functions are declared with empty lists of parameters like for example

void f();

In C opposite to C++ such a declaration means that there is nothing known about the number and types of the function parameters.

So instead you need to declare the function in C like

void f( void );

Or if a function indeed has parameters then you need to specify their types in the function declaration. Such a declaration is named as function prototype. Using the function prototype the compiler is able to determine whether the function is called correctly supplying corresponding types of argument expressions.

Leave a ReplyCancel reply