35 lines · cpp
1// RUN: %clangxx_asan %s -o %t2// RUN: %run %t | FileCheck %s3 4// This test tests that declaring a parameter in a catch-block does not produce a false positive5// ASan error on Windows.6 7// This code is based on the repro in https://github.com/google/sanitizers/issues/7498#include <cstdio>9#include <exception>10#include <stdexcept>11 12void throwInFunction() { throw std::runtime_error("test2"); }13 14int main() {15 // case 1: direct throw16 try {17 throw std::runtime_error("test1");18 } catch (const std::exception &ex) {19 puts(ex.what());20 // CHECK: test121 }22 23 // case 2: throw in function24 try {25 throwInFunction();26 } catch (const std::exception &ex) {27 puts(ex.what());28 // CHECK: test229 }30 31 printf("Success!\n");32 // CHECK: Success!33 return 0;34}35