Skip to content

Commit d8935b4

Browse files
Merge pull request gcc-mirror#70 from NinaRanns/template_conversion_ice
Fixing an ICE with dependent contract conditions
2 parents bf10037 + 7f29de4 commit d8935b4

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
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

gcc/testsuite/g++.dg/contracts/contracts-conversion1.C

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
// { dg-do compile }
44
// { dg-options "-std=c++2a -fcontracts" }
55

6+
struct Z {};
67

78
template<typename T>
8-
void fn()
9-
[[ pre: T{} ]] // { dg-error "no match" }
9+
void fn(T t)
10+
[[ pre: t ]] // { dg-error "could not convert" }
1011
{
1112
}
1213

13-
struct Z { };
1414

1515
int main(int, char**) {
16-
fn<int>();
17-
fn<Z>();
16+
fn(1);
17+
fn(Z{});
1818
return 0;
1919
}
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)