Skip to content

Commit 8c03940

Browse files
jurahulLukacma
authored andcommitted
[LLVM][CodingStandard] Extend namespace qualifier rule to variables/classes (llvm#163588)
Extend CS rule to use namespace qualifiers to define previously declared functions to variables and classes as well.
1 parent 2d6e945 commit 8c03940

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

llvm/docs/CodingStandards.rst

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -860,27 +860,40 @@ your private interface remains private and undisturbed by outsiders.
860860
It's okay to put extra implementation methods in a public class itself. Just
861861
make them private (or protected) and all is well.
862862

863-
Use Namespace Qualifiers to Implement Previously Declared Functions
864-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
863+
Use Namespace Qualifiers to Define Previously Declared Symbols
864+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
865865

866-
When providing an out-of-line implementation of a function in a source file, do
867-
not open namespace blocks in the source file. Instead, use namespace qualifiers
868-
to help ensure that your definition matches an existing declaration. Do this:
866+
When providing an out-of-line definition for various symbols (variables,
867+
functions, opaque classes) in a source file, do not open namespace blocks in the
868+
source file. Instead, use namespace qualifiers to help ensure that your
869+
definition matches an existing declaration. Do this:
869870

870871
.. code-block:: c++
871872

872873
// Foo.h
873874
namespace llvm {
875+
extern int FooVal;
874876
int foo(const char *s);
875-
}
877+
878+
namespace detail {
879+
class FooImpl;
880+
} // namespace detail
881+
} // namespace llvm
876882

877883
// Foo.cpp
878884
#include "Foo.h"
879885
using namespace llvm;
886+
887+
int llvm::FooVal;
888+
880889
int llvm::foo(const char *s) {
881890
// ...
882891
}
883892
893+
class detail::FooImpl {
894+
// ...
895+
}
896+
884897
Doing this helps to avoid bugs where the definition does not match the
885898
declaration from the header. For example, the following C++ code defines a new
886899
overload of ``llvm::foo`` instead of providing a definition for the existing

0 commit comments

Comments
 (0)