﻿id	summary	reporter	owner	description	type	status	priority	component	version	resolution	keywords	cc
229	Incorrect implementation of casting to monomorphic	f37yu		"This program attempts to assign a polymorphic function to a compatible monomorphic function pointer. It is allowed by cfa-cpp but produces incorrect C code:


{{{
forall (dtype T | {int asst (T *);}) void foo (T * x) {}

int asst (void *) { return 1; }

void f() {
    void (*bar) (void*);
    bar = foo;
}
}}}

cfa-cpp output:

{{{
void _X3fooQ1_0_0_1__X4asstFi_PBD0__Fv_PBD0__1(__attribute__ ((unused)) signed int (*_X4asstFi_PY1T__1)(void *__param_0), void *_X1xPY1T_1){
}
signed int _X4asstFi_Pv__1(__attribute__ ((unused)) void *__anonymous_object0){
    __attribute__ ((unused)) signed int _X12_retval_assti_1;
    {
        ((void)(_X12_retval_assti_1=1) /* ?{} */);
    }

    return _X12_retval_assti_1;
}
void _X1fFv___1(){
    void (*_X3barFv_Pv__2)(void *__param_0);
    {
        ((void)(_X3barFv_Pv__2=_X3fooQ1_0_0_1__X4asstFi_PBD0__Fv_PBD0__1));
    }

}
}}}

The incompatible type problem is caught by gcc afterwards.

{{{
test.c: In function '_X1fFv___1':
test.c:7:31: warning: assignment to 'void (*)(void *)' from incompatible pointer type 'void (*)(int (*)(void *), void *)' [-Wincompatible-pointer-types]
    7 |     bar = foo;
}}}


"	defect	new	major	cfa-cc	1.0			
