Noexcept operator and enable_if_t: do they work together?

Consider the following class:

struct S { template<typename T> std::enable_if_t<std::is_void<T>::value> f() noexcept {} template<typename T> std::enable_if_t<not std::is_void<T>::value> g() noexcept {} }; 

As expected, this compiles:

 sf<void>(); 

This is not instead of:

 sg<void>(); 

I am puzzled by the following main command with GCC (6.2) and it does not compile with clang (3.9):

 int main() { static_assert(noexcept(&S::f<void>), "!"); static_assert(noexcept(&S::g<void>), "!"); } 

I would say that the second statement failed due to invalid specialization. These two compilers do not agree with this.

Which one is correct?

+5
source share
1 answer

[except.spec] / 13 :

The set of potential exceptions of the expression e empty if e is (5.20).

That is, GCC does not even allow the template identifier, because it is known from get-go that the result is true (since g<void> not a static data element template whose type has an overloaded operator& ). Being smart, the behavior does not meet the requirements, since any appearance of the template identifier entails the replacement of arguments in the declaration of the function template.

+3
source

Source: https://habr.com/ru/post/1258495/


All Articles