Skip to content

Commit e2ef1e1

Browse files
Add 3C .clang-tidy files and documentation.
1 parent 8787e3a commit e2ef1e1

File tree

5 files changed

+105
-0
lines changed

5 files changed

+105
-0
lines changed

clang/docs/checkedc/3C/CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,7 @@ in your code. Specifically:
8686
* Space after the type name, i.e., `Type *K` _not_ `Type* K`.
8787

8888
* Space before and after `:` in iterators, i.e., `for (auto &k : List)`
89+
90+
All files should be formatted with `clang-format` and pass `clang-tidy` ([more
91+
information](clang-tidy.md)), and nonempty files should have a final newline
92+
(surprisingly, `clang-format` cannot enforce this).

clang/docs/checkedc/3C/clang-tidy.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Use of `clang-tidy` on 3C
2+
3+
We're starting to use `clang-tidy` to automatically enforce some of the LLVM
4+
style guidelines in our code. The main configuration is in
5+
`clang/lib/3C/.clang-tidy`.
6+
7+
We're currently using version 11.0.0 due to bugs in older versions, so if you
8+
want to verify that our code is compliant with `clang-tidy`, you'll need to get
9+
a copy of that version. If it isn't available from your OS distribution, you may
10+
need to build it from source. This repository is currently based on a
11+
pre-release of LLVM 9.0.0, so you can't use its version of `clang-tidy`.
12+
However, Microsoft plans to upgrade it to LLVM 11.0.0 soon, at which point
13+
you'll have the option to use `clang-tidy` built from this repository.
14+
15+
This file maintains a list of `clang-tidy` problems we've encountered that led
16+
to warnings we needed to suppress, so those suppressions can refer to the
17+
corresponding entries in this file.
18+
19+
## `_3C` name prefix
20+
21+
We use `3C` in the names of some program elements. Since an identifier cannot
22+
begin with a digit, for names that would begin with `3C`, we decided that the
23+
least evil is to prepend an underscore so the name begins with `_3C`. (A leading
24+
underscore sometimes suggests that a program element is "private" or "special",
25+
which is not the case here; this may be misleading.) One alternative we
26+
considered was to use `ThreeC` at the beginning of a name, but that would be
27+
inconsistent and would make it more work to search for all occurrences of either
28+
`3C` or `ThreeC`. And we thought the alternative of using `ThreeC` everywhere
29+
was just too clunky.
30+
31+
Unfortunately, the current implementation of the [LLVM naming
32+
guideline](https://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly)
33+
in the `readability-identifier-naming` check does not allow names to begin with
34+
underscores; in fact, it proposes to remove the underscores, leaving invalid
35+
identifiers that break compilation. There's no indication that the guideline has
36+
contemplated our scenario, and we don't know whether its maintainers would allow
37+
our scenario if they knew about it; we've filed [a
38+
bug](https://bugs.llvm.org/show_bug.cgi?id=48230) to ask.

clang/include/clang/3C/.clang-tidy

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# A copy of `clang/lib/3C/.clang-tidy`. We could consider using a symlink if we
2+
# don't care about Windows.
3+
Checks: '-*,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,-misc-non-private-member-variables-in-classes,readability-identifier-naming'
4+
CheckOptions:
5+
- key: readability-identifier-naming.ClassCase
6+
value: CamelCase
7+
- key: readability-identifier-naming.EnumCase
8+
value: CamelCase
9+
- key: readability-identifier-naming.FunctionCase
10+
value: camelBack
11+
- key: readability-identifier-naming.MemberCase
12+
value: CamelCase
13+
- key: readability-identifier-naming.ParameterCase
14+
value: CamelCase
15+
- key: readability-identifier-naming.UnionCase
16+
value: CamelCase
17+
- key: readability-identifier-naming.VariableCase
18+
value: CamelCase
19+

clang/lib/3C/.clang-tidy

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Standard clang-tidy options for 3C C++ code. The .clang-tidy files are mostly
2+
# analogous to the .clang-format files, so the remarks in .clang-format in this
3+
# directory apply.
4+
5+
# This is currently the same as `/.clang-tidy`. `/clang/.clang-tidy` disables
6+
# the readability-identifier-naming check, but we mostly comply with it.
7+
8+
Checks: '-*,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,-misc-non-private-member-variables-in-classes,readability-identifier-naming'
9+
CheckOptions:
10+
- key: readability-identifier-naming.ClassCase
11+
value: CamelCase
12+
- key: readability-identifier-naming.EnumCase
13+
value: CamelCase
14+
- key: readability-identifier-naming.FunctionCase
15+
value: camelBack
16+
- key: readability-identifier-naming.MemberCase
17+
value: CamelCase
18+
- key: readability-identifier-naming.ParameterCase
19+
value: CamelCase
20+
- key: readability-identifier-naming.UnionCase
21+
value: CamelCase
22+
- key: readability-identifier-naming.VariableCase
23+
value: CamelCase
24+

clang/tools/3c/.clang-tidy

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# A copy of `clang/lib/3C/.clang-tidy`. We could consider using a symlink if we
2+
# don't care about Windows.
3+
4+
Checks: '-*,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,-misc-non-private-member-variables-in-classes,readability-identifier-naming'
5+
CheckOptions:
6+
- key: readability-identifier-naming.ClassCase
7+
value: CamelCase
8+
- key: readability-identifier-naming.EnumCase
9+
value: CamelCase
10+
- key: readability-identifier-naming.FunctionCase
11+
value: camelBack
12+
- key: readability-identifier-naming.MemberCase
13+
value: CamelCase
14+
- key: readability-identifier-naming.ParameterCase
15+
value: CamelCase
16+
- key: readability-identifier-naming.UnionCase
17+
value: CamelCase
18+
- key: readability-identifier-naming.VariableCase
19+
value: CamelCase
20+

0 commit comments

Comments
 (0)