Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling clang-tidy diagnostic

I'm trying to set up clang-tidy for enforcing naming conventions in a C project. This project is composed of multiple external sources and uses a plain makefile environment, thus no tool like cmake or bear is available to generate a compilation database.

This is also what I want: Using the custom environment I'd like to selectively invoke clang-tidy for each file that should be checked.

I was configuring the tool, mainly for the check readability-identifier-naming. For testing I have a .c and .h file, both in the same directory, with the following content:

dummy.c

#include "dummy.h"
#include "MISSING_module.h"

// EOF

dummy.h

#ifndef _DUMMY_H_
#define _DUMMY_H_

#include <stdlib.h>

// EOF

The command I'm invoking is

clang-tidy dummy.c -checks='-*,readability-identifier-naming' -- -DCMAKE_EXPORT_COMPILE_COMMANDS=ON`

However, clang-tidy is still following the #include within the C-file and checks for existing headers:

dummy.h:4:10: error: 'stdlib.h' file not found [clang-diagnostic-error]
#include <stdlib.h>
          ^
Found compiler error(s).

Is there any way to disable this? clang-diagnostic-error is not even enabled as check. Or are there alternative tools I should know of to enforce naming conventions?

like image 333
martin Avatar asked Oct 18 '25 18:10

martin


1 Answers

Look at the way you are using clang-tidy: the -- option is used to specify compilation options.

clang-diagnostic-error doesn't have anything to do with clang-tidy itself. Those are compiler warnings and you cannot turn them off. Clang-tidy needs the analyzed file to be compile-able to build an AST which it uses internally for the checks. You'll find more on clang-diagnostic-error in clang-tidy documentation.

like image 61
pablo285 Avatar answered Oct 20 '25 09:10

pablo285



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!