AutosarC++17_03-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 271687 2017-03-23 08:57:35Z piotr.tanski $
#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 [8]: 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