This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/56970] New: SFINAE does not apply correctly to sizeof.


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: unassigned@gcc.gnu.org
        ReportedBy: yufanyufan@gmail.com


This code compiles with g++ 4.7.3, clang 3.2, but not g++ 4.8.
Error is:
In substitution of âtemplate<class C> static constexpr int
has<T>::test(decltype (sizeof (C:: x))) [with C = C; T = foo] [with C = foo]â:
required from âconst int foobar<foo>::valueâ
required from here
error: invalid use of non-static member function âint foo::x()â

#include <string>
#include <iostream>
template <typename T>
struct has {
    template <typename>
    constexpr static int test(...) {
      return 0;
    }
    template <typename C>
    constexpr static int test(decltype(sizeof(C::x))) {  // Doesn't compile.
      return 1;   // Is a member variable.
    }
    template <typename C, int c =
        sizeof(decltype(((C*)nullptr)->x()))>
    constexpr static int test(int) {
      return 2;   // Is a member function.
    }
    static const int value = test<T>(0);
};
struct foo {
    int x();
};
struct bar {
    int x;
};
int main() {
    std::cout << has<int>::value << std::endl;
    std::cout << has<foo>::value << std::endl;
    std::cout << has<bar>::value << std::endl;
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]