简体   繁体   中英

msvs 2013 error C2057 in one computer, no error in another. What's going on?

I have some code that compiles fine in two machine (Windows 8.1, msvs 2013, latest updates etc and Windows 7 64-bit, msvs 2013, latest updates etc) and the SAME code fails to compile in another machine (Windows 7 64-bit, msvs 2013, latest updates etc -- yes, the same as one of the working machines). All machines use the latest platform toolset, the project files are identical as they are generated by CMake files.

I tried to nail it down and make the smallest project possible, but the sample project compiles fine on the problematic machine. For what is worth, below is the example that compiles, I've added a comment in the problematic line.

#include <functional>
#include <vector>
#include <cstdint>

template<class T>
bool container_value_equal(typename T::const_reference v0, typename T::const_reference v1) { return v0 == v1; }

template<class T>
bool unordered_intersection_exists(const T& v0,
    const T& v1,
    // The below line fails in the problem computer + application!
    const std::function< bool(typename T::const_reference, typename T::const_reference)>& f = container_value_equal<T>);


int main()
{
    const std::vector<size_t> * vec2 = nullptr;
    std::vector<size_t> vec;
    const auto& vec_cref = vec;
    unordered_intersection_exists(vec_cref, *vec2);
    return 0;
}


template<class T>
bool unordered_intersection_exists(const T& vec0,
    const T& vec1,
    const std::function< bool(typename T::const_reference, typename T::const_reference)>& f)
{
    for (const auto& v0 : vec0)
        for (const auto& v1 : vec1)
            if (f(v0, v1))
                return true;
    return false;
}

The ONLY difference of the above chunk with the one that's actually called is that the code is located in a static library, not that I would expect that to make any difference. The errors that get generated for my ACTUAL program are the following:

1>E:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\type_traits(1511): error C2057: expected constant expression
1>          E:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\functional(385) : see reference to function template instantiation '_Ty std::forward<_Fty>(remove_reference<_Fty>::type &&) throw()' being compiled
1>          with
1>          [
1>              _Ty=bool (__cdecl &)(T::const_reference,T::const_reference)
1>  ,            _Fty=bool (__cdecl &)(T::const_reference,T::const_reference)
1>          ]
1>          E:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\functional(579) : see reference to function template instantiation 'void std::_Func_class<_Ret,const unsigned int &,const unsigned int &>::_Reset<_Fx(__cdecl &)>(_Fty)' being compiled
1>          with
1>          [
1>              _Ret=bool
1>  ,            _Fx=bool (T::const_reference,T::const_reference)
1>  ,            _Fty=bool (__cdecl &)(T::const_reference,T::const_reference)
1>          ]
1>          E:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\functional(579) : see reference to function template instantiation 'void std::_Func_class<_Ret,const unsigned int &,const unsigned int &>::_Reset<_Fx(__cdecl &)>(_Fty)' being compiled
1>          with
1>          [
1>              _Ret=bool
1>  ,            _Fx=bool (T::const_reference,T::const_reference)
1>  ,            _Fty=bool (__cdecl &)(T::const_reference,T::const_reference)
1>          ]
1>          E:\Programming\GitHub\xxx\yyy\zzz\ddd/eee/fff.h(14) : see reference to function template instantiation 'std::function<bool (const unsigned int &,const unsigned int &)>::function<bool(T::const_reference,T::const_reference)>(_Fx (__cdecl &))' being compiled
1>          with
1>          [
1>              _Fx=bool (T::const_reference,T::const_reference)
1>          ]
1>          E:\Programming\GitHub\xxx\yyy\zzz\aaa\bbb\ccc.cpp(443) : see reference to function template instantiation 'std::function<bool (const unsigned int &,const unsigned int &)>::function<bool(T::const_reference,T::const_reference)>(_Fx (__cdecl &))' being compiled
1>          with
1>          [
1>              _Fx=bool (T::const_reference,T::const_reference)
1>          ]

这不是一个很好的(自我)答案,但我通过不在函数“ bool unordered_intersection_exists(...)”中设置默认参数来解决了该问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM