What is proper LLVM header guard style?

家住魔仙堡 提交于 2019-12-01 04:17:40

问题


In clang tidy, the check [llvm-header-guard] looks for LLVM style header guards, but I can't find any examples of proper LLVM header guard style, specifically the structure of the name given to the define, the coding standards pages does not mention anything.


回答1:


Looking at the unit tests:

  • https://github.com/llvm-mirror/clang-tools-extra/blob/master/unittests/clang-tidy/LLVMModuleTest.cpp

it seems to accept a few variations on the commonly used patterns. For a file named include/llvm/ADT/foo.h the convention seems to be:

#ifndef LLVM_ADT_FOO_H
#define LLVM_ADT_FOO_H
//...
#endif // LLVM_ADT_FOO_H



回答2:


Presumably the LLVM codebase adheres to the LLVM coding standards, so one can simply look at a few LLVM header files to get an idea of what the guard looks like. Here are some random LLVM header files I looked at:

https://github.com/llvm-mirror/llvm/blob/master/include/llvm/CodeGen/SelectionDAG.h

https://github.com/llvm-mirror/llvm/blob/master/include/llvm/Support/AlignOf.h

Based on those files, I think the header guard looks like this:

#ifndef LLVM_CODEGEN_SELECTIONDAG_H
#define LLVM_CODEGEN_SELECTIONDAG_H
...
#endif



回答3:


The proper style for LLVM to detect and be happy with your header is to take the path used to include your header, convert it to uppercase, replace directory separators with underscores, and replace dots in file extensions with underscores.

For instance, if you use #include <dopelib/dopestuff/whatitisyo.h>, your header would be:

#ifndef DOPELIB_DOPESTUFF_WHATITISYO_H
#define DOPELIB_DOPESTUFF_WHATITISYO_H

/** Your code here. **/

#endif

Hope this helps!



来源:https://stackoverflow.com/questions/43880907/what-is-proper-llvm-header-guard-style

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!