================
@@ -0,0 +1,423 @@
+====================
+Clang-Reorder-Fields
+====================
+
+.. contents::
+
+.. toctree::
+  :maxdepth: 1
+
+:program:`clang-reorder-fields` is a refactoring tool to reorder fields in
+C/C++ structs and classes. This tool automatically updates:
+
+- Field declarations in the record definition
+- Constructor initializer lists in C++ classes
+- Aggregate initialization expressions (both C and C++)
+- Designated initializer lists (C++20)
+
+This can be useful for optimizing memory layout, improving cache performance,
+or conforming to coding standards that require specific field orderings.
+
+Example usage
+-------------
+
+Basic struct reordering
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+Consider this simple struct in `example.c`:
+
+.. code-block:: c
+
+  struct Foo {
+    const int *x;
+    int y;
+    double z;
+    int w;
+  };
+
+  int main() {
+    const int val = 42;
+    struct Foo foo = { &val, 0, 1.5, 17 };
+    return 0;
+  }
+
+To reorder the fields to `z, w, y, x`, run:
+
+.. code-block:: console
+
+  clang-reorder-fields -record-name Foo -fields-order z,w,y,x example.c --
+
+This will reorder both the struct definition and the initialization:
+
+.. code-block:: c
+
+  struct Foo {
+    double z;
+    int w;
+    int y;
+    const int *x;
+  };
+
+  int main() {
+    const int val = 42;
+    struct Foo foo = { 1.5, 17, 0, &val };
+    return 0;
+  }
+
+Namespaced structs
+~~~~~~~~~~~~~~~~~~
+
+For C++ code with namespaces, use the fully-qualified name:
+
+.. code-block:: c++
+
+  namespace bar {
+  struct Foo {
+    const int *x;
+    int y;
+    double z;
+    int w;
+  };
+  }
+
+.. code-block:: console
+
+  clang-reorder-fields -record-name ::bar::Foo -fields-order z,w,y,x 
example.cpp --
+
+For classes defined in the global namespace (without any namespace), you can
+use either the simple class name or prefix it with `::`:
+
+.. code-block:: console
+
+  clang-reorder-fields -record-name Foo -fields-order z,w,y,x example.cpp --
+  # or
+  clang-reorder-fields -record-name ::Foo -fields-order z,w,y,x example.cpp --
+
+C++ constructor initializer lists
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
----------------
EugeneZelenko wrote:

```suggestion
C++ constructor initializer lists
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```

https://github.com/llvm/llvm-project/pull/178446
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to