Opened 8 years ago
Closed 3 years ago
#81 closed defect (invalid)
Resolution Failure on Pass-by-value
| Reported by: | a3moss | Owned by: | |
|---|---|---|---|
| Priority: | major | Component: | cfa-cc |
| Version: | 1.0 | Keywords: | |
| Cc: |
Description
If the two commented lines in the following code are un-commented, this code fails to resolve, apparently because the T ?*? (T, T); constraint can't be satisfied. Everything else appears to work (this may be related to #8).
struct counter { int x; };
void ?{} (counter& c, one_t) {
c.x = 1;
}
forall(otype T | { void ?{} (T&, one_t); })
T unit() {
T u = 1;
return u;
}
counter ?*? (counter a, counter b) {
return (counter){ a.x * b.x };
}
forall(otype T | { T ?*? (T, T); })
T square(T x) { return x * x; }
int main() {
counter c = 1;
printf("%d\n", c.x);
counter u = unit();
printf("%d\n", u.x);
counter p = c * u;
printf("%d\n", p.x);
// counter s = square(c);
// printf("%d\n", s.x);
}
Change History (3)
comment:1 by , 8 years ago
comment:2 by , 8 years ago
Oh, huh, so counter u = unit(); works with T => one_t, not T => counter, and ?*? isn't defined for one_t. Interesting.
comment:3 by , 3 years ago
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
This code no longer produces the behaviour discussed above.
Note:
See TracTickets
for help on using tickets.
Hm. So I can get this to compile by making a couple of small changes. First, you need to define a default constructor, because it is hidden by the user defined constructor. So add this:
void ?{}(counter &c) {}Second, the call to
unitis ambiguous now, because it could beT = counterorT = one_t, since you have both?{}(count &, one_t)and?{}(counter &, counter). Adding a cast fixes it: