| Issue |
158621
|
| Summary |
[Clang-Tidy] Add discussion to portability-avoid-pragma-once
|
| Labels |
documentation,
clang-tidy
|
| Assignees |
|
| Reporter |
SunBlack
|
In #140388, a check was added that recommends replacing `#pragma once` with include guards. From a portability perspective, this is correct. However, there are also good reasons for `#pragma once`: It is not as susceptible to copy & paste errors or renaming errors.
I have now looked at only a few headers in this repo, and you can always find minor errors that were not detected even with `llvm-header-guard` – and as you can see in #66477, such errors happen more often if you don't have a dedicated test for them (which few projects are likely to have). As long as there is no generic check for this (which would be difficult), errors like this one #29221 are likely to occur.
Example for not uniform include guards here:
https://github.com/llvm/llvm-project/blob/29b6433bfbd6b778d6a6686cac96ae4b7640224e/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.h#L9-L10
vs (misses the word `check`)
https://github.com/llvm/llvm-project/blob/29b6433bfbd6b778d6a6686cac96ae4b7640224e/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.h#L9-L10
Therefore, I would suggest adding a brief discussion to the documentation:
- If portability and all possible edge cases are a high priority => include guard
- In "simple" projects, `#pragma once` is also perfectly fine, as it prevents macro naming errors
- In C++20 projects, switching to modules can be an alternative (including a note that compiler support is still limited)
So basically I just miss a hint, that header guards also have their disadvantages (and not only `#prama once`).
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs