2015-01-06 15 views
11

GCC çalışıyor: Hata, aşağıda test kodu GCC 4.8 (ve 4.7) ile mükemmel çalışıyor 4.8

#include <type_traits> 

template<typename T, T &object, typename... Args> 
struct Functor 
{ 
    template<float (T::*function)(Args...), Args... args> 
    struct Inner 
    { 
     float operator()() const 
     { 
      return (object.*function)(args...); 
     } 
    }; 
}; 

class Object 
{ 
public: 

    float someFunction() 
    { 
     return {}; 
    } 

    float someFunctionWithArgument(int) 
    { 
     return {}; 
    } 
}; 

Object object; 

Functor<Object, object>::template Inner<&Object::someFunction> functor1; 
Functor<Object, object, int>::template Inner<&Object::someFunctionWithArgument, 1> functor2; 

int main() 
{ 

} 

Ancak GCC 4.9 ile bu oldukça yararsız mesaja başarısız olur functor1 nesnelleştirilmesi noktası: Ben functor1 örnekleme, her şey ( functor2) ile çizgiyi yorum yaparsanız

$ g++ -std=c++11 test.cpp 
test.cpp: In instantiation of ‘struct Functor<Object, (* & object)>’: 
test.cpp:33:24: required from here 
test.cpp:7:9: error: wrong number of template arguments (2, should be 1) 
    struct Inner 
     ^
test.cpp:7:9: error: provided for ‘template<class T, T& object, class ... Args> template<float (T::* function)(Args ...), Args ...args> struct Functor<T, object, Args>::Inner’ 
test.cpp:7:9: error: wrong number of template arguments (2, should be 1) 
test.cpp:7:9: error: provided for ‘template<class T, T& object, class ... Args> template<float (T::* function)(Args ...), Args ...args> struct Functor<T, object, Args>::Inner’ 
test.cpp:33:35: error: ‘Inner’ in ‘struct Functor<Object, (* & object)>’ does not name a template type 
Functor<Object, object>::template Inner<&Object::someFunction> functor1; 

çalışıyor.

Bunu nasıl çözeceğine dair bir fikrin var mı?

DÜZENLEME: - Ben GCC tamamen yanlış olup olmadığı konusunda emin bir hundert yüzde değilim https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64514 göreceğiz ...

+0

Rastgele bir bıçak gibi, 'Functor' boş 'Args ...'? Sorun giderse sorun mu var? – Yakk

+1

Neden functor1 ve functor2 bildirimlerinde 'template' var? –

+0

@MarcGlisse - büyük olasılıkla derleyici "(hata iletisi ile)" bunu kaldırdığımda eklediğimde ... –

cevap

2

Ben GCC bir hata bildirdi. Bununla birlikte, problem durumu esas olarak GCC ile aynı davranışı gösterir. Bu kod iyi biçimli görünüyor - Inner herhangi bir şablon argümanları yok olsa bile:

When N is zero, the instantiation of the expansion produces an empty list. Such an instantiation does not alter the syntactic interpretation of the enclosing construct, even in cases where omitting the list entirely would otherwise be ill-formed or would result in an ambiguity in the grammar.

Ama artık bunun yerine bir takma şablonu kullanmayı kodunu değiştirmek durumunda, aniden çalışır:

template <typename... T> 
struct Functor 
{ 
    template <T...> 
    using Inner = void; 
}; 

using type = Functor<>::Inner<>; 

Demo.

template <typename... Args> 
struct Functor 
{ 
    template <Args... args> 
    struct A; 

    template <Args... args> 
    using B = A<args...>; 
}; 

using type = Functor<>::B<>; 

main.cpp:8:24: error: expansion pattern 'args' contains no argument packs

using B = A<args...> 
        ^

Ben GCC "boş" non-tipi şablonuyla temel sorunu olduğunu düşünüyorum: sorununuza bu çözümü uygulamak çalışırken, sadece orijinal hata değil, aynı zamanda bir ikincisini karşılaştınız parametreleri.

İlgili konular