From dd9b8ee7ef5666b0ba257a40c7c024628f821448 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 1 Jun 2021 08:54:31 +0200 Subject: [PATCH] Documentation: Add rule about "east const" to CodingStyle.md Unfortunately we cannot enforce this with clang-format yet, as that feature is not available. Until then, let's try to write new code with this in mind, and convert old code as we go. --- Documentation/CodingStyle.md | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Documentation/CodingStyle.md b/Documentation/CodingStyle.md index 5c8271ff949..8e12d9d7e9d 100644 --- a/Documentation/CodingStyle.md +++ b/Documentation/CodingStyle.md @@ -396,7 +396,7 @@ struct Thingy { class Doohickey { public: - const String& name() const { return m_name; } + String const& name() const { return m_name; } int frob_count() const { return m_frob_count; } void jam(); @@ -421,7 +421,7 @@ private: class Doohickey { public: - const String& name() const { return this->name; } + String const& name() const { return this->name; } void jam(); @@ -583,3 +583,18 @@ public: } ``` +### Const placement + +[](#east-const) Use "east const" style where `const` is written on the right side of the type being qualified. See [this article](https://mariusbancila.ro/blog/2018/11/23/join-the-east-const-revolution/) for more information about east const. + +###### Right: + +```cpp +Salt const& m_salt; +``` + +###### Wrong: + +```cpp +const Salt& m_salt; +```