Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Warning: Braces Around Empty Body

Warning: Braces Around Empty Body

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 2.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BKBK
    wrote on last edited by kshegunov
    #1

    Ubuntu 16, About box contains, in part: Qt Creator 4.5.0-rc1(4.4.83), Based on Qt 5.10.1
    I am a Qt novice and have been given a working project to modify. Please forgive typos as this is on a stand alone embedded system that cannot be connected to my internet computer. When I initiate a build the Issues tab has numerous errors that appear to be bogus. For example one entry in that tab contains:
    Suggest braces around empty body in an if statement
    … additional text omitted
    I double click on the file name and am taken a file named pdu.c and to this code:

    #ifndef NDEBUG
       if(!pdu)
         coap_log(LOG_CRIT,”coap_new_pdu: cannot allocate memory …”;
    #endif
       return pdu;
    

    In the C and C++ language the IF statement uses the next line of code so unless the code immedidately after the IF is { } there cannot be an empty body.
    How should I interpret this warning?
    My apologies, but I work for the government and the evidently the firewalls distort the display and formatting this post is rather difficult. My COMPOSE box is quite tiny and the code markings appear, to me, inconsistent.

    [Corrected formatting issue ~kshegunov]

    aha_1980A 1 Reply Last reply
    0
    • B BKBK

      Ubuntu 16, About box contains, in part: Qt Creator 4.5.0-rc1(4.4.83), Based on Qt 5.10.1
      I am a Qt novice and have been given a working project to modify. Please forgive typos as this is on a stand alone embedded system that cannot be connected to my internet computer. When I initiate a build the Issues tab has numerous errors that appear to be bogus. For example one entry in that tab contains:
      Suggest braces around empty body in an if statement
      … additional text omitted
      I double click on the file name and am taken a file named pdu.c and to this code:

      #ifndef NDEBUG
         if(!pdu)
           coap_log(LOG_CRIT,”coap_new_pdu: cannot allocate memory …”;
      #endif
         return pdu;
      

      In the C and C++ language the IF statement uses the next line of code so unless the code immedidately after the IF is { } there cannot be an empty body.
      How should I interpret this warning?
      My apologies, but I work for the government and the evidently the firewalls distort the display and formatting this post is rather difficult. My COMPOSE box is quite tiny and the code markings appear, to me, inconsistent.

      [Corrected formatting issue ~kshegunov]

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by aha_1980
      #2

      Hi @BKBK,

      if(!pdu)
           coap_log(LOG_CRIT,”coap_new_pdu: cannot allocate memory …”;
      

      I guess coap_log is no function but a macro, and maybe it is defined to "nothing" (i.e. empty) when you compile, so your if-statement looks like this for the compiler:

      if (!pdu)
        ;
      

      That would explain the warning message. And you have such fun with assertion macros in unit tests also, for example.

      Regards

      PS: This is no Qt problem, but rather a C/C++ edge case.

      Qt has to stay free or it will die.

      1 Reply Last reply
      3
      • B Offline
        B Offline
        BKBK
        wrote on last edited by kshegunov
        #3

        You are right. the phrase "coap_log is surrounded by a light gray box and hovering over it shows: #define coap_log(...), for a few seconds. Following the right click and Follow Symbol Under Cursor leads to an

           define coap_log(...)
        #endif
        

        Evidently something is causing that to not be declared. But, as you noted and implied, that is a question for my predecessor.
        Thank you for taking the time to post.

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved