forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
97 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,59 @@ | ||
// ADDITIONAL_COMPILE_FLAGS: -std=c++26 -Xclang -fcontracts -fcontract-evaluation-semantic=enforce -fcontract-group-evaluation-semantic=observe=observe,enforce=enforce | ||
|
||
|
||
#include <contracts> | ||
#include "contracts_test.h" | ||
#include "nttp_string.h" | ||
#include "contracts_support.h" | ||
#include "contracts_handler.h" | ||
#include "test_register.h" | ||
#include <exception> | ||
#include <stdexcept> | ||
|
||
struct A : CAliveCounter<"A"> { | ||
namespace exception_handling { | ||
#define OBSERVE [[clang::contract_group("observe")]] | ||
void foo() { | ||
|
||
}; | ||
contract_assert [[clang::contract_group("observe")]] ((true) ? throw 42 : true); | ||
|
||
|
||
} | ||
|
||
int main() { | ||
ContractHandlerInstaller installer; | ||
installer.install([&]() { | ||
installer.uninstall(); | ||
REGISTER_TEST(test_ex_handling) { | ||
ContractHandlerInstaller CHI; | ||
int called = 0; | ||
CHI.install([&]() { | ||
++called; | ||
assert(std::current_exception()); | ||
}); | ||
contract_assert OBSERVE ((true) ? throw 42 : true); | ||
assert(called); | ||
called = 0; | ||
|
||
}) | ||
{ | ||
A a; | ||
{ | ||
A a2; | ||
CHI.install([&]() { | ||
++called; | ||
assert(!std::current_exception()); | ||
assert(KV<"Local"> == 1); | ||
assert(KV<"Local2"> == 0); | ||
|
||
} | ||
throw 42; | ||
}); | ||
|
||
try { | ||
|
||
[] { | ||
CAliveCounter<"Local"> Local; | ||
contract_assert((CAliveCounter<"Local2">{}, false)); | ||
assert(KV<"Local2"> == 1); | ||
}(); | ||
assert(false); | ||
} catch (int) { | ||
KV<"InCatch">++; | ||
} | ||
} | ||
assert(called == 1); | ||
assert(NC<"Local"> == 0); | ||
assert(KV<"Local2"> == 0); | ||
assert(NC<"InCatch">.consume() == 1); | ||
|
||
}; | ||
|
||
} // namespace exception_handling |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.