From 593264ca8ef7bc494c19d8afd2508a67d51f7315 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pa=CC=84vels=20Nadtoc=CC=8Cajevs?= <7645683+bruvzg@users.noreply.github.com> Date: Mon, 14 Apr 2025 19:43:49 +0300 Subject: [PATCH] Clarify auto usage. --- .../development/cpp_usage_guidelines.rst | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/contributing/development/cpp_usage_guidelines.rst b/contributing/development/cpp_usage_guidelines.rst index 9f0032a262e..82eeee110b8 100644 --- a/contributing/development/cpp_usage_guidelines.rst +++ b/contributing/development/cpp_usage_guidelines.rst @@ -84,8 +84,26 @@ Keep in mind hover documentation often isn't readily available for pull request reviewers. Most of the time, reviewers will use GitHub's online viewer to review pull requests. -We chose to forbid ``auto`` instead of allowing it on a case-by-case basis to -avoid having to decide on difficult edge cases. Thank you for your understanding. +The ``auto`` keyword can be used in some special cases, like C++ lambda or Objective-C block +definitions and C++ templates. Please ask before using templates with ``auto`` in a pull request. + +.. code-block:: cpp + + // Full type definitions. + void (*mult64to128)(uint64_t, uint64_t, uint64_t &, uint64_t &) = [](uint64_t u, uint64_t v, uint64_t &h, uint64_t &l) { ... } + void (^JOYSTICK_LEFT)(GCControllerDirectionPad *__strong, float, float) = ^(GCControllerDirectionPad *dpad, float xValue, float yValue) { ... } + + // Less clutter with auto. + auto mult64to128 = [](uint64_t u, uint64_t v, uint64_t &h, uint64_t &l) { ... } + auto JOYSTICK_LEFT = ^(GCControllerDirectionPad *dpad, float xValue, float yValue) { ... } + + // Compare function for different types. + template + constexpr auto MIN(const T1 m_a, const T2 m_b) { + return m_a < m_b ? m_a : m_b; + } + +We chose to forbid ``auto`` in all other cases. Thank you for your understanding. Lambdas ~~~~~~~