cplusplus / draft

C++ standards drafts
http://www.open-std.org/jtc1/sc22/wg21/
5.69k stars 751 forks source link

[temp.over.link] types involving template parameters are not expressions [CWG2584] #5388

Open xmh0511 opened 2 years ago

xmh0511 commented 2 years ago

Two declarations correspond if they (re)introduce the same name, both declare constructors, or both declare destructors, unless

  • [...]
  • both declare function templates with equivalent non-object-parameter-type-lists, return types (if any), template-heads, and trailing requires-clauses (if any), and, if both are non-static members, they have corresponding object parameters.

we define whether two types are equivalent in [temp.over.link] p6, which says

When determining whether types or type-constraints are equivalent, the rules above are used to compare expressions involving template parameters.

Consider this example:

template<class T>
T fun();

template<class T>
T&& fun();

In this example, their return types are T and T&&, which involve template parameters. However, T and T&& are not expressions anyway. According to grammar, they are defined as type-specifier. So, whether two function templates correspond relies on the correct definition of [temp.over.link], the latter seems to be a bit clear in its definition.


Another special case is the conversion function template whose name involves template parameter

struct A{
   template<class T>
   operator T();

   template<class T>
   operator T&&();
};

Such two conversion function templates' names are operator T and operator T&&, respectively. whether they declare the same name or not is unclear in this document. For this issue, I think we may clarify it with the help of equivalent return types.

xmh0511 commented 2 years ago

@jensmaurer CWG2584 only covers the first case(namely, whether two types are equivalent). The second case is not covered(namely, whether two names involving template parameters are the same).

jensmaurer commented 2 years ago

I've fixed CWG2584.

xmh0511 commented 2 years ago

Thanks. Please add T vs. T&& example(if possible). The current added example decltype(T::foo) and decltype(U::foo) may arguably be said to that T::foo and U::foo thereof are expressions(involving template parameters). I want to say T and T&& are just type-specifiers that don't touch expressions at all, which can directly expose the subject.

jensmaurer commented 2 years ago

Done.

xmh0511 commented 2 years ago

Thank you.