llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.15k stars 12.03k forks source link

[clang-format] [request] Align trailing return types #105782

Open EmrecanKaracayir opened 2 months ago

EmrecanKaracayir commented 2 months ago

Is there a style option for aligning trailing return types?

Example:

    auto operator=(const Vector2&)        noexcept -> Vector2& = default;
    auto operator=(Vector2&&)             noexcept -> Vector2& = default;
    auto operator+=(const Vector2& other) noexcept -> Vector2&;
    auto operator-=(const Vector2& other) noexcept -> Vector2&;
    auto operator*=(const T& scalar)      noexcept -> Vector2&;
    auto operator*=(const Vector2& other) noexcept -> Vector2&;
    auto operator/=(const T& scalar)      noexcept -> Vector2&;
    auto operator/=(const Vector2& other) noexcept -> Vector2&;

    [[nodiscard]] auto operator<=>(const Vector2& other) const noexcept -> std::strong_ordering;
    [[nodiscard]] auto operator+(const Vector2& other)   const noexcept -> Vector2;
    [[nodiscard]] auto operator-(const Vector2& other)   const noexcept -> Vector2;
    [[nodiscard]] auto operator*(const T& scalar)        const noexcept -> Vector2;
    [[nodiscard]] auto operator*(const Vector2& other)   const noexcept -> Vector2;
    [[nodiscard]] auto operator/(const T& scalar)        const noexcept -> Vector2;
    [[nodiscard]] auto operator/(const Vector2& other)   const noexcept -> Vector2;

If there is not a style option currently achieving this, I suggest it should be added because it really helps understanding what a method does when skimming through crowded classes.

Way easier than this:

    auto operator=(const Vector2&) noexcept -> Vector2& = default;
    auto operator=(Vector2&&) noexcept -> Vector2&      = default;
    auto operator+=(const Vector2& other) noexcept -> Vector2&;
    auto operator-=(const Vector2& other) noexcept -> Vector2&;
    auto operator*=(const T& scalar) noexcept -> Vector2&;
    auto operator*=(const Vector2& other) noexcept -> Vector2&;
    auto operator/=(const T& scalar) noexcept -> Vector2&;
    auto operator/=(const Vector2& other) noexcept -> Vector2&;

    [[nodiscard]] auto operator<=>(const Vector2& other) const noexcept -> std::strong_ordering;
    [[nodiscard]] auto operator+(const Vector2& other) const noexcept -> Vector2;
    [[nodiscard]] auto operator-(const Vector2& other) const noexcept -> Vector2;
    [[nodiscard]] auto operator*(const T& scalar) const noexcept -> Vector2;
    [[nodiscard]] auto operator*(const Vector2& other) const noexcept -> Vector2;
    [[nodiscard]] auto operator/(const T& scalar) const noexcept -> Vector2;
    [[nodiscard]] auto operator/(const Vector2& other) const noexcept -> Vector2;
EmrecanKaracayir commented 2 months ago

Currently Clang-Format already does similar aligning for the equals sign (= default, = delete, = 0) after function signatures.