2

I want to use clang-tidy (LLVM v7.0.0) with the llvm-header-guard on Windows 10 with CMake for following header file

#ifndef _BAR_H_
#define _BAR_H_

namespace FOO {
namespace BAR {
class BarC {
public:
  BarC() = default;
  ~BarC() = default;
  BarC(const BarC &iValue) = delete;
  const BarC &operator=(const BarC &iValue) = delete;
  BarC(BarC &&iValue) = delete;
  BarC &operator=(BarC &&iValue) = delete;
};
} // namespace BAR
} // namespace FOO

#endif // _BAR_H_

where the ROOT is C:\User\Zlatan\Project\Guard and the header file Bar.h is located at ROOT\Foo\Bar\src\include\Bar\Bar.h

This creates unfortunately following warning

warning: header guard does not follow preferred style [llvm-header-guard]

I read What is proper LLVM header guard style? but I didn't found the correct style with

#ifndef BAR_BAR_H
#ifndef INCLUDE_BAR_BAR_H
#ifndef SRC_INCLUDE_BAR_BAR_H
#ifndef BAR_SRC_INCLUDE_BAR_BAR_H
#ifndef FOO_BAR_SRC_INCLUDE_BAR_BAR_H
#ifndef C_USERS_ZLATAN_PROJECT_GUARD_FOO_BAR_SRC_INCLUDE_BAR_BAR_H

and received for all again

warning: header guard does not follow preferred style [llvm-header-guard]

What is the correct style for my use case? Do I have to configure something in CMake (already use CMAKE_EXPORT_COMPILE_COMMANDS=ON)?

Update

Running

cd C:/Users/Zlatan/Project/Guard/build/Release

clang-tidy -checks='llvm-header-guard' -header-filter=.* -p=. ../../Foo/Bar/src/Bar.cpp

as suggested in cmd generates following output

C:\Users\Zlatan\Project\Guard\build\Release\../../Foo/Bar/src/include/Bar/Bar.h: warning: header guard does not follow preferred style [llvm-header-guard]
#ifndef BAR_BAR_H
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        C:\USERS\ZLATAN\PROJECT\GUARD\BUILD\RELEASE\__\__\FOO\BAR\SRC\INCLUDE\BAR\BAR_H

Best regards Zlatan

ge45mue
  • 677
  • 8
  • 23
  • 4
    First see [What are the rules about using an underscore in a C++ identifier?](https://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier) Other than that it's a purely subjective issue, and probably depends on settings and configuration of `clang-tidy`. – Some programmer dude Jan 08 '19 at 09:03
  • 3
    What constitutes proper header guard naming is indeed a subjective issue, but the question "how do I have to choose my guard names to satisfy clang-tidy" is not in the least bit subjective. – Max Langhof Jan 08 '19 at 09:08
  • This is however a duplicate of [What is proper LLVM header guard style?](https://stackoverflow.com/questions/43880907/what-is-proper-llvm-header-guard-style) – Max Langhof Jan 08 '19 at 09:08
  • 1
    **Not a dup**, OP already tried what is suggested in _"What is proper LLVM header guard style?"_ (which is linked in the Q itself!). Please make sure you read the question entirely before you VTC. – YSC Jan 08 '19 at 09:14
  • you miss a closing `{` on the line `class BarC`. After changing that, I see your warning as `warning: header guard does not follow preferred style [llvm-header-guard]` `#ifndef _BAR_H_` ` ^~~~~~~` ` BAR_BAR_H` i.e. clang-tidy suggests `BAR_BAR_H` to me, and accepts it. I run clang-tidy from the cmake build directory with `clang-tidy -checks='llvm-*' -header-filter='.*' -p=. ../Foo/Bar/src/Bar.cc` and have `#include "Bar/Bar.h"` in `Bar.cc` – pseyfert Jan 15 '19 at 10:04
  • @pyseyfert Please see update and thanks for the hint with the missing closing! – ge45mue Jan 16 '19 at 14:29
  • @ge45mue I have the same issue; maybe windows vs unix path issue? see https://github.com/Microsoft/clang-tools-extra/issues/3 – tbhartman Jun 12 '19 at 15:32

0 Answers0