http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56970
Bug #: 56970
Summary: SFINAE does not apply correctly to sizeof.
Classification: Unclassified
Product: gcc
Version: 4.8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassig...@gcc.gnu.org
ReportedBy: yufanyu...@gmail.com
This code compiles with g++ 4.7.3, clang 3.2, but not g++ 4.8.
Error is:
In substitution of ‘template static constexpr int
has::test(decltype (sizeof (C:: x))) [with C = C; T = foo] [with C = foo]’:
required from ‘const int foobar::value’
required from here
error: invalid use of non-static member function ‘int foo::x()’
#include
#include
template
struct has {
template
constexpr static int test(...) {
return 0;
}
template
constexpr static int test(decltype(sizeof(C::x))) { // Doesn't compile.
return 1; // Is a member variable.
}
template x()))>
constexpr static int test(int) {
return 2; // Is a member function.
}
static const int value = test(0);
};
struct foo {
int x();
};
struct bar {
int x;
};
int main() {
std::cout << has::value << std::endl;
std::cout << has::value << std::endl;
std::cout << has::value << std::endl;
}