c++ - g++ 4.7 bug with SFINAE + decltype? -


i have constructed following mcve illustrate issue i'm having g++ 4.7. uses sfinae via decltype() determine if functor type can called given argument type (specialized test if functor type can called no arguments when argument type void).

#include <iostream> #include <utility>  template <typename f, typename a> class can_call_functor_impl { private:     typedef char yes[1];     typedef char no[2];      template <typename u>     static auto test(u *)         -> decltype(void(std::declval<u const &>()(std::declval<a &>())),                     std::declval<yes &>());      template <typename>     static no & test(...);  public:     static constexpr bool value = sizeof(test<f>(0)) == sizeof(yes); };  template <typename f> class can_call_functor_impl<f, void> { private:     typedef char yes[1];     typedef char no[2];      template <typename u>     static auto test(u *)         -> decltype(void(std::declval<u const &>()()),                     std::declval<yes &>());      template <typename>     static no & test(...);  public:     static constexpr bool value = sizeof(test<f>(0)) == sizeof(yes); };  template <typename f, typename a> class can_call_functor :     public std::integral_constant<bool, can_call_functor_impl<f, a>::value> {};  class int_functor { public:     void operator()(int) const; };  #define print_exp(e) (std::cout << #e " == " << (e) << std::endl)  int main(void) {     print_exp((can_call_functor<int_functor, int>::value));     print_exp((can_call_functor<int_functor, short>::value));     print_exp((can_call_functor<int_functor, void>::value));     print_exp((can_call_functor<int_functor, double>::value));     print_exp((can_call_functor<int_functor, int_functor>::value)); } 

output on g++ (debian 4.7.2-5) 4.7.2:

(can_call_functor<int_functor, int>::value) == 1 (can_call_functor<int_functor, short>::value) == 1 (can_call_functor<int_functor, void>::value) == 1 (can_call_functor<int_functor, double>::value) == 1 (can_call_functor<int_functor, int_functor>::value) == 1 

this output troubling, expect third , fifth lines have result of 0, , indeed later g++ , clang in agreement should case.

it appears g++ 4.7 evaluates can_call_functor<int_functor, t>::value true t can come with.

i suspect g++ bug specific 4.7, can't find evidence of (these kinds of problems being particularly difficult search on bug trackers), i'm looking definitive answer:

is g++ 4.7 bug, , if there workaround? if it's not bug in g++ bug in code?

is g++ 4.7 bug?

it appears be

on 4.9.1 produced

(can_call_functor<int_functor, int>::value) == 1 (can_call_functor<int_functor, short>::value) == 1 (can_call_functor<int_functor, void>::value) == 0 (can_call_functor<int_functor, double>::value) == 1 (can_call_functor<int_functor, int_functor>::value) == 0 

but can't find evidence of (these kinds of problems being particularly difficult search on bug trackers)

this 1 might bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53788

and if there workaround?

ummm....

i cannot think one

move @ least 4.8? have several gcc installed side-by-side


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -