>
>
>
V3552. AUTOSAR. Cast should not convert…


V3552. AUTOSAR. Cast should not convert a pointer to a function to any other pointer type, including a pointer to function type.

This diagnostic rule is based on the AUTOSAR (AUTomotive Open System ARchitecture) software development standard.

When a pointer to a function is cast to any other pointer, undefined behavior occurs. Type casting between pointers to functions of incompatible types causes undefined behavior when this function is called.

The code below violates this rule - all four type casts are invalid:

void foo(int32_t x); 
typedef void (*fp)(int16_t x); 

void bar() 
{ 
  fp fp1 = reinterpret_cast<fp>(&foo);
  fp fp2 = (fp)foo;
  void* vp = reinterpret_cast<void*>(fp1);
  char* chp = (char*)fp1;
}

Using such pointers to call the function may potentially cause segmentation errors.

This diagnostic is classified as:

  • AUTOSAR-M5.2.6