[llvm] [NFC][CodingStandard] Extend "Use Namespace Qualifiers" to variables (PR #141289)

Rahul Joshi via llvm-commits llvm-commits at lists.llvm.org
Fri May 23 12:58:24 PDT 2025


https://github.com/jurahul created https://github.com/llvm/llvm-project/pull/141289

Extend the coding standard for defining out-of-line definitions of functions in namespaces to variables as well, and change the wording to use the term definition instead of implementation.

>From ae008ce27a9c274b31a3ce4154f0dc09c357c482 Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Fri, 23 May 2025 12:55:04 -0700
Subject: [PATCH] [NFC][CodingStandard] Extend "Use Namespace Qualifiers" to
 variables

Extend the coding standard for defining out-of-line definitions of
functions in namespaces to variables as well, and change the wording
to use the term definition instead of implementation.
---
 llvm/docs/CodingStandards.rst | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/llvm/docs/CodingStandards.rst b/llvm/docs/CodingStandards.rst
index ad772f69127ad..ed9f8913abad1 100644
--- a/llvm/docs/CodingStandards.rst
+++ b/llvm/docs/CodingStandards.rst
@@ -852,23 +852,27 @@ 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 Variables & Functions
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
-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 of a variable or 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:
 
 .. code-block:: c++
 
   // Foo.h
   namespace llvm {
+  cl::opt<bool> FooOption;
   int foo(const char *s);
   }
 
   // Foo.cpp
   #include "Foo.h"
   using namespace llvm;
+
+  cl::opt<bool> llvm::FooOption(/*...*/);
   int llvm::foo(const char *s) {
     // ...
   }



More information about the llvm-commits mailing list