3

I have run into a corner case and looking for a work around. I am almost sure that it is a compiler bug and I couldn't come up with anything. I have a class which optionally requires a pointer to a member function. To allow it to be optional I made the default value to be nullptr. It was working until I made an unrelated change. In visual studio it now fires "invalid template argument, expected a compile-time constant". It still works in GCC. Here is the working case:

template<class Key_, 
         class Value_, 
         Key_ (Value_::*KeyFn_)() const = nullptr, 
         template <class ...> class Map_ = std::map>
class Hashmap { ... }

Here is the case not working

template<class Key_, 
         class Value_, 
         Key_ (Value_::*KeyFn_)() const = nullptr, 
         template <class ...> class Map_ = std::map, 
         class Comparator_=std::less<Key_>>
class Hashmap { ... }

For some reason I cannot split key retrieval from type, so even though it is tempting to supplying keyfn in constructor, it is not possible. Second version only fails if KeyFn_ is nullptr (or 0). If I give a class member for it, it compiles just fine.

Full source code is also available:

http://sourceforge.net/p/gorgon-ge/code/ci/gscript/tree/

working revision:

http://sourceforge.net/p/gorgon-ge/code/ci/77d287af75c2301fce55ab97ba49362f7ef6d9e0/tree/

I am looking either for a work around, or an explanation if it shouldn't work at all.

Cem Kalyoncu
  • 14,120
  • 4
  • 40
  • 62
  • I think also it is a compiler bug. for *empty* `Hashmap` class, if I change default value of `Comparator_` to `int`, it compiles. If I provide all values (same as default, it compiles), only when I let compiler set `Comparator_` to its default value it fails... – Jarod42 Oct 10 '14 at 19:53
  • Even `std::integral_constant m;` fails with VS-2013 – Jarod42 Oct 10 '14 at 20:52

0 Answers0