http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57111



--- Comment #5 from jb <jb.1234abcd at gmail dot com> 2013-04-30 21:57:00 UTC 
---

(In reply to comment #4)

> gcc has -Wfree-nonheap-object, which works for free but not for delete or

> delete[]. Extending it to these functions seems like a reasonable RFE.



I agree with your suggestion.



gcc(1)

       -Wno-free-nonheap-object

           Do not warn when attempting to free an object that was not

           allocated on the heap.



The above is a non-default option.



$ cat free-test.c

#include <stdlib.h>



int main () {

  int arr[] = {1,2};

  int * p = arr;

  free(p);

  return 0;

}



$ gcc -Wall -o free-test free-test.c 

$ ./free-test                      

Segmentation fault (core dumped)



$ gcc -Wall -Wfree-nonheap-object -o free-test free-test.c

$ ./free-test

Segmentation fault (core dumped)



$ gcc -Wall -Wno-free-nonheap-object -o free-test free-test.c

$ ./free-test

Segmentation fault (core dumped)

$



It seems to me that the option "free-nonheap-object" does not work in gcc.

Reply via email to