-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Contracts p2900 contract violation #8
Changes from all commits
c424e03
761e5bb
e56f79d
288a0d8
1934d5b
678db53
69cf292
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
// { dg-do run } | ||
// { dg-options "-std=c++2a -fcontracts -fcontracts-nonattr -fcontract-continuation-mode=on" } | ||
#include <iostream> | ||
#include <experimental/contract> | ||
#include "../../../../../libstdc++-v3/include/std/contracts" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that does not look right; |
||
|
||
#define VERIFY_ASSERT(statement, asserts) \ | ||
{ \ | ||
|
@@ -27,12 +27,12 @@ static_assert (__cpp_contracts >= 201906); | |
static_assert (__cpp_contracts_literal_semantics >= 201906); | ||
static_assert (__cpp_contracts_roles >= 201906); | ||
|
||
void handle_contract_violation(const std::experimental::contract_violation &violation) { | ||
void handle_contract_violation(const std::contracts::contract_violation &violation) { | ||
std::cerr << "custom std::handle_contract_violation called:" | ||
<< " " << violation.line_number() | ||
<< " " << violation.file_name() | ||
<< " " << violation.location().line() | ||
<< " " << violation.location().file_name() | ||
<< std::endl; | ||
throw -(int)violation.line_number(); | ||
throw -(int)violation.location().line(); | ||
} | ||
|
||
void foo(int x) pre (x>10){}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// test that contracts on overriding functions are found correctly | ||
// { dg-do run } | ||
// { dg-options "-std=c++2a -fcontracts -fcontract-continuation-mode=on -fcontracts-nonattr " } | ||
|
||
int foo(const int i) pre( i > 3) post (r: r > 4){ | ||
|
||
contract_assert( i > 5); | ||
return i; | ||
}; | ||
|
||
int main(int, char**) | ||
{ | ||
|
||
foo (1); | ||
} | ||
// { dg-output "contract violation in function foo at .*5: i > 3.*(\n|\r\n|\r)" } | ||
// { dg-output ".assertion_kind: pre, semantic: enforce, mode: predicate_false.(\n|\r\n|\r)" } | ||
|
||
// { dg-output "contract violation in function foo at .*7: i > 5.*(\n|\r\n|\r)" } | ||
// { dg-output ".assertion_kind: assert, semantic: enforce, mode: predicate_false.(\n|\r\n|\r)" } | ||
|
||
// { dg-output "contract violation in function foo at .*5: r > 4.*(\n|\r\n|\r)" } | ||
// { dg-output ".assertion_kind: post, semantic: enforce, mode: predicate_false.(\n|\r\n|\r)" } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// { dg-do run } | ||
// { dg-options "-std=c++2a -fcontracts -fcontracts-nonattr" } | ||
#include <stdio.h> | ||
#include <stdarg.h> | ||
int simple_printf(const char* fmt, ...) [[pre : fmt != 0]] [[ post r: r > 0]] | ||
{ | ||
va_list args; | ||
va_start(args, fmt); | ||
|
||
while (*fmt != '\0') { | ||
if (*fmt == 'd') { | ||
int i = va_arg(args, int); | ||
printf("%d\n", i); | ||
} else if (*fmt == 'c') { | ||
// A 'char' variable will be promoted to 'int' | ||
// A character literal in C is already 'int' by itself | ||
int c = va_arg(args, int); | ||
printf("%c\n", c); | ||
} else if (*fmt == 'f') { | ||
double d = va_arg(args, double); | ||
printf("%f\n", d); | ||
} | ||
++fmt; | ||
} | ||
|
||
va_end(args); | ||
|
||
return 6; | ||
} | ||
|
||
int main() | ||
{ | ||
simple_printf("dcff", 3, 'a', 1.999, 42.5); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// These tests cover various crashes found in development | ||
// { dg-do compile } | ||
// { dg-options "-std=c++2a -fcontracts -fcontracts-nonattr -fcontract-continuation-mode=on" } | ||
template<typename T> | ||
struct Base | ||
{ | ||
virtual int f(const int a) pre(i > 5){return a;}; | ||
private: | ||
int i = 2; | ||
}; | ||
|
||
int Base::f(const int a) // { dg-error "used without template arguments" } | ||
{ | ||
return a; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should have a comment here that these need to be kept in sync with libstdc++/src/std{/experimental}/contracts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done