This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/CCSTUDIO: max() with enum element and matching indexed array remarks about signed/unsigned comparison #2142-D

Part Number: CCSTUDIO

Tool/software: TI C/C++ Compiler

There seems to be a small hole in the type checking whereby using the max() macro (from the gcc Typeof docs) results in a remark about signed/unsigned comparison.  Only line 51 is flagged.

#include <stdint.h>


#define max(a,b) \
   ({ __typeof__ (a) _a = (a); \
       __typeof__ (b) _b = (b); \
     _a > _b ? _a : _b; })

typedef enum
{
    AE0 = 0,
    AE1 = 1
} AnonymousEnumeration_t;

typedef enum NamedEnumeration_e
{
    NE0,
    NE1
} NamedEnumeration_t;

enum PostNamedEnumeration_e
{
    PNE0,
    PNE1
};
typedef enum PostNamedEnumeration_e PostNamedEnumeration_t;


AnonymousEnumeration_t AEa[3] = {};

int f() {
    uint16_t x = 5;
    __typeof__(x) y = x;
    __typeof__(x) z = max(x, y);

    AnonymousEnumeration_t a = max(AE0, AE0);
    AnonymousEnumeration_t b = max(AE0, AE1);

    AnonymousEnumeration_t c = max(AE0, AE0);
    __typeof__(c) d = max(AE0, AE1);

    AnonymousEnumeration_t e = AE0;
    __typeof__(e) f = e;
    __typeof__(e) g = max(e, f);

    AnonymousEnumeration_t h = max(AEa[0], AEa[1]);
    AnonymousEnumeration_t i = AE1;
    AnonymousEnumeration_t j = max(i, AEa[1]);
    // /opt/ti/ccsv8/tools/compiler/ti-cgt-c2000_18.1.2.LTS/bin/cl2000 --include_path='/opt/ti/ccsv8/tools/compiler/ti-cgt-c2000_18.1.2.LTS/include' --issue_remarks --display_error_number test.c
    // "test.c", line 51: remark #2142-D: comparison between signed and unsigned operands
    AnonymousEnumeration_t k = max(AE1, AEa[1]);
    __typeof__(AEa[1]) l = AEa[1];
    AnonymousEnumeration_t m = max(l, AEa[1]);

    return x + y + z + a + b + c + d + e + f + g + h + i + j + k + l + m;
}

(edit: Sorry, the original file above was a mixed run with the 18.1.2 compiler but the 18.1.1 include path. From what I saw it was the same in both 18.1.1 and 18.1.2. For completeness, I have updated it to be a copy run with 18.1.2 compiler and include path.)