C++ 在std::async中,由于char*异常而导致clang崩溃

C++ 在std::async中,由于char*异常而导致clang崩溃,c++,c++11,exception,C++,C++11,Exception,使用clang++编译以下代码时遇到崩溃: #include <future> #include <iostream> int main() { auto job = [] { throw "failed"; }; auto f = std::async(std::launch::deferred, job); try { f.get(); } catch (const char *&e) {

使用clang++编译以下代码时遇到崩溃:

#include <future>
#include <iostream>

int main() {
    auto job = [] { throw "failed"; };

    auto f = std::async(std::launch::deferred, job);

    try {
        f.get();
    } catch (const char *&e) {
        std::cout << "boom! " << e << '\n';
    }
}
valgrind说:

==10334== 
==10334== Invalid read of size 8
==10334==    at 0x401834: main (in /tmp/a.out)
==10334==  Address 0x60c02a0 is 0 bytes after a block of size 128 alloc'd
==10334==    at 0x4C3147C: memalign (vg_replace_malloc.c:908)
==10334==    by 0x4C31589: posix_memalign (vg_replace_malloc.c:1072)
==10334==    by 0x5121AA0: ??? (in /usr/lib64/libc++abi.so.1.0)
==10334==    by 0x5123BFA: __cxa_rethrow_primary_exception (in /usr/lib64/libc++abi.so.1.0)
==10334==    by 0x4E7D678: std::rethrow_exception(std::exception_ptr) (in /usr/lib64/libc++.so.1.0)
==10334==    by 0x4E7E0F4: std::__1::__assoc_sub_state::copy() (in /usr/lib64/libc++.so.1.0)
==10334==    by 0x4E7E425: std::__1::future<void>::get() (in /usr/lib64/libc++.so.1.0)
==10334==    by 0x4017D0: main (in /tmp/a.out)
==10334== 
==10334== Invalid read of size 1
==10334==    at 0x4C32256: strlen (vg_replace_strmem.c:461)
==10334==    by 0x403DA4: std::__1::char_traits<char>::length(char const*) (in /tmp/a.out)
==10334==    by 0x40373B: std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::operator<< <std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*) (in /tmp/a.out)
==10334==    by 0x40183F: main (in /tmp/a.out)
==10334==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==10334== 
==10334== 
==10334== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==10334==  Access not within mapped region at address 0x0
==10334==    at 0x4C32256: strlen (vg_replace_strmem.c:461)
==10334==    by 0x403DA4: std::__1::char_traits<char>::length(char const*) (in /tmp/a.out)
==10334==    by 0x40373B: std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::operator<< <std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*) (in /tmp/a.out)
==10334==    by 0x40183F: main (in /tmp/a.out)
==10334==  If you believe this happened as a result of a stack
==10334==  overflow in your program's main thread (unlikely but
==10334==  possible), you can try to increase the size of the
==10334==  main thread stack using the --main-stacksize= flag.
==10334==  The main thread stack size used in this run was 8388608.
boom! ==10334== 
更新: 我用各种版本的叮当进行了测试,它总是在叮当声中崩溃。
测试的最后一个版本是10.0.0,仍然崩溃…

在安装clang之后,我与n.m处于相同的情况(谁知道重新安装可能是一个解决方案)。 对于未打印的消息“failed!”,我已通过将第11行替换为以下内容进行了修复:

    } catch (const char* e) {

在安装了clang之后,我和n.m的情况一样(谁知道重新安装可能是一个解决方案)。 对于未打印的消息“failed!”,我已通过将第11行替换为以下内容进行了修复:

    } catch (const char* e) {

在我看来像只叮当作响的虫子。对我来说,当它没有崩溃时,它只打印“砰!”而没有“失败”。在我看来,它就像一只叮当作响的虫子。对我来说,当它没有崩溃时,它只打印“boom!”而不打印“failed”。感谢您的解决方案,但这是否意味着我的代码是错误的?实际上,这只是因为const char*e已经是一个指针。因此,添加一个引用(const char*&e)将给出一个不是const char*的其他对象。仅供参考,我使用clang 8.0.0版。“谁知道重新安装可能是一个解决方案”-为什么重新安装会是一个解决方案?除非你知道解决问题的具体原因,否则这只是猜测(这不是解决问题的方法)。解决问题的方法是从根本上解决问题,然后根据实际知识应用解决方案。请不要只是猜测修复。感谢您的解决方案,但这是否意味着我的代码是错误的?实际上,这只是因为const char*e已经是一个指针。因此,添加一个引用(const char*&e)将给出一个不是const char*的其他对象。仅供参考,我使用clang 8.0.0版。“谁知道重新安装可能是一个解决方案”-为什么重新安装会是一个解决方案?除非你知道解决问题的具体原因,否则这只是猜测(这不是解决问题的方法)。解决问题的方法是从根本上解决问题,然后根据实际知识应用解决方案。请不要只是猜测修复。
$ clang++ --version
clang version 6.0.1 (tags/RELEASE_601/final)
    } catch (const char* e) {