@@ -30,7 +30,7 @@ because the naming and other conventions are dictated by the C++ standard.
30
30
31
31
There are some conventions that are not uniformly followed in the code base
32
32
(e.g. the naming convention). This is because they are relatively new, and a
33
- lot of code was written before they were put in place. Our long term goal is
33
+ lot of code was written before they were put in place. Our long- term goal is
34
34
for the entire codebase to follow the convention, but we explicitly *do not *
35
35
want patches that do large-scale reformatting of existing code. On the other
36
36
hand, it is reasonable to rename the methods of a class if you're about to
@@ -50,7 +50,7 @@ code imported into the tree. Generally, our preference is for standards
50
50
conforming, modern, and portable C++ code as the implementation language of
51
51
choice.
52
52
53
- For automation, build-systems and utility scripts Python is preferred and
53
+ For automation, build-systems, and utility scripts, Python is preferred and
54
54
is widely used in the LLVM repository already.
55
55
56
56
C++ Standard Versions
@@ -92,7 +92,7 @@ LLVM support libraries (for example, `ADT
92
92
<https://github.com/llvm/llvm-project/tree/main/llvm/include/llvm/ADT> `_)
93
93
implement specialized data structures or functionality missing in the standard
94
94
library. Such libraries are usually implemented in the ``llvm `` namespace and
95
- follow the expected standard interface, when there is one.
95
+ follow the expected standard interface when there is one.
96
96
97
97
When both C++ and the LLVM support libraries provide similar functionality, and
98
98
there isn't a specific reason to favor the C++ implementation, it is generally
@@ -325,8 +325,8 @@ implementation file. In any case, implementation files can include additional
325
325
comments (not necessarily in Doxygen markup) to explain implementation details
326
326
as needed.
327
327
328
- Don't duplicate function or class name at the beginning of the comment.
329
- For humans it is obvious which function or class is being documented;
328
+ Don't duplicate the function or class name at the beginning of the comment.
329
+ For humans, it is obvious which function or class is being documented;
330
330
automatic documentation processing tools are smart enough to bind the comment
331
331
to the correct declaration.
332
332
@@ -369,7 +369,7 @@ lower-case letter, and finish the last sentence without a period, if it would
369
369
end in one otherwise. Sentences which end with different punctuation, such as
370
370
"did you forget ';'?", should still do so.
371
371
372
- For example this is a good error message:
372
+ For example, this is a good error message:
373
373
374
374
.. code-block :: none
375
375
@@ -443,7 +443,7 @@ Write your code to fit within 80 columns.
443
443
There must be some limit to the width of the code in
444
444
order to allow developers to have multiple files side-by-side in
445
445
windows on a modest display. If you are going to pick a width limit, it is
446
- somewhat arbitrary but you might as well pick something standard. Going with 90
446
+ somewhat arbitrary, but you might as well pick something standard. Going with 90
447
447
columns (for example) instead of 80 columns wouldn't add any significant value
448
448
and would be detrimental to printing out code. Also many other projects have
449
449
standardized on 80 columns, so some people have already configured their editors
@@ -520,7 +520,7 @@ within each other and within function calls in order to build up aggregates
520
520
The historically common formatting of braced initialization of aggregate
521
521
variables does not mix cleanly with deep nesting, general expression contexts,
522
522
function arguments, and lambdas. We suggest new code use a simple rule for
523
- formatting braced initialization lists: act as- if the braces were parentheses
523
+ formatting braced initialization lists: act as if the braces were parentheses
524
524
in a function call. The formatting rules exactly match those already well
525
525
understood for formatting nested function calls. Examples:
526
526
@@ -607,11 +607,11 @@ Static constructors and destructors (e.g., global variables whose types have a
607
607
constructor or destructor) should not be added to the code base, and should be
608
608
removed wherever possible.
609
609
610
- Globals in different source files are initialized in `arbitrary order
610
+ Globals in different source files are initialized in an `arbitrary order
611
611
<https://yosefk.com/c++fqa/ctors.html#fqa-10.12> `_, making the code more
612
612
difficult to reason about.
613
613
614
- Static constructors have negative impact on launch time of programs that use
614
+ Static constructors have a negative impact on the launch time of programs that use
615
615
LLVM as a library. We would really like for there to be zero cost for linking
616
616
in an additional LLVM target or other library into an application, but static
617
617
constructors undermine this goal.
@@ -698,7 +698,7 @@ If you use a braced initializer list when initializing a variable, use an equals
698
698
Use ``auto `` Type Deduction to Make Code More Readable
699
699
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
700
700
701
- Some are advocating a policy of "almost always ``auto ``" in C++11, however LLVM
701
+ Some are advocating a policy of "almost always ``auto ``" in C++11; however, LLVM
702
702
uses a more moderate stance. Use ``auto `` if and only if it makes the code more
703
703
readable or easier to maintain. Don't "almost always" use ``auto ``, but do use
704
704
``auto `` with initializers like ``cast<Foo>(...) `` or other places where the
@@ -783,14 +783,14 @@ guards, and might not include their prerequisites. Name such files with the
783
783
784
784
In general, a header should be implemented by one or more ``.cpp `` files. Each
785
785
of these ``.cpp `` files should include the header that defines their interface
786
- first. This ensures that all of the dependences of the header have been
786
+ first. This ensures that all of the dependencies of the header have been
787
787
properly added to the header itself, and are not implicit. System headers
788
788
should be included after user headers for a translation unit.
789
789
790
790
Library Layering
791
791
^^^^^^^^^^^^^^^^
792
792
793
- A directory of header files (for example ``include/llvm/Foo ``) defines a
793
+ A directory of header files (for example, ``include/llvm/Foo ``) defines a
794
794
library (``Foo ``). One library (both
795
795
its headers and implementation) should only use things from the libraries
796
796
listed in its dependencies.
@@ -822,7 +822,7 @@ especially in header files.
822
822
823
823
But wait! Sometimes you need to have the definition of a class to use it, or to
824
824
inherit from it. In these cases go ahead and ``#include `` that header file. Be
825
- aware however that there are many cases where you don't need to have the full
825
+ aware, however, that there are many cases where you don't need to have the full
826
826
definition of a class. If you are using a pointer or reference to a class, you
827
827
don't need the header file. If you are simply returning a class instance from a
828
828
prototyped function or method, you don't need it. In fact, for most cases, you
@@ -970,7 +970,7 @@ loops. A silly example is something like this:
970
970
When you have very, very small loops, this sort of structure is fine. But if it
971
971
exceeds more than 10-15 lines, it becomes difficult for people to read and
972
972
understand at a glance. The problem with this sort of code is that it gets very
973
- nested very quickly. Meaning that the reader of the code has to keep a lot of
973
+ nested very quickly. This means that the reader of the code has to keep a lot of
974
974
context in their brain to remember what is going immediately on in the loop,
975
975
because they don't know if/when the ``if `` conditions will have ``else ``\s etc.
976
976
It is strongly preferred to structure the loop like this:
@@ -988,7 +988,7 @@ It is strongly preferred to structure the loop like this:
988
988
...
989
989
}
990
990
991
- This has all the benefits of using early exits for functions: it reduces nesting
991
+ This has all the benefits of using early exits for functions: it reduces the nesting
992
992
of the loop, it makes it easier to describe why the conditions are true, and it
993
993
makes it obvious to the reader that there is no ``else `` coming up that they
994
994
have to push context into their brain for. If a loop is large, this can be a
@@ -1149,12 +1149,12 @@ In general, names should be in camel case (e.g. ``TextFileReader`` and
1149
1149
nouns and start with an upper-case letter (e.g. ``TextFileReader ``).
1150
1150
1151
1151
* **Variable names ** should be nouns (as they represent state). The name should
1152
- be camel case, and start with an upper case letter (e.g. ``Leader `` or
1152
+ be camel case, and start with an upper- case letter (e.g. ``Leader `` or
1153
1153
``Boats ``).
1154
1154
1155
1155
* **Function names ** should be verb phrases (as they represent actions), and
1156
1156
command-like function should be imperative. The name should be camel case,
1157
- and start with a lower case letter (e.g. ``openFile() `` or ``isFoo() ``).
1157
+ and start with a lower- case letter (e.g. ``openFile() `` or ``isFoo() ``).
1158
1158
1159
1159
* **Enum declarations ** (e.g. ``enum Foo {...} ``) are types, so they should
1160
1160
follow the naming conventions for types. A common use for enums is as a
@@ -1207,7 +1207,7 @@ Assert Liberally
1207
1207
^^^^^^^^^^^^^^^^
1208
1208
1209
1209
Use the "``assert ``" macro to its fullest. Check all of your preconditions and
1210
- assumptions, you never know when a bug (not necessarily even yours) might be
1210
+ assumptions. You never know when a bug (not necessarily even yours) might be
1211
1211
caught early by an assertion, which reduces debugging time dramatically. The
1212
1212
"``<cassert> ``" header file is probably already included by the header files you
1213
1213
are using, so it doesn't cost anything to use it.
@@ -1302,7 +1302,7 @@ preferred to write the code like this:
1302
1302
assert(NewToSet && "The value shouldn't be in the set yet");
1303
1303
1304
1304
In C code where ``[[maybe_unused]] `` is not supported, use ``void `` cast to
1305
- suppress unused variable warning as follows:
1305
+ suppress an unused variable warning as follows:
1306
1306
1307
1307
.. code-block :: c
1308
1308
@@ -1546,7 +1546,7 @@ whenever possible.
1546
1546
The semantics of postincrement include making a copy of the value being
1547
1547
incremented, returning it, and then preincrementing the "work value". For
1548
1548
primitive types, this isn't a big deal. But for iterators, it can be a huge
1549
- issue (for example, some iterators contains stack and set objects in them...
1549
+ issue (for example, some iterators contain stack and set objects in them...
1550
1550
copying an iterator could invoke the copy ctor's of these as well). In general,
1551
1551
get in the habit of always using preincrement, and you won't have a problem.
1552
1552
@@ -1663,7 +1663,7 @@ Don't Use Braces on Simple Single-Statement Bodies of if/else/loop Statements
1663
1663
1664
1664
When writing the body of an ``if ``, ``else ``, or for/while loop statement, we
1665
1665
prefer to omit the braces to avoid unnecessary line noise. However, braces
1666
- should be used in cases where the omission of braces harm the readability and
1666
+ should be used in cases where the omission of braces harms the readability and
1667
1667
maintainability of the code.
1668
1668
1669
1669
We consider that readability is harmed when omitting the brace in the presence
@@ -1763,7 +1763,7 @@ would help to avoid running into a "dangling else" situation.
1763
1763
handleAttrOnDecl(D, A, i);
1764
1764
}
1765
1765
1766
- // Use braces on the outer block because of a nested `if `; otherwise the
1766
+ // Use braces on the outer block because of a nested `if `; otherwise, the
1767
1767
// compiler would warn: `add explicit braces to avoid dangling else `
1768
1768
if (auto *D = dyn_cast<FunctionDecl>(D)) {
1769
1769
if (shouldProcess(D))
0 commit comments