Skip to content

Commit a28b943

Browse files
committed
Fixing an ICE with dependent contract conditions
1 parent a44feeb commit a28b943

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

gcc/cp/pt.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12060,7 +12060,15 @@ tsubst_contract (tree decl, tree t, tree args, tsubst_flags_t complain,
1206012060
CONTRACT_CONDITION (r)
1206112061
= tsubst_expr (CONTRACT_CONDITION (t), args, complain, in_decl);
1206212062

12063+
/* The condition is converted to bool. */
12064+
CONTRACT_CONDITION (r) = finish_contract_condition (CONTRACT_CONDITION (r));
12065+
1206312066
/* And the comment. */
12067+
/* TODO : this does not do anything at the moment. The CONTRACT_COMMENT is
12068+
(currently) a string literal, built from the string of the contract.
12069+
There is nothing to substitute. If we wanted to rebuild the
12070+
CONTRACT_COMMENT from the substituted contract tree, we would need to
12071+
modify how a CONTRACT_COMMENT is built. */
1206412072
CONTRACT_COMMENT (r)
1206512073
= tsubst_expr (CONTRACT_COMMENT (r), args, complain, in_decl);
1206612074

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// check that dependent contract check does not cause an ICE
2+
// { dg-do run }
3+
// { dg-options "-std=c++2a -fcontracts -fcontracts-nonattr -fcontract-evaluation-semantic=observe " }
4+
template <typename ST>
5+
struct S{
6+
7+
int* check() const
8+
{
9+
static int i = 6;
10+
return &i;
11+
}
12+
13+
template <typename T>
14+
T* tcheck(T) const{
15+
static T t;
16+
return nullptr;
17+
}
18+
19+
void f() pre(check()) pre(tcheck(1)){
20+
}
21+
22+
template <typename T>
23+
void f(T t) pre(check()) pre(tcheck(1)) pre(tcheck<T>(t)){
24+
}
25+
26+
};
27+
28+
int main() {
29+
S<int> s;
30+
s.f();
31+
s.f(1);
32+
}

0 commit comments

Comments
 (0)