cppfront icon indicating copy to clipboard operation
cppfront copied to clipboard

[SUGGESTION][FIX] Add pointer deduce type support

Open filipsajdak opened this issue 3 years ago • 1 comments
trafficstars

Current implementation is not handling deduced pointer types when analysing safety checks.

It means that this code will pass safety checks

i : int = 42;
pi := i&;
pi = 0; // this should trigger error

This change introduce support for deduced pointer types and makes safety checks work with below code:

main: (argc : int, argv : **char) -> int = {
    a:     int = 2;
    pa:   *int = a&;
    ppa: **int = pa&;

    pa = 0; // error

    pa2:= ppa*;
    pa2 = 0; // error

    pa3 := a&;
    pa3 = 0;  // error
    pa3 += 2; // error

    ppa2 := pa2&;
    pa4 := ppa2*;

    pa4 = 0; // error

    pppa := ppa&;
    pa5 := pppa**;
    pa5 = 0; // error

    return a*pa**ppa**; // 8
}

and will cause errors

tests/pointer-to-pointer.cpp2...
pointer-to-pointer.cpp2(6,8): error: = - pointer assignment from null or integer is illegal
pointer-to-pointer.cpp2(9,9): error: = - pointer assignment from null or integer is illegal
pointer-to-pointer.cpp2(12,9): error: = - pointer assignment from null or integer is illegal
pointer-to-pointer.cpp2(13,9): error: += - pointer assignment from null or integer is illegal
pointer-to-pointer.cpp2(18,9): error: = - pointer assignment from null or integer is illegal
pointer-to-pointer.cpp2(22,9): error: = - pointer assignment from null or integer is illegal
  ==> program violates lifetime safety guarantee - see previous errors

Based on https://github.com/hsutter/cppfront/pull/93

filipsajdak avatar Oct 25 '22 01:10 filipsajdak

Pointers from cpp1 are handled here https://github.com/hsutter/cppfront/pull/96

filipsajdak avatar Oct 27 '22 13:10 filipsajdak

Replaced by https://github.com/hsutter/cppfront/pull/196

filipsajdak avatar Jan 03 '23 22:01 filipsajdak