Skip to content

[Clangd] C++20 modules support ignores CompileFlags.Add/Remove compiling a module preamble #112635

@petr-polezhaev

Description

@petr-polezhaev

When used with compile_commands.json clangd seem to ignore flag modifications from .clangd when (and only when) compiling module information, leading to module search issues

Given compile_commands.json:

[
    {
      "directory": "/path/to/example",
      "command": "/usr/bin/clang++ -std=c++23 -ffoobar test.cppm",
      "file": "test.cppm",
      "output": "build/test.cppm.o"
    },
    {
        "directory": "/path/to/example",
        "command": "/usr/bin/clang++ -std=c++23 -ffoobar main.cpp",
        "file": "main.cpp",
        "output": "build/main.cpp.o"
    }
  ]

.clangd:

CompileFlags:
    CompilationDatabase: "."
    Remove:
    - "-ffoobar"

test.cppm:

export module test;

export void test() {}

main.cpp:

import test;

int main() { return 0; }

Results in:
image

E[02:40:54.668] Scanning modules dependencies for /home/test/clangd_modules_test/test.cppm failed: error: unknown argument: '-ffoobar'

I[02:40:54.668] Built prerequisite modules for file /home/test/clangd_modules_test/test.cppm in 0.00 seconds
E[02:40:54.668] Scanning modules dependencies for /home/test/clangd_modules_test/main.cpp failed: error: unknown argument: '-ffoobar'

I[02:40:54.668] Built prerequisite modules for file /home/test/clangd_modules_test/main.cpp in 0.00 seconds

If I remove -ffoobar from compile_commands.json it works correctly

This breaks support for compiling with gcc (that requires -fmodule-ts and other arguments clang does not understand) and using clangd, while generating compile_commands.json with cmake. Using .clangd to remove unsupported options (and add other options needed for clang) works for the rest of the functionality but not for modules

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:modulesC++20 modules and Clang Header Modulesclangd

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions