forked from gcc-mirror/gcc
-
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.
Merge pull request gcc-mirror#55 from NinaRanns/noexcept_observe
noexcept_observe
- Loading branch information
Showing
7 changed files
with
122 additions
and
11 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
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 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Test that there is no crash with default contract violation handler and noexcept_observe | ||
// { dg-do compile } | ||
// { dg-options "-std=c++2a -fcontracts -fcontracts-nonattr -fcontract-evaluation-semantic=noexcept_observe " } | ||
|
||
|
||
void f(int i) pre(i > 0){} | ||
|
||
int main() | ||
{ | ||
f(0); | ||
} | ||
|
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//Test that a throwing violation handler causes termination with noexcept-observe | ||
// { dg-do run } | ||
// { dg-options "-std=c++2a -fcontracts -fcontracts-nonattr -fcontract-evaluation-semantic=noexcept_observe " } | ||
#include <experimental/contract> | ||
#include <exception> | ||
#include <cstdlib> | ||
|
||
void my_term() | ||
{ | ||
try { throw; } | ||
catch(int) { std::exit(0); } | ||
} | ||
void handle_contract_violation(const std::experimental::contract_violation& violation) | ||
{ | ||
throw 1; | ||
} | ||
|
||
struct X | ||
{ | ||
void f(const int x) pre(x>1) post(x>3) { | ||
int i = 1; | ||
} | ||
}; | ||
|
||
int main() | ||
{ | ||
std::set_terminate (my_term); | ||
try | ||
{ | ||
X x; | ||
x.f(-42); | ||
} catch (...) { | ||
} | ||
// We should not get here | ||
return 1; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//Test that a throwing violation handler causes termination with noexcept-observe | ||
// { dg-do run } | ||
// { dg-options "-std=c++2a -fcontracts -fcontracts-nonattr -fcontract-evaluation-semantic=noexcept_observe " } | ||
#include <experimental/contract> | ||
#include <exception> | ||
#include <cstdlib> | ||
|
||
void my_term() | ||
{ | ||
try { throw; } | ||
catch(int) { std::exit(0); } | ||
} | ||
|
||
void handle_contract_violation(const std::experimental::contract_violation& violation) | ||
{ | ||
throw 1; | ||
} | ||
|
||
void f(int x) pre(x >= 0) | ||
{ | ||
} | ||
|
||
int main() | ||
{ | ||
std::set_terminate (my_term); | ||
try | ||
{ | ||
f(-42); | ||
} catch (...) {} | ||
// We should not get here | ||
return 1; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//Test that noexcept-observe with a non throwing violation handler has | ||
// observe semantics | ||
// { dg-do run } | ||
// { dg-options "-std=c++2a -fcontracts -fcontracts-nonattr -fcontract-evaluation-semantic=noexcept_observe " } | ||
|
||
int f(const int a, const int b) pre (a > 2) post(r : r > 2){ return 1;}; | ||
|
||
int main(int, char**) | ||
{ | ||
f(1,1); | ||
return 0; | ||
} | ||
|
||
// { dg-output "contract violation in function f at .*: a > 2.*(\n|\r\n|\r)" } | ||
// { dg-output "contract violation in function f at .*: r > 2.*(\n|\r\n|\r)" } |