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 #17 from NinaRanns/contracts-nonattr
preparation for P3097R0
- Loading branch information
Showing
24 changed files
with
1,076 additions
and
54 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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,36 @@ | ||
// ensure contracts on friend declarations are a complete class context | ||
// { dg-do run } | ||
// { dg-options "-std=c++2a -fcontracts -fcontract-continuation-mode=on -fcontracts-nonattr" } | ||
|
||
|
||
struct X { | ||
friend void fn0(X x) [[ pre: x.a > 0 ]] { } | ||
|
||
static void fns0(X x) [[ pre: x.a > 0 ]] { } | ||
static void fns1(X x) [[ pre: x.a > 0 ]]; | ||
static void fns2(X x) [[ pre: x.a > 0 ]] ; | ||
|
||
friend void fn(X &x) { x.a = -5; } | ||
|
||
private: | ||
int a{10}; | ||
}; | ||
void X::fns1(X x) { } | ||
void X::fns2(X x) [[ pre: x.a > 0 ]] { } | ||
|
||
int main(int, char**) { | ||
X x; | ||
fn(x); // no contract | ||
|
||
fn0(x); | ||
|
||
X::fns0(x); | ||
X::fns1(x); | ||
X::fns2(x); | ||
return 0; | ||
} | ||
|
||
// { dg-output "contract violation in function fn0 at .*.C:7: .*(\n|\r\n|\r)" } | ||
// { dg-output "contract violation in function X::fns0 at .*.C:9: .*(\n|\r\n|\r)" } | ||
// { dg-output "contract violation in function X::fns1 at .*.C:10: .*(\n|\r\n|\r)" } | ||
// { dg-output "contract violation in function X::fns2 at .*.C:19: .*(\n|\r\n|\r)" } |
32 changes: 32 additions & 0 deletions
32
gcc/testsuite/g++.dg/contracts/cpp26/contracts-multiple-inheritance2.C
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 @@ | ||
// { dg-do compile } | ||
// { dg-options "-std=c++2a -fcontracts -fcontract-continuation-mode=on -fcontracts-nonattr" } | ||
|
||
struct BaseA { | ||
virtual int fun(int n) [[ pre: n > 0 ]] { return -n; } | ||
}; | ||
|
||
struct BaseB { | ||
virtual int fun(int n) [[ pre: n < 0 ]] { return -n; } | ||
}; | ||
|
||
struct Child1 : public BaseA, BaseB { | ||
int fun(int n) [[ pre: n > 0 ]] { return -n; } | ||
}; | ||
|
||
struct Child2 : public BaseA, BaseB { | ||
int fun(int n) [[ pre: n < 0 ]] { return -n; } | ||
}; | ||
|
||
struct Child3 : public BaseA, BaseB { | ||
int fun(int n) { return -n; } | ||
}; | ||
|
||
struct Child4 : public BaseA { | ||
int fun(int n); | ||
}; | ||
|
||
int Child4::fun(int n) [[ pre: n != 0 ]] // { dg-error "declaration adds contracts" } | ||
{ | ||
return -n; | ||
} | ||
|
23 changes: 23 additions & 0 deletions
23
gcc/testsuite/g++.dg/contracts/cpp26/contracts-nested-class1.C
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,23 @@ | ||
// { dg-do compile } | ||
// { dg-options "-std=c++2a -fcontracts -fcontracts-nonattr" } | ||
|
||
void gfn3(int n) [[ pre: n > 0 ]]; | ||
|
||
struct Outer { | ||
struct Inner { | ||
void fn(int n) [[ pre: n > 0 && bob > 1 ]]; | ||
void fn2(int n) [[ pre: n > 0 && bob > 1 ]]; | ||
}; | ||
|
||
void fn(int m) [[ pre: m > 1 ]]; | ||
friend void Inner::fn(int n) [[ pre: n > 0 && bob > 1 ]]; // { dg-error "not declared" } | ||
|
||
friend void gfn(int p) [[ pre: p > 0 ]]; | ||
friend void gfn(int q) [[ pre: q > 1 ]]; // { dg-error "'q' was not declared" } | ||
|
||
friend void gfn2(int q); | ||
friend void gfn2(int p) [[ pre: p > 0 ]] { } // { dg-error "declaration adds contracts" } | ||
|
||
static int bob; | ||
}; | ||
int Outer::bob{-1}; |
38 changes: 38 additions & 0 deletions
38
gcc/testsuite/g++.dg/contracts/cpp26/contracts-nested-class2.C
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,38 @@ | ||
// { dg-do run } | ||
// { dg-options "-std=c++2a -fcontracts -fcontract-continuation-mode=on -fcontracts-nonattr" } | ||
|
||
void gfn3(int n) [[ pre: n > 0 ]]; | ||
|
||
struct Outer { | ||
struct Inner { | ||
void fn(int n) [[ pre: n > 0 && bob > 1 ]]; | ||
}; | ||
|
||
void fn(int m) [[ pre: m > 1 ]]; | ||
|
||
friend void gfn1(int p) [[ pre: p > 0 ]] { } | ||
|
||
friend void gfn2(int p, Outer *) [[ pre: p > 0 ]] { } | ||
|
||
friend void gfn3(int n); | ||
|
||
static int bob; | ||
}; | ||
int Outer::bob{-1}; | ||
|
||
void Outer::Inner::fn(int x) { } | ||
void Outer::fn(int y) { } | ||
|
||
void gfn3(int n) { } | ||
void gfn1(int q); | ||
|
||
int main(int, char **) { | ||
Outer::Inner in; | ||
in.fn(-5); | ||
Outer out; | ||
out.fn(-6); | ||
gfn1(-7); | ||
gfn2(-8, &out); | ||
gfn3(-9); | ||
} | ||
|
Oops, something went wrong.