Commit ed45569d authored by Jeff Chapman's avatar Jeff Chapman

Fix contracts feature test macros

parent 6c030ebb
......@@ -1003,9 +1003,6 @@ c_cpp_builtins (cpp_reader *pfile)
cpp_define (pfile, "__cpp_constexpr_dynamic_alloc=201907L");
cpp_define (pfile, "__cpp_impl_three_way_comparison=201907L");
cpp_define (pfile, "__cpp_aggregate_paren_init=201902L");
cpp_define (pfile, "__cpp_contracts=201906L");
cpp_define (pfile, "__cpp_contracts_literal_semantics=201906L");
cpp_define (pfile, "__cpp_contracts_roles=201906L");
}
if (flag_concepts)
{
......@@ -1014,6 +1011,12 @@ c_cpp_builtins (cpp_reader *pfile)
else
cpp_define (pfile, "__cpp_concepts=201507L");
}
if (flag_contracts)
{
cpp_define (pfile, "__cpp_contracts=201906L");
cpp_define (pfile, "__cpp_contracts_literal_semantics=201906L");
cpp_define (pfile, "__cpp_contracts_roles=201906L");
}
if (flag_modules)
{
/* FIXME: get clarification about such a define. */
......
// { dg-do compile }
#ifdef __cpp_contracts
static_assert (false);
#endif
#ifdef __cpp_contracts_literal_semantics
static_assert (false);
#endif
#ifdef __cpp_contracts_roles
static_assert (false);
#endif
// ensure the feature test macros are defined pre c++20 while we still support
// -fcontracts independent of std version
// { dg-do compile { target c++11 } }
// { dg-additional-options "-fcontracts" }
static_assert (__cpp_contracts >= 201906, "__cpp_contracts");
static_assert (__cpp_contracts_literal_semantics >= 201906, "__cpp_contracts_literal_semantics");
static_assert (__cpp_contracts_roles >= 201906, "__cpp_contracts_roles");
int main()
{
int x;
[[assert: x >= 0]];
[[assert default: x < 0]];
[[assert audit: x == 0]];
[[assert axiom: x == 1]];
[[assert: x > 0 ? true : false]];
[[assert: x < 0 ? true : false]];
[[assert ignore: x >= 0]];
[[assert assume: x >= 0]];
[[assert check_never_continue: x >= 0]];
[[assert check_maybe_continue: x >= 0]];
[[assert check_always_continue: x >= 0]];
[[assert %default: x >= 0]];
[[assert default %default: x < 0]];
[[assert audit %default: x == 0]];
[[assert axiom %default: x == 1]];
return 0;
}
// basic test to ensure contracts work pre-c++2a
// { dg-do run { target c++11 } }
// { dg-additional-options "-fcontracts -fcontract-continuation-mode=on" }
int f(int n)
[[ pre: n > 0 ]]
[[ post r: r < 0 ]]
{
[[ assert: n > 0 ]];
return -n;
}
int main()
{
f(-5);
return 0;
}
// { dg-output "default std::handle_contract_violation called: .*.C 6 .*(\n|\r\n|\r)*" }
// { dg-output "default std::handle_contract_violation called: .*.C 9 .*(\n|\r\n|\r)*" }
// { dg-output "default std::handle_contract_violation called: .*.C 7 .*(\n|\r\n|\r)*" }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment