-2

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.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
menget
  • 21
  • 2
  • 1
    Why not specify `void` instead of looking for a loophole? It's deprecated as the warning says. But are you writing C or C++, because these are two different languages with different rules. – Harith Feb 12 '23 at 12:15
  • Sorry, I prefer the style without void, but don't know which setting this is related to. – menget Feb 12 '23 at 12:18
  • 1
    `void function()` does **not** specify a function that takes no arguments. It's a *deprecated* way of specifying a function that takes an unspecified number of arguments of unspecified type. If you don't want to get that warning, properly write `void function(void)` to specify a function that takes no arguments. – Andrew Henle Feb 12 '23 at 12:20
  • 4
    Using or not using `void` is not a style. It is a different semantic meaning. Update your code to modern C. – Eric Postpischil Feb 12 '23 at 12:21
  • Thanks, but how do I specify which C standard to use for syntax checking? – menget Feb 12 '23 at 12:31
  • This is a pure style choice in C++ (where without `void` is more common), but not C (where it should usually be with `void`). – user17732522 Feb 12 '23 at 12:32
  • @menget It will take the one from your `compile_commands.json`. You specified C++17 as fallback in the flags you are showing. – user17732522 Feb 12 '23 at 12:35

1 Answers1

1

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.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335