[llvm] 58dd7a6 - [LLVM][CodingStandard] Extend namespace qualifier rule to variables/classes (#163588)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 20 09:34:13 PDT 2025
Author: Rahul Joshi
Date: 2025-10-20T09:34:09-07:00
New Revision: 58dd7a60939e1dfc7fe4ff956cbef93d6f14e451
URL: https://github.com/llvm/llvm-project/commit/58dd7a60939e1dfc7fe4ff956cbef93d6f14e451
DIFF: https://github.com/llvm/llvm-project/commit/58dd7a60939e1dfc7fe4ff956cbef93d6f14e451.diff
LOG: [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.
Added:
Modified:
llvm/docs/CodingStandards.rst
Removed:
################################################################################
diff --git a/llvm/docs/CodingStandards.rst b/llvm/docs/CodingStandards.rst
index 65dd794103ac3..8677d894a94a6 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
More information about the llvm-commits
mailing list