Issue 114770
Summary [clang-tidy] compiler flag '-Warray-compare' does not take effect
Labels clang-tidy
Assignees
Reporter stephenLucien
    
clangd version
```shell
[li@ArchLinux-li cpp]$ clangd --version
clangd version 18.1.8
Features: linux
Platform: x86_64-pc-linux-gnu
[li@ArchLinux-li cpp]$ clang-tidy --version
LLVM (http://llvm.org/):
  LLVM version 18.1.8
  Optimized build.
```

my `.clangd` file:
```yaml
Diagnostics:
 ClangTidy:
        Remove: 
            - modernize-use-trailing-return-type
            - modernize-use-nullptr
 - modernize-use-using
            - modernize-use-bool-literals
            - modernize-use-equals-default
 - modernize-avoid-c-arrays
            - modernize-redundant-void-arg
            - modernize-deprecated-headers
            - bugprone-easily-swappable-parameters
        Add: 
            - modernize*
            - bugprone-* 
            - performance-*
CompileFlags:
    Add: 
        - "-ferror-limit=0"
        - "-fdelete-null-pointer-checks"
 - "-Wall"
        - "-Wextra"
        - "-Wpedantic"
        - "-Wformat=2"
        - "-Wnull-dereference"
        - "-Wpointer-compare"
        - "-Wstring-compare"
        - "-Warray-compare"
        - "-Wno-unused-but-set-variable"
 - "-Wno-unused-but-set-parameter"
        - "-Wno-unused-variable"
 - "-Wno-unused-parameter"
        - "-Wno-unused-label"
 - "-Wno-unused-function"
        
```


my test code `main.cpp`:
```cpp

#include <iostream>

typedef struct {
 char str[16];
  int id[16];
} MyObj;

bool myobj_equal(const MyObj &obj1, const MyObj &obj2) {
  if (obj1.str != obj2.str) // compare array here, expect warning !!!
    return false;
  if (obj1.id != obj2.id) // compare array here, expect warning !!!
    return false;
 return true;
}

int main(int argc, char *argv[]) {
  //
  char str1[16] = "hello";
  char str2[16] = "hello";
  if (str1 == str2) {
    std::cout << "same string";
  }
  //
  MyObj a1 = {.str = "hello"};
  MyObj a2 = {.str = "hello"};
  if (myobj_equal(a1, a2)) {
    std::cout << "same obj";
  }
  return 0;
}

```

only the following warnings pops up:
![image](https://github.com/user-attachments/assets/dea82e61-02e4-4cbe-942d-e6795e7fdcc7)

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to