C1001: An internal error occurred in the compiler

That should be clear. I am trying to implement distribution sorting and the MSVC compiler is crashing. It seems that the specific case related to my SFINAE, in order to detect a member function, this does not happen unless I pass a pointer to the function or replace has_get_index. This also does not happen if I remove one of the remaining indexer overloads. The problem remains if the sortable has a getIndex() const member.

 1>test.cpp(34): fatal error C1001: An internal error has occurred in the compiler. 1> (compiler file 'msc1.cpp', line 1420) 1> To work around this problem, try simplifying or changing the program near the locations listed above. 

(There are no "locations"). Minimum test case:

 #include <vector> #include <iterator> #include <type_traits> #ifndef HAS_MEM_FUNC //SFINAE (or maybe it is?) #define HAS_MEM_FUNC(name, func) \ template<typename T> \ struct name { \ typedef char yes[1]; \ typedef char no [2]; \ template <typename C> static yes& test( typename C::func ) ; \ template <typename C> static no& test(...); \ static bool const value = sizeof(test<T>(0)) == sizeof(yes); \ } #endif HAS_MEM_FUNC(has_get_index,getIndex); //default indexer undefined template <class T> double indexer(...); //indexer for objects that have a "T::getIndex() const" member template <class T> double indexer(const typename std::enable_if<has_get_index<T>::value,T>::type& b) { return b.getIndex(); }; template<class indexert> void function(indexert indexeri) {} struct sortable {}; int main () { function(indexer<sortable>); //line 34 } 
+6
source share
1 answer

Perhaps this is not what you intended:

 template <typename C> static yes& test( typename C::func ) ; 

With typename you tell the compiler that C::func will be a type. Actually it will be a function, and placing the function name there in the parameter declaration makes no sense.

Perhaps you intend to use typeof instead of typename ?

+5
source

Source: https://habr.com/ru/post/895454/


All Articles