public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/109787] New: Warn about contract violations that can be detected at compile time
@ 2023-05-09 12:16 redi at gcc dot gnu.org
2023-05-09 12:17 ` [Bug middle-end/109787] " redi at gcc dot gnu.org
2023-05-09 15:02 ` pinskia at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2023-05-09 12:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109787
Bug ID: 109787
Summary: Warn about contract violations that can be detected at
compile time
Product: gcc
Version: 13.1.0
Status: UNCONFIRMED
Keywords: diagnostic
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: redi at gcc dot gnu.org
Blocks: 87403
Target Milestone: ---
struct array {
int operator[](unsigned n) [[pre: n < 1]] { return 0; }
};
int main() {
array a;
return a[1];
}
When this C++ program is compiled with -fcontracts it will fail at runtime:
contract violation in function array<int, 1>::operator[] at contract.cc:7: n <
N
terminate called without an active exception
Aborted (core dumped)
The front-end inserts a call to this handler when the precondition check fails:
extern "C++" {
void handle_contract_violation (const std::experimental::contract_violation &);
}
It would be nice if the middle-end could notice that the contract handler is
reached on all paths, and so warn. If we can prove we're going to call the
contract violation handler, then we can prove the program is wrong, and we
should warn.
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87403
[Bug 87403] [Meta-bug] Issues that suggest a new warning
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug middle-end/109787] Warn about contract violations that can be detected at compile time
2023-05-09 12:16 [Bug middle-end/109787] New: Warn about contract violations that can be detected at compile time redi at gcc dot gnu.org
@ 2023-05-09 12:17 ` redi at gcc dot gnu.org
2023-05-09 15:02 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2023-05-09 12:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109787
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug middle-end/109787] Warn about contract violations that can be detected at compile time
2023-05-09 12:16 [Bug middle-end/109787] New: Warn about contract violations that can be detected at compile time redi at gcc dot gnu.org
2023-05-09 12:17 ` [Bug middle-end/109787] " redi at gcc dot gnu.org
@ 2023-05-09 15:02 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-09 15:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109787
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Last reconfirmed| |2023-05-09
Status|UNCONFIRMED |NEW
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-05-09 15:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-09 12:16 [Bug middle-end/109787] New: Warn about contract violations that can be detected at compile time redi at gcc dot gnu.org
2023-05-09 12:17 ` [Bug middle-end/109787] " redi at gcc dot gnu.org
2023-05-09 15:02 ` pinskia at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).