diff --git a/doc/contributing/source/coding-style.rst b/doc/contributing/source/coding-style.rst index 2aad07152..664afc576 100644 --- a/doc/contributing/source/coding-style.rst +++ b/doc/contributing/source/coding-style.rst @@ -1064,6 +1064,60 @@ the preceding lines. /// Node container with the Wi-Fi stations NodeContainer wifiStations(3); +Comments in closing braces are generally discouraged, to allow for consistent style +formatting across recent versions of clang-format (see MRs +`!1899 `_ and +`!2070 `_). +This rule may be overridden in cases where the comment improves the code's readability. +For example, in class declarations in files with multiple classes, classes within parent classes, +and inline class functions. +To ensure consistent style formatting, prefer placing the comment marking the end of the class +in a new line before the brace. + +An exception to this rule are the comments in the closing brace of a namespace, +which identifies the corresponding namespace. + +The following examples illustrate the above guidelines. + +.. sourcecode:: cpp + + // File with only one class + + namespace ns3 + { + + int + MyClass::Func(int x) + { + while (...) + { + if (...) + { + } // end if // Do not add this comment + } // end while // Do not add this comment + } // end Func // Do not add this comment + + } // namespace ns3 // Keep this comment + +.. sourcecode:: cpp + + // Example of file with multiple classes, and classes within classes + + class MyClass + { + class InlineClass + { + ... + int var; //!< Some variable + + // end of class InlineClass // This comment is allowed + }; + + ... + + // end of class MyClass // This comment is allowed + }; + Casts =====