Skip to content

Identical return type considered different in redeclaration with trailing return type and enough templates #91650

@davidstone

Description

@davidstone

The following valid code:

template<bool>
struct enable_if {
	using type = void;
};

template<typename>
struct trait {
	static constexpr bool value = false;
};

template<typename T>
struct s {
  typename enable_if<trait<T>::value>::type assign();
};

template<typename T>
auto s<T>::assign() -> typename enable_if<trait<T>::value>::type {
}

is rejected by clang with

<source>:17:12: error: return type of out-of-line definition of 's::assign' differs from that in the declaration
   17 | auto s<T>::assign() -> typename enable_if<trait<T>::value>::type {
      |            ^
<source>:13:45: note: previous declaration is here
   13 |   typename enable_if<trait<T>::value>::type assign();
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
1 error generated.
Compiler returned: 1

This occurred on clang trunk very recently, so it's not yet showing up on Godbolt: https://godbolt.org/z/KTE7dvcjd

@sdkrystian: It was introduced by 62b5b61.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions