diff options
| author | Rahul Joshi <rjoshi@nvidia.com> | 2025-10-20 09:34:09 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-20 09:34:09 -0700 |
| commit | 58dd7a60939e1dfc7fe4ff956cbef93d6f14e451 (patch) | |
| tree | 36565a7c8a464a234c9560eac07086e8e43ee73f | |
| parent | a5bab28de7b44df77fe45709f89a96a2b68dd0a8 (diff) | |
| download | llvm-58dd7a60939e1dfc7fe4ff956cbef93d6f14e451.zip llvm-58dd7a60939e1dfc7fe4ff956cbef93d6f14e451.tar.gz llvm-58dd7a60939e1dfc7fe4ff956cbef93d6f14e451.tar.bz2 | |
[LLVM][CodingStandard] Extend namespace qualifier rule to variables/classes (#163588)
Extend CS rule to use namespace qualifiers to define previously declared
functions to variables and classes as well.
| -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 |
