首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >visual studio 2013中的select_on_container_copy_construction内部错误

visual studio 2013中的select_on_container_copy_construction内部错误
EN

Stack Overflow用户
提问于 2014-04-13 21:49:17
回答 1查看 369关注 0票数 2

我在Visual Studio 2013中遇到内部编译器错误。确切的错误是

代码语言:javascript
复制
c:\program files (x86)\microsoft visual studio 12.0\vc\include\xmemory0(487): fatal error     C1001: An internal error has occurred in the compiler.
2>  (compiler file 'f:\dd\vctools\compiler\utc\src\p2\ehexcept.c', line 1483)
2>   To work around this problem, try simplifying or changing the program near the locations listed above.

这让我在std::allocator_traits的实现中看到了下面的代码:

代码语言:javascript
复制
static _Alloc select_on_container_copy_construction(
    const _Alloc& _Al)
    {   // get allocator to use
    return (_Alloc_select::_Fn(0, _Al));
    }

由此,我认为问题与我为自定义分配器所做的一个实现有关。这个分配器是一个类模板,用于包装我在项目中使用的不符合标准的更简单的分配器(因此需要包装)。封装器如下:

代码语言:javascript
复制
template<class BaseAlloc_, class T_>
    class StdAllocator : public BaseAlloc_ {
    public:
        // Public types
        typedef T_              value_type;
        typedef T_*             pointer;
        typedef const T_*       const_pointer;
        typedef T_&             reference;
        typedef const T_&       const_reference;
        typedef std::size_t     size_type;
        typedef std::ptrdiff_t  difference_type;

    public:
        // Convert an allocator<T_> to allocator<U_>
        template<typename U_>
        struct rebind {
            typedef StdAllocator<BaseAlloc_,U_> other;
        };

    public:
        inline explicit StdAllocator():BaseAlloc_() {}
        inline explicit StdAllocator(BaseAlloc_ _b) :BaseAlloc_(_b) {}
        inline ~StdAllocator() {}
        inline explicit StdAllocator(StdAllocator const& _x) :BaseAlloc_(_x) {}
        template<typename U>
        inline explicit StdAllocator(StdAllocator<BaseAlloc_,U> const&) :BaseAlloc_() {}

        //    address
        inline pointer address(reference r) { return &r; }
        inline const_pointer address(const_reference r) { return &r; }

        //    memory allocation
        inline pointer allocate(size_type _cnt,
            typename std::allocator<void>::const_pointer = 0) {
            return BaseAlloc_::allocate<T_>(_cnt);
        }
        inline void deallocate(pointer _p, size_type _cnt) {
            BaseAlloc_::deallocate(_p,_cnt);
        }

        //    size
        inline size_type max_size() const {
            return std::numeric_limits<size_type>::max() / sizeof(T_);
        }

        //    construction/destruction
        inline void construct(pointer p, const T_& t) { new(p)T_(t); }
        inline void destroy(pointer _p) { 
            _p; // Work around for visual studio incorrect warning
            _p->~T_();
        }

        inline bool operator==(StdAllocator const&) { return true; }
        inline bool operator!=(StdAllocator const& a) { return !operator==(a); }
    };

鉴于Visual Studio没有提供更多信息,我不知道如何解决这个问题。

EN

回答 1

Stack Overflow用户

发布于 2016-03-30 16:22:47

这对我来说很有效。我把它复制到answer中,不是为了窃取它,而是为了暴露它。

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

https://stackoverflow.com/questions/23043545

复制
相关文章

相似问题

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