diff options
Diffstat (limited to 'llvm/docs/CodingStandards.rst')
-rw-r--r-- | llvm/docs/CodingStandards.rst | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/llvm/docs/CodingStandards.rst b/llvm/docs/CodingStandards.rst index 65dd794..8677d89 100644 --- a/llvm/docs/CodingStandards.rst +++ b/llvm/docs/CodingStandards.rst @@ -860,27 +860,40 @@ your private interface remains private and undisturbed by outsiders. It's okay to put extra implementation methods in a public class itself. Just make them private (or protected) and all is well. -Use Namespace Qualifiers to Implement Previously Declared Functions -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Use Namespace Qualifiers to Define Previously Declared Symbols +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -When providing an out-of-line implementation of a function in a source file, do -not open namespace blocks in the source file. Instead, use namespace qualifiers -to help ensure that your definition matches an existing declaration. Do this: +When providing an out-of-line definition for various symbols (variables, +functions, opaque classes) in a source file, do not open namespace blocks in the +source file. Instead, use namespace qualifiers to help ensure that your +definition matches an existing declaration. Do this: .. code-block:: c++ // Foo.h namespace llvm { + extern int FooVal; int foo(const char *s); - } + + namespace detail { + class FooImpl; + } // namespace detail + } // namespace llvm // Foo.cpp #include "Foo.h" using namespace llvm; + + int llvm::FooVal; + int llvm::foo(const char *s) { // ... } + class detail::FooImpl { + // ... + } + Doing this helps to avoid bugs where the definition does not match the declaration from the header. For example, the following C++ code defines a new overload of ``llvm::foo`` instead of providing a definition for the existing |