Opened 4 years ago

Last modified 4 years ago

#81 new defect

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 (2)

comment:1 Changed 4 years ago by Rob Schluntz

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 unit is ambiguous now, because it could be T = counter or T = one_t, since you have both ?{}(count &, one_t) and ?{}(counter &, counter). Adding a cast fixes it:

  counter u = (counter)unit();

comment:2 Changed 4 years ago by a3moss

Oh, huh, so counter u = unit(); works with T => one_t, not T => counter, and ?*? isn't defined for one_t. Interesting.

Note: See TracTickets for help on using tickets.