diff --git a/cppguide.html b/cppguide.html index 7c6db3c..c5c7b98 100644 --- a/cppguide.html +++ b/cppguide.html @@ -346,8 +346,21 @@ void test(D* x) { f(x); } // Calls f(B*)

-

Try to avoid forward declarations of entities -defined in another project.

+

Do not use forward declarations of entities that your project + does not own.

+ +

For entities that you do own: +

Defining Functions in Header Files

@@ -718,7 +731,7 @@ namespace librarian { namespace internal { // Internal, not part of the API. namespace sidetable = ::pipeline_diagnostics::sidetable; -} // namespace internal +} inline void my_inline_function() { // Local to a function. @@ -1583,7 +1596,7 @@ methods); all other inheritance is "implementation inheritance".

-

Implementation inheritance reduces code size by re-using +

Implementation inheritance reduces code size by reusing the base class code as it specializes an existing type. Because inheritance is a compile-time declaration, you and the compiler can understand the operation and detect @@ -1880,7 +1893,9 @@ In some cases reference parameters can bind to temporaries, leading to lifetime bugs. Instead, find a way to eliminate the lifetime requirement (for example, by copying the parameter), or pass retained parameters by pointer and document the lifetime and non-null requirements. -See TotW 116 for more.

+See TotW 116 for more. + +

When ordering function parameters, put all input-only parameters before any output parameters. In particular, @@ -2091,6 +2106,33 @@ C++ that may differ from what you see elsewhere.

+

cpplint

+ +

Use cpplint.py to detect style errors.

+ +

cpplint.py +is a tool that reads a source file and identifies many +style errors. It is not perfect, and has both false +positives and false negatives, but it is still a valuable +tool.

+ + + +
+

Some projects have instructions on +how to run cpplint.py from their project +tools. If the project you are contributing to does not, +you can download + +cpplint.py separately.

+
+ + + + + +

Other C++ Features

+

Ownership and Smart Pointers

Prefer to have single, fixed owners for dynamically @@ -2218,31 +2260,6 @@ do use shared ownership, prefer to use

Never use std::auto_ptr. Instead, use std::unique_ptr.

-

cpplint

- -

Use cpplint.py to detect style errors.

- -

cpplint.py -is a tool that reads a source file and identifies many -style errors. It is not perfect, and has both false -positives and false negatives, but it is still a valuable -tool.

- - - -
-

Some projects have instructions on -how to run cpplint.py from their project -tools. If the project you are contributing to does not, -you can download - -cpplint.py separately.

-
- - - -

Other C++ Features

-

Rvalue References

Use rvalue references only in certain special cases listed below.

@@ -2292,7 +2309,7 @@ rules apply. Such a reference is called a forwarding reference.

+

Third-party Libraries

+ +

When choosing to use third-party libraries, be consistent with the code + around you.

+ +

+

A third-party library is a library that is not primarily developed in the + same repository as your code.

+ +

+ + +

+ + +

+

When choosing a library to solve a particular problem, first check if there's + already a library that your codebase typically uses for that kind of problem. + If so, use it. If not, prefer libraries from the following sources, in roughly + decreasing order of priority:

+ + + +

If you choose to use a third-party library, make sure to follow + + your codebase's policies for third-party code.

+

Nonstandard Extensions

Nonstandard extensions to C++ may not be used unless otherwise specified.

@@ -4546,7 +4548,7 @@ class members, which should follow the rules for private: std::string table_name_; // OK - underscore at end. - static Pool<TableInfo>* pool_; // OK. + static Pool<TableInfo>* absl_nullable pool_; // OK. }; @@ -4559,7 +4561,7 @@ the trailing underscores that data members in classes have.

struct UrlTableProperties {
   std::string name;
   int num_entries;
-  static Pool<UrlTableProperties>* pool;
+  static Pool<UrlTableProperties>* absl_nullable pool;
 };
 
@@ -4846,8 +4848,10 @@ declaration:

call. This is quite common for pointer/reference arguments to constructors. -
  • For each pointer argument, whether it is allowed to be null and what happens - if it is.
  • +
  • For each pointer argument, whether it is allowed + to be null and what happens if it is.
  • + +
  • For each output or input/output argument, what happens to any state that argument is in (e.g., is the state appended to or overwritten?). @@ -5651,6 +5655,8 @@ int* GetPointer(); std::vector<char*> // Note no space between '*' and '>' + +

    It is allowed (if unusual) to declare multiple variables in the same declaration, but it is disallowed if any of those have pointer or reference decorations. Such declarations are easily misread.

    @@ -5792,11 +5798,12 @@ needed) is:

    public: // Note the 1 space indent! MyClass(); // Regular 2 space indent. explicit MyClass(int var); + MyClass(const MyClass& other); + MyClass& operator=(const MyClass& other); ~MyClass() {} void SomeFunction(); - void SomeFunctionThatDoesNothing() { - } + void SomeFunctionThatDoesNothing() {} void set_some_var(int var) { some_var_ = var; } int some_var() const { return some_var_; }