I have simple code snippet where I'm trying to test for a data-member:
#include <type_traits>
template< typename T0 >
using is_data_member = std::bool_constant< std::is_same_v< std::void_t< T0 >, void > >;
template< typename U,
std::add_pointer_t< std::enable_if_t<
is_data_member< decltype( std::declval< U >().a ) >::value
> > = nullptr >
auto test() {}
struct A { int a; };
struct B {};
int main() {
static_assert( is_data_member< decltype( std::declval< A >().a ) >::value );
// #1: static_assert below fails in both gcc and clang.
// static_assert( is_data_member< decltype( std::declval< B >().a ) >::value );
test< A >();
// #2: test< B >() below fails in gcc, but does not fail in clang?
test< B >();
}
With gcc
everything works as I would expect: compilation error for both #1
and #2
.
But with clang
only #1
fails to compile, while #2
does compile.
Please, see for yourself: code on godbolt.
So the question is, basically, what's going on? I tend to think that clang
has slightly better compliance with the Standard in comparison to gcc
, but in this case it looks to me that clang
is wrong?
Thanks!