[PATCH] D12359: New warning -Wnonconst-parameter when a pointer parameter can be const

Daniel Marjamäki via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 27 04:49:54 PDT 2015


danielmarjamaki added a comment.

I saw a FP when I looked through the logs today...

Example code:

  void dostuff(int *);
  
  void f(int *p) {
  #ifdef X
      dostuff(p);
  #endif
  
      if (*p == 0) {}
  }

As far as I know there is nothing I can do about this in the checker.

A user could for instance solve this with a macro:

  void dostuff(int *);
  
  #define NONCONST(p)   (void)(0 ? 0 : ++(*p))
  
  void f(int *p) {
      NONCONST(p);
  
  #ifdef X
      dostuff(p);
  #endif
  
      if (*p == 0) {}
  }

Or by using a second pointer:

  void dostuff(int *);
  void f(int *p) {
      int *p2 = p;
  
  #ifdef X
      dostuff(*p2);
  #endif
  
      if (*p2 == 0) {}
  }


http://reviews.llvm.org/D12359





More information about the cfe-commits mailing list