Uploaded image for project: 'Qt Creator'
  1. Qt Creator
  2. QTCREATORBUG-9535

Comments in macros between arguments cause errors to appear

XMLWordPrintable

    • a341094a684fa304a2da1003aa8edd1d9226c58d

      Hi,

      after this change:
      https://codereview.qt-project.org/#change,58405

      I started seeing some issues with macros. If macro has multiple arguments, and you place comments between them, they cause false errors to appear

      here is the code:

      #define MACRO_NUM_1    (17)
      #define MACRO_NUM_2    (21)
      
      bool
      someFunct(void *a, const char *b,
                   struct somethingElse *c,
                   struct somethingElse *d)
      {
         /* do something and Always return True   */
         return true;
      }
      
      extern struct somethingElse *someExternStruct;
      
      
      #define MACRO1(a) /* comment */\
        ( __builtin_expect(!!(a), 0) )
      
      
      #define MACRO2(a, /* comment breaker 2 */\
                     b)   /* comment */\
        ( __builtin_expect(!!(a == b), 0) )
      
      #define MACRO3(a,/* comment breaker 1 */  \
         b,/* comment breaker 1 */\
         c) /* comment that  */ \
           (void)(MACRO2(a, MACRO_NUM_1) &&\
              MACRO1(MACRO_NUM_2) &&\
              someFunct(b, c,\
                        someExternStruct,\
                        somethingUnknown ## a ## _p))
      
      #define NSS_TUHWIF_REF_INTERRUPT 10
      
      
      int main()
      {
          int * pointer;
      
          MACRO3(UNKNOWN_MACRO,
                 pointer,
                 "NSS_TUHWIF_REF_INTERRUPT");
      }
      
      

      in pictures you can see two errors. One is caused by two comments:

      /* comment breaker 1 */

      if you remove this comments, then another type of error appears, caused by:

      /* comment breaker 2 */

      This one highlights line below then main macro call as error, even if it is comment.

      Regards
      Petar

        1. comment_breaker_1.png
          54 kB
          Petar
        2. comment_breaker_2.png
          85 kB
          Petar
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            orgads Orgad Shaneh
            pperisin Petar
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes