Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Polyspace (Mathworks) for static code analysis
Forum Updated to NodeBB v4.3 + New Features

Polyspace (Mathworks) for static code analysis

Scheduled Pinned Locked Moved Qt Creator and other tools
4 Posts 3 Posters 4.1k Views 1 Watching
  • 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.
  • D Offline
    D Offline
    dana
    wrote on last edited by
    #1

    Has anyone successfully used Polyspace (for static code analysis) with their -QT- Qt project? Ive encountered a few difficulties with the configuration. Im currently getting a compilation error related with -QT- Qt's foreach statement which stops the analysis. Any hints would be really appreciated!

    Here's the error Im getting:
    @
    Limitation: A compound statement cannot be used where an expression is expected
    | (e.g.: #define maxint(a,b) ({int _a = (a), _b = (b); _a > _b ? _a : _b; }))
    | (use : #define max(a,b) ((a) > (b) ? (a) : (b))).
    |This construction is not supported by PolySpace Verifier.
    |The computation has been halted.
    @
    for the code:
    @
    Q_FOREACH(infoVariant, response.value<QVariantList>()){
    @

    1 Reply Last reply
    0
    • D Offline
      D Offline
      Duck
      wrote on last edited by
      #2

      You could probably trick it into reading something different, with the goal to make the result digestible for the tool (even if it's not functional code). Something like #undef Q_FOREACH and
      #define Q_FOREACH(variable, container) for (variable;;) might already be sufficient.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SmartCba
        wrote on last edited by
        #3

        Polyspace for C++ does not accept actually GNU extension compound statement expressions.
        Replace your macro @#define maxint(a,b) ({int _a = (a), _b = (b); _a > _b ? _a : _b; })@ by an inline function:
        @inline int maxint(int a, int b) {int _a = (a), _b = (b); return (_a > _b ? _a : _b); }@

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SmartCba
          wrote on last edited by
          #4

          Facing the limitation when using Q_FOREACH MACRO and a Qt gnu compiler (Q_CC_GNU), it could be possible to replace the MACRO by another:

          • Copy from QtCore/qglobal.h in the configuration file folder
            and rename it mygglobal.h

          • Search for the MACRO Q_FOREACH around line 2244 and replace it with MACRO (use flag of compilation to encapsulate new MACRO definition):
            @#define Q_FOREACH(variable, container)
            QForeachContainer<typeof(container)> container(container);
            for (variable = *container.i;
            !container.brk && container.i != container.e;
            ++container.i)@

          • Relaunch using -include myqglobal.h. Note that it does not work if Q_FOREACH MACRO is used more than one time in same statement.

          1 Reply Last reply
          0

          • Login

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