AutosarC++18_10-A8.2.1ΒΆ

When declaring function templates, the trailing return type syntax shall be used if the return type depends on the type of parameters

Required inputs: IR

Rationale

Use of trailing return type syntax avoids a fully qualified return type of a function along with the typename keyword.

Example
// $Id: A8-2-1.cpp 289436 2017-10-04 10:45:23Z michal.szczepankiewicz $
    #include <cstdint>
    template <typename T>
    class A
    {
      public:
        using Type = std::int32_t;

        Type F(T const&) noexcept;
        Type G(T const&) noexcept;
    };
    template <typename T>
    typename A<T>::Type A<T>::F(T const&) noexcept // Non-compliant
    {
        // Implementation
    }
    template <typename T>
    auto A<T>::G(T const&) noexcept -> Type // Compliant
    {
        // Implementation
    }
See Also
  • HIC++ v4.0 [9]: 7.1.7 Use a trailing return type in preference to type disambiguation using typename.

Possible Messages

Key

Text

Severity

Disabled

use_trailing_return

Use trailing return-type syntax for function templates.

None

False

Options