首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C1001:编译器中发生内部错误

C1001:编译器中发生内部错误
EN

Stack Overflow用户
提问于 2011-08-20 06:03:14
回答 1查看 8.9K关注 0票数 6

这应该是不言而喻的。我正在尝试实现一个分布排序,但是MSVC编译器崩溃了。这似乎是我的SFINAE检测成员函数的一个特殊情况,如果我没有将indexert传递给一个函数,或者如果我替换了has_get_index,这似乎不会发生。如果我移除任何剩余的索引器重载,也不会发生这种情况。如果sortable有一个getIndex() const成员,问题仍然存在。

代码语言:javascript
复制
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.

(没有“上面列出的位置”)最小的测试用例是:

代码语言:javascript
复制
#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
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-08-20 06:16:12

这可能不是您想要的:

代码语言:javascript
复制
template <typename C> static yes& test( typename C::func ) ;

使用typename,您可以告诉编译器C::func将是一个类型。实际上,它将是一个函数,在参数声明中放入一个函数名没有任何意义。

您是否打算用typeof代替typename

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7127889

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档