[PATCH] clang-tidy checker that enforce proper parentheses in macros

Alexander Kornienko alexfh at google.com
Thu May 21 05:14:00 PDT 2015


A few random issues I noticed on the first couple of pages of results you posted on a different thread:

  ../src/transmit.c:37:25: warning: macro replacement list should be enclosed in parentheses [misc-macro-parentheses]
  #define MKQUERY_ADDB(b) *rqp++= (b)
                          ^

It looks like the check is complaining about  the `rgp` variable, which is not a parameter of the macro.

  ../src/addrfam.c:538:3: warning: macro replacement list should be enclosed in parentheses [misc-macro-parentheses]
    const char *p= dgram + rps->labstart[labnum]; \
    ^

Does it complain about `const`? Then it looks like the same issue as the first one.

  adnstest.c:82:3: warning: macro replacement list should be enclosed in parentheses [misc-macro-parentheses]
    case e: fprintf(stderr,"adns failure: %s: errno=" #e "\n",what); break
    ^
  adnstest.c:82:8: warning: macro argument should be enclosed in parentheses [misc-macro-parentheses]
    case e: fprintf(stderr,"adns failure: %s: errno=" #e "\n",what); break
         ^

Same.

It looks like a frequent case, so fixing this would help fixing lots of false positives.

  ../src/addrfam.c:47:48: warning: macro argument should be enclosed in parentheses [misc-macro-parentheses]
  #define SIN(cnst, sa) ((void)(sa)->sa_family, (cnst struct sockaddr_in *)(sa))
                                                 ^

`cnst` is a parameter of the macro, but parens are not needed (if acceptable) in this context. The rule only makes sense for the macro arguments that can be expressions, so you should try to restrict the check to the cases where macro argument resembles an expression or when the context where the parameter is expanded looks like an expression. I'm not sure how exactly this can be done, and whether it's possible to do this precisely enough, but some cases can definitely be improved.


http://reviews.llvm.org/D9528

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the cfe-commits mailing list