Clang-tidy integration in clangd 'misc-const-correctness' not working

Hi all,

I’m running clangd version:

clangd version 15.0.7 (Red Hat 15.0.7-1.module+el8.8.0+17939+b58878af)
Features: linux
Platform: x86_64-unknown-linux-gnu; target=x86_64-redhat-linux-gnu

and clang-tidy:

LLVM (http://llvm.org/):
  LLVM version 15.0.7
  Optimized build.
  Default target: x86_64-redhat-linux-gnu
  Host CPU: tigerlake

When I’m adding in my clangd configuration (in ~/.config/clangd/config.yaml)
the option ‘misc-const-correctness’ to the clang-tidy this is completely ignored.
But when I use clang-tidy directly from command line it’s working perfectly.

Why is this happening?

here’s the clangd configuration file

CompileFlags: # Tweak the parse settings
  Compiler: clang++
  Add: [
      # Compiler flags
      "-xc++",
      "-Wall",
      "-Wextra", # reasonable and standard
      "-Wshadow", # warn the user if a variable declaration shadows one from a parent context
      "-Wnon-virtual-dtor", # warn the user if a class with virtual functions has a non-virtual destructor. This helps
                            #, catch hard to track down memory errors
      "-Wold-style-cast", # warn for c-style casts
      "-Wcast-align", # warn for potential performance problem casts
      "-Wunused", # warn on anything being unused
      "-Woverloaded-virtual", # warn if you overload (not override) a virtual function
      "-Wpedantic", # warn if non-standard C++ is used
      "-Wconversion", # warn on type conversions that may lose data
      "-Wsign-conversion", # warn on sign conversions
      "-Wnull-dereference", # warn if a null dereference is detected
      "-Wdouble-promotion", # warn if float is implicit promoted to double
      "-Wformat=2", # warn on security issues around functions that format output (ie printf)
      "-Wno-implicit-int-float-conversion" # disable int to float conversions warning
    ]

Index:
  Background: Build # Build a type + incoming reference index in the background

Diagnostics:

  UnusedIncludes: Strict
  # https://clang.llvm.org/extra/clang-tidy/
  ClangTidy:
    Add: [
      '*',
    ]
    Remove: [
      'fuchsia-*',
      'google-*',
      'zircon-*',
      'abseil-*',
      'modernize-*',
      'llvm*',
      'hicpp-vararg',                                          
      'hicpp-no-array-decay',                                   
      'cppcoreguidelines-pro-type-union-access',            
      'cppcoreguidelines-pro-type-vararg',                      
      'cppcoreguidelines-pro-bounds-array-to-pointer-decay',   
      'altera-unroll-loops',
      'cppcoreguidelines-owning-memory',                       
      'readability-identifier-length',                         
      'altera-id-dependent-backward-branch',
    ]

InlayHints:
  Designators: Yes
  Enabled: Yes
  ParameterNames: Yes
  DeducedTypes: Yes

Hover:
  ShowAKA: Yes

and the working clang-tidy command:

$ clang-tidy --checks='*' test.cpp

the test file is:

class MyClass
{
  public:
    MyClass(const MyClass&)            = default;
    MyClass(MyClass&&)                 = default;
    MyClass& operator=(const MyClass&) = default;
    MyClass& operator=(MyClass&&)      = default;
    MyClass() = default;
    ~MyClass() = default;
    void const_qualified_method() const {};
};
int test()
{
    // Normal values like built-ins or objects.
    int potential_const_int = 42; // 'const int potential_const_int = 42' suggestion.

    MyClass could_be_const; // 'const MyClass could_be_const' suggestion;
    could_be_const.const_qualified_method();

    return potential_const_int;
}

and the output of clang-tidy:

test.cpp:1:7: warning: declaration must be declared within the '__llvm_libc' namespace [llvmlibc-implementation-in-namespace]
class MyClass
      ^
test.cpp:6:14: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
    MyClass& operator=(const MyClass&) = default;
    ~~~~~~~~ ^
    auto                               -> MyClass&
test.cpp:7:14: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
    MyClass& operator=(MyClass&&)      = default;
    ~~~~~~~~ ^
    auto                          -> MyClass&
est.cpp:12:5: warning: declaration must be declared within the '__llvm_libc' namespace [llvmlibc-implementation-in-namespace]
int test()
    ^
test.cpp:12:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
int test()
~~~ ^
auto       -> int
test.cpp:15:5: warning: variable 'potential_const_int' of type 'int' can be declared 'const' [misc-const-correctness]
    int potential_const_int = 42; // 'const int potential_const_int = 42' suggestion.
    ^
        const 
test.cpp:15:31: warning: 42 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers]
    int potential_const_int = 42; // 'const int potential_const_int = 42' suggestion.
                              ^
test.cpp:17:5: warning: variable 'could_be_const' of type 'MyClass' can be declared 'const' [misc-const-correctness]
    MyClass could_be_const; // 'const MyClass could_be_const' suggestion;
    ^
            const 
test.cpp:1:7: warning: declaration must be declared within the '__llvm_libc' namespace [llvmlibc-implementation-in-namespace]
class MyClass
      ^
test.cpp:6:14: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
    MyClass& operator=(const MyClass&) = default;
    ~~~~~~~~ ^
    auto                               -> MyClass&
test.cpp:7:14: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
    MyClass& operator=(MyClass&&)      = default;
    ~~~~~~~~ ^
    auto                          -> MyClass&
test.cpp:12:5: warning: declaration must be declared within the '__llvm_libc' namespace [llvmlibc-implementation-in-namespace]
int test()
    ^
test.cpp:12:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
int test()
~~~ ^
auto       -> int
test.cpp:15:5: warning: variable 'potential_const_int' of type 'int' can be declared 'const' [misc-const-correctness]
    int potential_const_int = 42; // 'const int potential_const_int = 42' suggestion.
    ^
        const 
test.cpp:15:31: warning: 42 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers]
    int potential_const_int = 42; // 'const int potential_const_int = 42' suggestion.
                              ^
test.cpp:17:5: warning: variable 'could_be_const' of type 'MyClass' can be declared 'const' [misc-const-correctness]
    MyClass could_be_const; // 'const MyClass could_be_const' suggestion;
    ^
            const 
9 warnings generated.

Unfortunately, clangd disables the misc-const-correctness check due to its performance impact.

It was suggested in Don't run slow clang-tidy checks · Issue #1337 · clangd/clangd · GitHub that we should add a way for users to override this (for users who don’t mind the performance impact), but this has not been implemented.