Travis Vitek wrote:
Martin Sebor wrote:
Travis Vitek wrote:
Not always. If the template is instantiated the error would not be seen.
The reason I ask is because I couldn't get even a simple SFINAE
test program to compile. I think the program is well-formed even
though gcc 4.3.0 chokes on too (albeit for a different reason --
see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36797)


Hah, I was just filing a nearly identical bug with gcc when I got this
message.

I happened to be playing around with this a little bit earlier today.
You might find this interesting. If I use the pseudo-function
__is_empty() directly, the error message says there is no matching
function, but if I wrap it in a template, I get multiple matches (after
the incomplete class type message I complained about earlier).

This all seems to work when using the trait with a non-template type. If
you want to use a template, it has to be instantiated first. I think I'm
going to put the Edison compiler port on hold for now.

Yeah, it doesn't seem quite stable enough. Let's see what they
come back with, but unless there's something we're missing it
might be best to wait for 3.10. I assume HP aCC 6 isn't any
better?


$ cat t.cpp

template <bool B, class T = void>
struct enable_if {
    typedef T type;
};

template <class T>
struct enable_if<false, T> {
};

#ifdef _TEMPLATE

template <class T>
struct is_empty {
    enum { val = __is_empty(T) };
};

template <class T>
int enabled_if_empty (typename enable_if< is_empty<T>::val>::type* = 0)
{
    return 1;
}

template <class T>
int enabled_if_empty (typename enable_if<!is_empty<T>::val>::type* = 0)
{
    return 0;
}

#else // !_TEMPLATE

template <class T>
int enabled_if_empty (typename enable_if< __is_empty(T)>::type* = 0) {
    return 1;
}

template <class T>
int enabled_if_empty (typename enable_if<!__is_empty(T)>::type* = 0) {
    return 0;
}

#endif // !_TEMPLATE

template <int> struct S { };

#include <assert.h>

//template struct S<1>;

int main () {

    assert (0 == enabled_if_empty< S<1> >());
    assert (1 == enabled_if_empty< long >());

    return 0;
}

$ eccp -A t.cpp
"t.cpp", line 50: error: no instance of overloaded function
"enabled_if_empty"
          matches the argument list
      assert (0 == enabled_if_empty< S<1> >());
      ^

1 error detected in the compilation of "t.cpp".
$ eccp -A -D_TEMPLATE t.cpp
"t.cpp", line 15: error: an incomplete class type is not allowed
      enum { val = __is_empty(T) };
                   ^
          detected during instantiation of class "is_empty<T> [with
T=S<1>]"
                    at line 50

"t.cpp", line 50: error: more than one instance of overloaded function
          "enabled_if_empty" matches the argument list:
            function template "int
                      enabled_if_empty<T>(enable_if<is_empty<T>::val,
                      void>::type *)"
            function template "int
enabled_if_empty<T>(enable_if<<expression>,
                      void>::type *)"
      assert (0 == enabled_if_empty< S<1> >());
      ^

2 errors detected in the compilation of "t.cpp".


Reply via email to