[C ++编译的C ++程序在新运算符过载时崩溃

问题描述 投票:0回答:1

我正在Windows 10上使用Clang版本10.0.0。

此程序

#include <iostream>
// without this operator the program works just fine
void* operator new(std::size_t nrOfBytes) {
    std::cout << "allocate " << nrOfBytes << " bytes on heap" << std::endl;
    void* p = malloc(nrOfBytes);
    if (p) {
        return p;
    } else {
        throw std::bad_alloc{};
    }
}
int main() {
    printf("START\n");
    return 0;
}

使用]编译后,崩溃,返回码-1073741819>

clang ++ Main.cpp -std = c ++ 17

当然,当没有重载的新运算符时,对clang的完全相同的调用会生成无错误的程序。

有任何提示吗?

我在Windows 10上使用的是Clang版本10.0.0。

c++ clang clang++
1个回答
0
投票
尝试从“新”中删除cout操作。可能某些流操作需要其他“新”功能?
© www.soinside.com 2019 - 2024. All rights reserved.