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/C6000-CGT: Constexpr array with not defined size

Part Number: C6000-CGT

Tool/software: TI C/C++ Compiler

Hello,

We started to verify CGT 8.3.7 and noticed following phenomena for this code:

int main()
{
    constexpr char monthFromDate[] = { __DATE__[0], __DATE__[1], __DATE__[2], '\0' };
    
    // Impossible
    if (monthFromDate[0] == 'G')
    {
        return 1;
    }

    return 0;
}

Initially, it caused a flood of errors in our project:

"./main.cpp", line 4: error #28: expression must have a constant value
"./main.cpp", line 4: note #3062-D: attempt to access run-time storage
1 error detected in the compilation of "./main.cpp".

>> Compilation failure

Using "monthFromDate[4]" solved issue. GCC and CLANG compiles it without any problems, but we verified on Compiler's Explorer, that such code can cause the same problems, when Intel C++ Compiler is used (x86-64 icc 19.0.1). To keep portability, we would like to ensure, that this is not a bug, but rather implementation-defined behaviour. We are also curious about compiler's logic, which leads to this error.

Sample code with used command attached.ConstExprArrayTest.zip

Best Regards,

ZD

  • I don't know why the compiler issues this diagnostic ...

    Zbigniew Duszeńczuk said:
    "./main.cpp", line 4: error #28: expression must have a constant value

    So I filed the entry EXT_EP-9855 to have this investigated.  You are welcome to follow it with the link below in my signature.

    Thanks and regards,

    -George