From 78c5bdd8514b7639dffea8d74d96a03ab8b47b38 Mon Sep 17 00:00:00 2001 From: Daniel Cheng Date: Tue, 5 Jul 2022 22:28:56 +0000 Subject: [PATCH] Update C++ style guide. - Include friend types in class declaration order guidance. - Include previously omitted text (due to mismatched tags) about preferring int16_t over short, et cetera. - Function declarations: - Updated guidance for what comments should cover. - Add a C++ attribute example. --- cppguide.html | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/cppguide.html b/cppguide.html index 07e49e9..a7f3224 100644 --- a/cppguide.html +++ b/cppguide.html @@ -1706,7 +1706,7 @@ following order:

  1. Types and type aliases (typedef, using, - enum, nested structs and classes)
  2. + enum, nested structs and classes, and friend types)
  3. Static constants
  4. @@ -2896,6 +2896,17 @@ compiler and architecture.

    +

    +The standard library header <cstdint> defines types +like int16_t, uint32_t, +int64_t, etc. You should always use +those in preference to short, unsigned +long long and the like, when you need a guarantee +on the size of an integer. Of the C integer types, only +int should be used. When appropriate, you +are welcome to use standard types like +size_t and ptrdiff_t.

    +

    We use int very often, for integers we know are not going to be too big, e.g., loop counters. Use plain old int for such things. You @@ -4459,23 +4470,20 @@ declaration:

    are provided in `backticks`, then code-indexing tools may be able to present the documentation better. -
  5. For class member functions: whether the object - remembers reference arguments beyond the duration of - the method call, and whether it will free them or - not.
  6. +
  7. For class member functions: whether the object remembers + reference or pointer arguments beyond the duration of the method + call. This is quite common for pointer/reference arguments to + constructors.
  8. -
  9. If the function allocates memory that the caller - must free.
  10. +
  11. For each pointer argument, whether it is allowed to be null and what happens + if it is.
  12. -
  13. Whether any of the arguments can be a null - pointer.
  14. +
  15. 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?). -
  16. If there are any performance implications of how a +
  17. If there are any performance implications of how a function is used.
  18. - -
  19. If the function is re-entrant. What are its - synchronization assumptions?
  20. - +

    Here is an example:

    @@ -4946,7 +4954,8 @@ void Circle::Rotate(double) {}

    Attributes, and macros that expand to attributes, appear at the very beginning of the function declaration or definition, before the return type:

    -
    ABSL_MUST_USE_RESULT bool IsOk();
    +
      ABSL_ATTRIBUTE_NOINLINE void ExpensiveFunction();
    +  [[nodiscard]] bool IsOk();
     

    Lambda Expressions