doc: Add guidelines for comments in closing braces

This commit is contained in:
Eduardo Almeida
2025-01-21 16:15:16 +00:00
parent bb6183ded8
commit 7adaf06c57

View File

@@ -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 <https://gitlab.com/nsnam/ns-3-dev/-/merge_requests/1899>`_ and
`!2070 <https://gitlab.com/nsnam/ns-3-dev/-/merge_requests/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
=====