Opened 7 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 Changed 7 years ago by
comment:2 Changed 7 years ago by
Oh, huh, so counter u = unit();
works with T => one_t
, not T => counter
, and ?*?
isn't defined for one_t
. Interesting.
comment:3 Changed 3 years ago by
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:
Second, the call to
unit
is ambiguous now, because it could beT = counter
orT = one_t
, since you have both?{}(count &, one_t)
and?{}(counter &, counter)
. Adding a cast fixes it: