Skip to content

Request: Allow merge of forcedInclude setting from base config when using compile_commands.json #8274

Open

Description

Bug type: General

Describe the bug

  • OS and Version: Latest Linux Mint
  • VS Code Version: 1.61
  • C/C++ Extension Version: v1.7.0

This bug should be pretty easy to reproduce, for example:

Create a header file suppress-warnings.h with contents:

#ifdef __INTELLISENSE__
// 20 - identifier is undefined
#pragma diag_suppress 20
#endif

Create main.cc with contents:

int main(int argc, char** argv) { fdsfsdsfd; }

Edit c_cpp_properties.json:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": ["${default}"],
            "defines": [],
            "compilerPath": "/usr/local/bin/clang++",
            "compileCommands": "${workspaceFolder}/compile_commands.json",
            "cStandard": "c17",
            "cppStandard": "gnu++20",
            "intelliSenseMode": "linux-clang-x64",
            "forcedInclude": [
                "${workspaceFolder}/suppress-warnings.h"
            ]
        }
    ],
    "version": 4
}

Example compile_commands.json (empty list won't break it):

[
  {
    "directory": "/path-to-workspace/build/src",
    "command": "true",
    "file": "/path-to-workspace/main.cc"
  }
]

Includes from forcedInclude are not included and do not suppress a warning.

If you comment compileCommands in c_cpp_properties.json - the forced include is included.

Expected behaviour:

forcedInclude is included when using compileCommands

Activity

  1. Colengms commented on Oct 13, 2021

    @Colengms
    Contributor

    Hi Łukasz Kurowski (@crackcomm) . It's currently 'by design' that use of compile_commands.json superceeds the other settings in your c_cpp_properties.json. A compile_commands.json should include all compiler args necessary to compile the file. The C/C++ extension uses that entire command line (from either the command field, or the arguments field) to configure IntelliSense to match how the file is actually built. If a forced include is required to compile the file, it should be passed on the command line in compile_commands.json. I don't believe "true" would be a valid compiler command line. The specification for compile_commands.json is here: https://clang.llvm.org/docs/JSONCompilationDatabase.html

  2. crackcomm commented on Oct 13, 2021

    @crackcomm
    Author

    Hi Colen Garoutte-Carson (@Colengms), indeed "true" is not a valid compiler command nevertheless it does break the behavior I was expecting. It is a valid command though.

  3. crackcomm commented on Oct 13, 2021

    @crackcomm
    Author

    Colen Garoutte-Carson (@Colengms) on the other hand - header files are never included in compile_commands.json.

  4. bobbrow commented on Oct 13, 2021

    @bobbrow
    Contributor

    Colen Garoutte-Carson (@Colengms) this request is in the context of #1231 trying to suppress some warnings. Does the new "merge configurations" setting apply for compile_commands.json + forcedInclude?

  5. Colengms commented on Oct 14, 2021

    @Colengms
    Contributor

    Bob Brown (@bobbrow) The new merge feature only applies to configuration providers.

    Łukasz Kurowski (@crackcomm) When a header file is opened, the extension tries to associate that header with a source file that includes it, and looks for that source file in your compile_commands.json. Note that the purpose of using compile_commands.json with the C/C++ extension is specifically so that configuration information can be inferred based on the compiler args. Without those args present, I don't believe it's accomplishing anything. You might get the behavior you expect by removing use of the compile_commands.json from your cpp_properties.json (or, adding real compile command lines, which use your forced include, to compile_commands.json).

  6. crackcomm commented on Oct 14, 2021

    @crackcomm
    Author

    Colen Garoutte-Carson (@Colengms) previously my compile_commands.json was generated by CMake, the one provided here is enough to reproduce the issue.

  7. Colengms commented on Oct 14, 2021

    @Colengms
    Contributor

    Hi Łukasz Kurowski (@crackcomm) What you are seeing is currently by design. To add a forced include when using compile_commands.json, you would need to specify -include <file> to the command line.

    It sounds like you're requesting a feature, that we merge forcedInclude settings from c_cpp_properties.json when using compile_commands.json. So, I'll change this to a feature request.

  8. changed the title [-]Can't use forcedInclude with compileCommands[/-] [+]Request: Allow merge of `forcedInclude` setting from base config when using `compile_commands.json`[/+] on Oct 14, 2021
  9. github-actions commented on Dec 13, 2021

    @github-actions

    This feature request is being closed due to insufficient upvotes. When enough upvotes are received, this issue will be eligible for our backlog.

  10. modified the milestones: Triage, Backlog on Jun 30, 2022
  11. removed
    more votes neededIssues that have been postponed until more community members upvote it
    on Jun 30, 2022
  12. github-actions commented on Jun 30, 2022

    @github-actions

    This feature request has received enough votes to be added to our backlog.

  13. tgvarik commented on Jun 7, 2023

    @tgvarik

    forcedInclude can't serve as a workaround for #4503 without this.

  14. sean-mcmanus commented on Jun 16, 2023

    @sean-mcmanus
    Contributor

    Tom G Varik (@tgvarik) FYI, we may move our compile_commands.json handling to the open source TypeScript, so this would be more likely to be implemented after that is done (or we could accept and external PR to for it).

  15. yiftahw commented on Nov 11, 2024

    @yiftahw
    Contributor

    Colen Garoutte-Carson (@Colengms) I encountered a real problem that demonstrates this feature is needed, unless you can advise a workaround.
    I'm working on an embedded project using the Altera Nios II processor, the compiler nios2-elf-gcc provides built in functions for memory access. these functions are not visible in any compiler header.
    Currently when opening any source file which uses these built in functions, I see in the PROBLEMS tab the following:
    identifier "____builtin_ldbio" is undefined.
    A possible solution is to create a file nios2_stub.h with the following content:

    #ifdef __INTELLISENSE__
    int __builtin_ldbio(volatile const void *);
    int __builtin_ldbuio(volatile const void *);
    int __builtin_ldhio(volatile const void *);
    // more function prototypes followed...
    #endif

    but I will need to explicitly #include this header in my code or add it as a forced include in my CMake build, both options feel like a wrong move as this header exists only for IntelliSense purposes. a better solution IMO would be to add it to the extension's forcedIncludes paths.
    for clarity, I am using the compileCommands feature in my project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions