Created on 2019-06-19.00:00:00 last changed 33 months ago
The expected behavior of the following example is not clear:
template<class T> struct Y { typedef typename T::value_type blah; void swap(Y<T> &); }; template<class T> void swap(Y<T>& Left, Y<T>& Right) noexcept(noexcept(Left.swap(Right))) { } template <class T> struct Z { void swap(Z<T> &); }; template<class T> void swap(Z<T>& Left, Z<T>& Right) noexcept(noexcept(Left.swap(Right))) { } Z<int> x00, y00; constexpr bool b00 = noexcept(x00.swap(y00)); // Instantiates the Z<int> overload: template void swap<int>(Z<int>&, Z<int>&) noexcept(b00);
The question is whether the explicit instantiation directive also instantiates the Y<int> overload and thus Y<int> (because of the exception specification), which will fail because of the reference to T::value_type with T=int.
According to 14.5 [except.spec] bullet 13.3, one of the contexts in which an exception specification is needed (thus triggering its instantiation) is when:
the exception specification is compared to that of another declaration (e.g., an explicit specialization or an overriding virtual function);
In this example, the declarations of swap must be compared in order to determine which function template is being instantiated, resulting in the instantiation of Y<int>. There is implementation divergence, however, with some accepting the example and some issuing an error for the instantiation of Y<int>.
Rationale (February, 2022): Duplicate of issue 2417.
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-02-18 07:47:23 | admin | set | status: open -> dup |
2019-06-19 00:00:00 | admin | create |