Important: Please read the Qt Code of Conduct -

Warning: Braces Around Empty Body

  • 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
         coap_log(LOG_CRIT,”coap_new_pdu: cannot allocate memory …”;
       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]

  • Lifetime Qt Champion

    Hi @BKBK,

         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.


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

  • 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(...)

    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.

Log in to reply