4

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?

pablo285
  • 2,460
  • 4
  • 14
  • 38
martin
  • 591
  • 1
  • 8
  • 17

1 Answers1

3

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.

pablo285
  • 2,460
  • 4
  • 14
  • 38
  • 7
    For me it wasn't quite obvious that `clang-tidy` actually needs to invoke a compiler. The docs are rather short so that was hard to understand, I've worked with different static analyzers that wouldn't need it. In the end I'm now generating a compilation database with `gmake` and python. – martin Jul 09 '19 at 17:22