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.

TMS320F28335: Forcing a compiling error is not working with a template parameter

Part Number: TMS320F28335

Hello everyone,

I'm having problems with what appears to be a compiler error. I have created a structure which allows to detect compiling errors, because when the template parameter is evalueted as true is implemented, and when it is false is only declared, so it launch "error #71: incomplete type is not allowed". This is already working, but if I call it inside a template, is compiling when it shouldn't. 

I'm attaching the project where it can be tested. The code is as follows:

#include <stdint.h>

namespace Test
{
    template<bool b>
    struct Compile_time;

    template<>
    struct Compile_time<true>
    {
        static const uint16_t value = 0;
    };

    template <uint16_t nbits>
    struct Compile_template
    {
       static const bool a = Compile_time<nbits <= 1>::value;
       static const bool b = Compile_time<32 <= 1>::value;      //< This don't compiles (Compiler working)
    };
}

int main(void)
{
    /// Should fail
    Test::Compile_template<32>::a;          //< This compiles (Compiler ISSUE)
    Test::Compile_time<32 <= 1>::value;     //< This don't compiles (Compiler working)

    /// Should compile
    Test::Compile_template<1>::a;           //< This compiles (Compiler working)
    Test::Compile_time<0 <= 1>::value;      //< This compiles (Compiler working)
	return 0;
}

5751.Compiler_error.zip

  • Thank you for notifying us of this problem, and supplying a concise test case.  I am able to reproduce the same behavior.  I filed the issue EXT_EP-10935 to have this investigated.  You are welcome to follow it with that link.

    Thanks and regards,

    -George

  • After analysis, we conclude this is not a bug in the compiler.  The best way to explain why is with an example.  It is similar to yours, but not the same.

    #include <stdint.h>
    
    namespace Test
    {
        template<bool b>
        struct Compile_time;
    
        template<>
        struct Compile_time<true>
        {
            static const uint16_t value = 0;
        };
    
        template <uint16_t nbits>
        struct Compile_template
        {
           static const bool a = Compile_time<nbits <= 1>::value;  // line 17
        };
    }
    
    int main(void)
    {
        return Test::Compile_template<32>::a;                      // line 23
    }

    It has no lines which are present to intentionally demonstrate compile time errors.  The variable created in main is actually used (though in a minimal way).  

    Build it ...

    % cl2000 file.cpp
    "file.cpp", line 17: error: incomplete type is not allowed
              detected during instantiation of class "Test::Compile_template<nbits> [with nbits=32U]" at line 23
    1 error detected in the compilation of "file.cpp".
    
    >> Compilation failure

    I suspect the problem you experience manifests in a fairly complicated bit of code.  When submitting it here, you tried to cut it down.  Maybe you cut it down too far, and removed some important details.  

    It is not difficult to submit a problem in a form very close to how you actually experience it.  For the source file that causes the problem, please follow the directions in the article How to Submit a Compiler Test Case.

    Thanks and regards,

    -George

  • Hello George,

    yes, I tried to simplify the example to find the problem and publish it in the forum. In any case, this solved my problem. I assumed that, as the variable is a static const, the compiler would compile it, but this is not the behaivour expected.

    Really thank you for your quick reply!

    Best regards,

    Marta.