[llvm] 900ea21 - [NFC][CodingStandard] Add additional example for if-else brace rule (#111733)

via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 11 05:25:17 PDT 2024


Author: Rahul Joshi
Date: 2024-10-11T05:25:12-07:00
New Revision: 900ea21ffb38ba5b783b20f394c43c6c89d58086

URL: https://github.com/llvm/llvm-project/commit/900ea21ffb38ba5b783b20f394c43c6c89d58086
DIFF: https://github.com/llvm/llvm-project/commit/900ea21ffb38ba5b783b20f394c43c6c89d58086.diff

LOG: [NFC][CodingStandard] Add additional example for if-else brace rule (#111733)

Add example to document that single statement `else` needs a brace if
the associated `if` needs a brace.

Added: 
    

Modified: 
    llvm/docs/CodingStandards.rst

Removed: 
    


################################################################################
diff  --git a/llvm/docs/CodingStandards.rst b/llvm/docs/CodingStandards.rst
index 63df5af2523db6..87bbb3d127ad51 100644
--- a/llvm/docs/CodingStandards.rst
+++ b/llvm/docs/CodingStandards.rst
@@ -1713,6 +1713,14 @@ would help to avoid running into a "dangling else" situation.
     handleOtherDecl(D);
   }
 
+  // Use braces for the `else` block to keep it uniform with the `if` block.
+  if (isa<FunctionDecl>(D)) {
+    verifyFunctionDecl(D);
+    handleFunctionDecl(D);
+  } else {
+    handleOtherDecl(D);
+  }
+
   // This should also omit braces.  The `for` loop contains only a single
   // statement, so it shouldn't have braces.  The `if` also only contains a
   // single simple statement (the `for` loop), so it also should omit braces.


        


More information about the llvm-commits mailing list