Stack around the variable '…' was corrupted

徘徊边缘 提交于 2020-06-25 21:24:27

问题


On MSVC 15.8.5 in debug mode I get that

Run-Time Check Failure #2 - Stack around the variable 'insert_into' was corrupted.

Is there a bug in MSVC or have I done something bad?

Runs fine on clang version 6.0.0-1ubuntu2 and clang version 7.0.0-svn341916-1~exp1~20180911115939.26

#include <set>

template <typename... T>
struct Overload : T...
{
//support struct for combining and overloading multiple lambdas
    using T::operator()...;
};
template <typename... T>
Overload(T...)->Overload<T...>;

using BuiltSet = std::set<std::string>;

template <typename... Args>
BuiltSet MakeBuildSet(const Args&... args)
{
//takes a list of arguments if an argument is a 
// BuiltSet each element is added to headers, 
// otherwise the arg itself is added to headers
    BuiltSet headers{};

//Construct a lambda with overloading on if argument is a BuiltSet or not
    const Overload insert_into{
        [](const BuiltSet& h, BuiltSet& headers) {
            headers.insert(h.begin(), h.end());
        },
        [](const auto& arg, BuiltSet& headers) { 
            headers.insert(arg); 
        }
    };
//Fold over arguments applying the lambda on each element
    (insert_into(args, headers), ...);
    return headers;
}

int main(int argc, char** argv)
{
    MakeBuildSet(MakeBuildSet("a", "b", "c"), "a", "b", "c");
    return 0;
}

回答1:


MSVC bug so it is a flaw in the compiler.



来源:https://stackoverflow.com/questions/52833810/stack-around-the-variable-was-corrupted

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!