-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
c++: Improve contracts support in modules [PR108205]
Modules makes some assumptions about types that currently aren't fulfilled by the types created in contracts logic. This patch ensures that exporting inline functions using contracts works again with modules. PR c++/108205 gcc/cp/ChangeLog: * contracts.cc (get_pseudo_contract_violation_type): Give names to generated FIELD_DECLs. (declare_handle_contract_violation): Mark contract_violation type as external linkage. (build_contract_handler_call): Ensure any builtin declarations created here aren't treated as attached to the current module. gcc/testsuite/ChangeLog: * g++.dg/modules/contracts-5_a.C: New test. * g++.dg/modules/contracts-5_b.C: New test. Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
- Loading branch information
Showing
3 changed files
with
46 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// PR c++/108205 | ||
// Test that the implicitly declared handle_contract_violation function is | ||
// properly matched with a later declaration in an importing TU. | ||
// { dg-additional-options "-fmodules -fcontracts -fcontract-continuation-mode=on" } | ||
// { dg-module-cmi test } | ||
|
||
export module test; | ||
export inline void foo(int x) noexcept [[ pre: x != 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,20 @@ | ||
// PR c++/108205 | ||
// { dg-module-do run } | ||
// { dg-additional-options "-fmodules -fcontracts -fcontract-continuation-mode=on" } | ||
|
||
#include <experimental/contract> | ||
import test; | ||
|
||
bool saw_violation = false; | ||
void handle_contract_violation(const std::experimental::contract_violation& v) { | ||
saw_violation = true; | ||
} | ||
|
||
int main() { | ||
foo(10); | ||
if (saw_violation) | ||
__builtin_abort(); | ||
foo(0); | ||
if (!saw_violation) | ||
__builtin_abort(); | ||
} |