Skip to content

Commit 52f5683

Browse files
authored
Remove non-standard use of std::exception in compiler-rt/test/asan/TestCases/Windows/basic_exception_handling.cpp (#164137)
**Follow up to:** #159618 **Context** The linked PR ^ introduced a new test to ensure that ASan on Windows no longer instruments catch-parameters. This test used a non-standard constructor of `std::exception`,one that accepted strings as their input, which _somehow_ passed the PR CI but would fail to compile on mingw with libc++. This was originally reported by @mstorsjo, in this comment: ``` This testcase fails to compile in mingw environments, with libc++ as a C++ standard library - https://github.com/mstorsjo/llvm-mingw/actions/runs/18608410056/job/53074081871: D:\a\llvm-mingw\llvm-mingw\llvm-project\compiler-rt\test\asan\TestCases\Windows\basic_exception_handling.cpp:11:32: error: no matching conversion for functional-style cast from 'const char[6]' to 'std::exception' 11 | void throwInFunction() { throw std::exception("test2"); } | ^~~~~~~~~~~~~~~~~~~~~~~ C:/llvm-mingw/include/c++/v1/__exception/exception.h:75:25: note: candidate constructor not viable: no known conversion from 'const char[6]' to 'const exception' for 1st argument 75 | _LIBCPP_HIDE_FROM_ABI exception(const exception&) _NOEXCEPT = default; | ^ ~~~~~~~~~~~~~~~~ C:/llvm-mingw/include/c++/v1/__exception/exception.h:74:25: note: candidate constructor not viable: requires 0 arguments, but 1 was provided 74 | _LIBCPP_HIDE_FROM_ABI exception() _NOEXCEPT {} | ^ D:\a\llvm-mingw\llvm-mingw\llvm-project\compiler-rt\test\asan\TestCases\Windows\basic_exception_handling.cpp:16:11: error: no matching conversion for functional-style cast from 'const char[6]' to 'std::exception' 16 | throw std::exception("test1"); | ^~~~~~~~~~~~~~~~~~~~~~~ C:/llvm-mingw/include/c++/v1/__exception/exception.h:75:25: note: candidate constructor not viable: no known conversion from 'const char[6]' to 'const exception' for 1st argument 75 | _LIBCPP_HIDE_FROM_ABI exception(const exception&) _NOEXCEPT = default; | ^ ~~~~~~~~~~~~~~~~ C:/llvm-mingw/include/c++/v1/__exception/exception.h:74:25: note: candidate constructor not viable: requires 0 arguments, but 1 was provided 74 | _LIBCPP_HIDE_FROM_ABI exception() _NOEXCEPT {} | ^ 2 errors generated. Looking at https://en.cppreference.com/w/cpp/error/exception/exception.html, I don't see any std::exception constructor taking a const char* parameter. ``` _from:_ #159618 (comment) **This PR** adjusts the faulty test case to rely on `std::runtime_error`, which contains a standard constructor accepting a string. This should suffice to make the test pass on mingw. I tested this on godbolt: https://godbolt.org/z/M4hPv5Wvx
1 parent 08484d9 commit 52f5683

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

compiler-rt/test/asan/TestCases/Windows/basic_exception_handling.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
// This code is based on the repro in https://github.com/google/sanitizers/issues/749
88
#include <cstdio>
99
#include <exception>
10+
#include <stdexcept>
1011

11-
void throwInFunction() { throw std::exception("test2"); }
12+
void throwInFunction() { throw std::runtime_error("test2"); }
1213

1314
int main() {
1415
// case 1: direct throw
1516
try {
16-
throw std::exception("test1");
17+
throw std::runtime_error("test1");
1718
} catch (const std::exception &ex) {
1819
puts(ex.what());
1920
// CHECK: test1

0 commit comments

Comments
 (0)