Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

not enough arguments for function-like macro invocation 'realloc'



  • I have a problem, including some QtCore libraries in my project. I am using CMake and Visual Studio Qt 5.15. In my CMakeLists.txt I include QtCore like this:

    find_package(Qt5 REQUIRED COMPONENTS Core)
    
    target_link_libraries(${projectName} PRIVATE Qt5::Core)
    

    Then I add:

    #include <qstring.h>
    #include <qfile.h>
    

    in my code and some errors will show up:

    C:\qt\5.15.0\msvc2019_64\include\QtCore\qvector.h(103): warning C4003: not enough arguments for function-like macro invocation 'realloc'
    C:\qt\5.15.0\msvc2019_64\include\QtCore\qvector.h(316): error C2059: syntax error: 'constant'
    C:\qt\5.15.0\msvc2019_64\include\QtCore\qvector.h(327): note: see reference to class template instantiation 'QVector<T>' being compiled
    C:\qt\5.15.0\msvc2019_64\include\QtCore\qvector.h(411): warning C4003: not enough arguments for function-like macro invocation 'realloc'
    C:\qt\5.15.0\msvc2019_64\include\QtCore\qvector.h(420): warning C4003: not enough arguments for function-like macro invocation 'realloc'
    C:\qt\5.15.0\msvc2019_64\include\QtCore\qvector.h(700): error C2988: unrecognizable template declaration/definition
    C:\qt\5.15.0\msvc2019_64\include\QtCore\qvector.h(700): error C2059: syntax error: 'constant'
    C:\qt\5.15.0\msvc2019_64\include\QtCore\qvector.h(1071): warning C4003: not enough arguments for function-like macro invocation 'realloc'
    

    This error is probably issue of defining realloc two times, first in the qstring.h, then in the qfile.h.

    I tried deleting CMake cache, but with no result. This problem most probably has started since migrating from Visual Studio solution to CMake.


  • Lifetime Qt Champion

    Your dev environment is wrong. Fix it. No Qt specfic problem I would guess. Create a simple main.cpp and see if it compiles when you include a Qt header. If not remove the Qt header and try to call realloc() directly by yourself. I would guess you get the same errors then.



  • @gragas said in not enough arguments for function-like macro invocation 'realloc':

    Then I add:
    #include <qstring.h>
    #include <qfile.h>

    This error is probably issue of defining realloc two times, first in the qstring.h, then in the qfile.h.

    Because you are not suppose to include the .h files. They are internal to the framework. You include the <QFile> and <QString> headers.


  • Lifetime Qt Champion

    @Kent-Dorfman said in not enough arguments for function-like macro invocation 'realloc':

    you are not suppose to include the .h files. They are internal to the framework. You include the <QFile> and <QString> headers.

    But this can't lead to the compiler errors.



  • I think it could, and very well may be. constant is obviously an undefined macro and the not enough arguements is probably a consequence of stringing together macro definitions where some are missing and are null or default empty strings.


  • Lifetime Qt Champion

    @Kent-Dorfman said in not enough arguments for function-like macro invocation 'realloc':

    I think it could, and very well may be.

    No, there is no difference when I include qcolor.h or QColor:

    > cat /usr/include/qt5/QtGui/QColor
    #include "qcolor.h"
    


  • The reason this happened was, redefinition of realloc keyword. I had to do push/pop realloc macro for new keyword as well. I Think this issue was solved in Qt 6, but thanks anyway. Refference: https://bugreports.qt.io/browse/QTBUG-40575.


  • Lifetime Qt Champion

    Hi,

    Adding link to the corresponding code review.