Opened 3 months ago
Closed 3 months ago
#298 closed defect (fixed)
Return cast does not work with variables
Reported by: | mlbrooks | Owned by: | |
---|---|---|---|
Priority: | minor | Component: | cfa-cc |
Version: | 1.0 | Keywords: | resolver cast |
Cc: |
Description ¶
forall ( T * ) void f( T & ) { printf("%zd\n", sizeof(T)); } int foo () { return 42; } double foo () { return 3.14; } int bar = 42; double bar = 3.14; int main() { f( (return int) foo() ); // ok f( (return double) foo() ); // ok #ifndef HIDE_PROBLEM f( (return int) bar ); // ambiguous f( (return double) bar ); // ambiguous #endif return 0; }
Actual: Error "cannot choose between 2 alternatives" at both lines commented "ambiguous"
Expected: Runs and prints 4, 8, 4, 8
Change History (3)
comment:1 Changed 3 months ago by
comment:2 Changed 3 months ago by
#include <limits.hfa> int main() { unsigned int max_value = (return int)MAX; printf("%u\n", max_value); }
Prints 4294967295 but should print 2147483647. I was just creating another example that I thought would present well (getting a limit of a smaller type in a larger type seems nice). I was surprised that it didn't result in an ambiguous situation but instead the cast seemed to be ignored and it used the cast's context to resolve.
comment:3 Changed 3 months ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
Note: See
TracTickets for help on using
tickets.
I missed this use case when I implemented the return cast, as I didn't think it can be used on variables, and only put the relevant code in UntypedExpr? aka unresolved function calls.