@@ -30,7 +30,7 @@ because the naming and other conventions are dictated by the C++ standard.
3030
3131There are some conventions that are not uniformly followed in the code base
3232(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
3434for the entire codebase to follow the convention, but we explicitly *do not *
3535want patches that do large-scale reformatting of existing code. On the other
3636hand, 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
5050conforming, modern, and portable C++ code as the implementation language of
5151choice.
5252
53- For automation, build-systems and utility scripts Python is preferred and
53+ For automation, build-systems, and utility scripts, Python is preferred and
5454is widely used in the LLVM repository already.
5555
5656C++ Standard Versions
@@ -92,7 +92,7 @@ LLVM support libraries (for example, `ADT
9292<https://github.com/llvm/llvm-project/tree/main/llvm/include/llvm/ADT> `_)
9393implement specialized data structures or functionality missing in the standard
9494library. 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.
9696
9797When both C++ and the LLVM support libraries provide similar functionality, and
9898there 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
325325comments (not necessarily in Doxygen markup) to explain implementation details
326326as needed.
327327
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;
330330automatic documentation processing tools are smart enough to bind the comment
331331to the correct declaration.
332332
@@ -369,7 +369,7 @@ lower-case letter, and finish the last sentence without a period, if it would
369369end in one otherwise. Sentences which end with different punctuation, such as
370370"did you forget ';'?", should still do so.
371371
372- For example this is a good error message:
372+ For example, this is a good error message:
373373
374374.. code-block :: none
375375
@@ -443,7 +443,7 @@ Write your code to fit within 80 columns.
443443There must be some limit to the width of the code in
444444order to allow developers to have multiple files side-by-side in
445445windows 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
447447columns (for example) instead of 80 columns wouldn't add any significant value
448448and would be detrimental to printing out code. Also many other projects have
449449standardized 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
520520The historically common formatting of braced initialization of aggregate
521521variables does not mix cleanly with deep nesting, general expression contexts,
522522function 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
524524in a function call. The formatting rules exactly match those already well
525525understood for formatting nested function calls. Examples:
526526
@@ -607,11 +607,11 @@ Static constructors and destructors (e.g., global variables whose types have a
607607constructor or destructor) should not be added to the code base, and should be
608608removed wherever possible.
609609
610- Globals in different source files are initialized in `arbitrary order
610+ Globals in different source files are initialized in an `arbitrary order
611611<https://yosefk.com/c++fqa/ctors.html#fqa-10.12> `_, making the code more
612612difficult to reason about.
613613
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
615615LLVM as a library. We would really like for there to be zero cost for linking
616616in an additional LLVM target or other library into an application, but static
617617constructors undermine this goal.
@@ -698,7 +698,7 @@ If you use a braced initializer list when initializing a variable, use an equals
698698Use ``auto `` Type Deduction to Make Code More Readable
699699^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
700700
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
702702uses a more moderate stance. Use ``auto `` if and only if it makes the code more
703703readable or easier to maintain. Don't "almost always" use ``auto ``, but do use
704704``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
783783
784784In general, a header should be implemented by one or more ``.cpp `` files. Each
785785of 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
787787properly added to the header itself, and are not implicit. System headers
788788should be included after user headers for a translation unit.
789789
790790Library Layering
791791^^^^^^^^^^^^^^^^
792792
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
794794library (``Foo ``). One library (both
795795its headers and implementation) should only use things from the libraries
796796listed in its dependencies.
@@ -822,7 +822,7 @@ especially in header files.
822822
823823But wait! Sometimes you need to have the definition of a class to use it, or to
824824inherit 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
826826definition of a class. If you are using a pointer or reference to a class, you
827827don't need the header file. If you are simply returning a class instance from a
828828prototyped 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:
970970When you have very, very small loops, this sort of structure is fine. But if it
971971exceeds more than 10-15 lines, it becomes difficult for people to read and
972972understand 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
974974context in their brain to remember what is going immediately on in the loop,
975975because they don't know if/when the ``if `` conditions will have ``else ``\s etc.
976976It is strongly preferred to structure the loop like this:
@@ -988,7 +988,7 @@ It is strongly preferred to structure the loop like this:
988988 ...
989989 }
990990
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
992992of the loop, it makes it easier to describe why the conditions are true, and it
993993makes it obvious to the reader that there is no ``else `` coming up that they
994994have 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
11491149 nouns and start with an upper-case letter (e.g. ``TextFileReader ``).
11501150
11511151* **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
11531153 ``Boats ``).
11541154
11551155* **Function names ** should be verb phrases (as they represent actions), and
11561156 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() ``).
11581158
11591159* **Enum declarations ** (e.g. ``enum Foo {...} ``) are types, so they should
11601160 follow the naming conventions for types. A common use for enums is as a
@@ -1207,7 +1207,7 @@ Assert Liberally
12071207^^^^^^^^^^^^^^^^
12081208
12091209Use 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
12111211caught early by an assertion, which reduces debugging time dramatically. The
12121212"``<cassert> ``" header file is probably already included by the header files you
12131213are using, so it doesn't cost anything to use it.
@@ -1302,7 +1302,7 @@ preferred to write the code like this:
13021302 assert(NewToSet && "The value shouldn't be in the set yet");
13031303
13041304In 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:
13061306
13071307.. code-block :: c
13081308
@@ -1546,7 +1546,7 @@ whenever possible.
15461546The semantics of postincrement include making a copy of the value being
15471547incremented, returning it, and then preincrementing the "work value". For
15481548primitive 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...
15501550copying an iterator could invoke the copy ctor's of these as well). In general,
15511551get in the habit of always using preincrement, and you won't have a problem.
15521552
@@ -1663,7 +1663,7 @@ Don't Use Braces on Simple Single-Statement Bodies of if/else/loop Statements
16631663
16641664When writing the body of an ``if ``, ``else ``, or for/while loop statement, we
16651665prefer 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
16671667maintainability of the code.
16681668
16691669We 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.
17631763 handleAttrOnDecl(D, A, i);
17641764 }
17651765
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
17671767 // compiler would warn: `add explicit braces to avoid dangling else `
17681768 if (auto *D = dyn_cast<FunctionDecl>(D)) {
17691769 if (shouldProcess(D))
0 commit comments