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/TMS320F28379D: Forward declarations of enums no longer supported

Part Number: TMS320F28379D

Tool/software: TI C/C++ Compiler

I was recently asked to upgrade my development projects to CCS 8.0 and the latest compiler. 18.1.0 at the time. The port went smoothly until the compiler reached a module that contained class definitions whose member function declarations contained forward references to enum types. These modules compiled without errors with compiler ver 16.3 but starting with ver 17.9, they no longer will due to the forward declarations, (it generated a compiler fault because its use is non-standard).. I looked through the various compiler options but couldn't see any way to re-enable the ability, but couldn't find anything.

Is there a way to allow the compilation to complete or must I remove the forward declarations.

Thanks in advance,

  • This is a change in the C++ language standard. Because C++11 allows the user to declare the size of an enum, it might have a different size than expected. Thus, you can't use an enum-typed variable for which you don't know the size. It is possible to forward-declare the size of an enum. Please see the following for a discussion of this issue:
    stackoverflow.com/.../forward-declaring-an-enum-in-c
  • I understand that starting with C++11, the size of an enum can be defined, thus making a forward declaration possible. However both compiler versions 16.3 and 17.9 both support C++03, with ver 16.3 allowing the nonstandard use, and 17.9 not. I checked the revision history for version 17.9, (SPRU514o), and I didn't see any mention of the change. I followed the link that was attached, and saw the approach that I had previously tried to use as a work around. However the feature doesn't have any support in the new compiler.

    Maybe if I knew where this change to the compiler behavior was documented, I could determine if parts of of the code need to be re-written.
    Any tangible ways to get the desired behavior?

    Thanks again.
  • 16.x and 17.x both support C++03. The 18.x compiler does not support C++03, it supports C++11 and C++14. This is mentioned in the README.txt for 18.0.1.LTS, although it doesn't make clear that the compiler no longer has a C++98 or C++03 mode.

    I personally don't have any experience with this particular feature, so I don't have a guess for you as to how to fix the problem. Could you please show us the code you used to try to work around the problem, and that you say the new compiler does not support? If the new compiler does not support all of the enum features of C++11, that would be a surprise to me.

    I can't quickly find on the web any sort of guide for incompatibilities introduced with C++11. In my experience, there just haven't been any (we don't use forward declarations of enums). Let me ask our expert.
  • I am unable to locate anything on the c2000 18.0.1 LTS, but after looking at the new features listed in the 18.1.0 and 18.1.1 readme.txt files, I can see that they are in "preparation for the support of C++14". Does it already support it? In the language Options of my project, the only C++ options I have are to compile either in c++03 mode or embedded C++ mode, (which isn't allowed any more). So as far as I can tell. C++14 isn't supported yet.
    I appreciate the help, and will restructure the code to not use forward declarations of enums. Thanks
  • I'm sorry, I missed the fact that you are using C2000. You are correct, C2000 hasn't yet moved to C++11/14.
  • Okay, I have spoken to the expert. I was wrong - this is not a change in the C++ standard from C++98/03 to C++11/14. Instead, this is a bug fix for C++ in general, including C++98/03. The compiler will now emit a discretionary error for a forward declaration of an enum. Because it is a discretionary error, you can suppress it, and the behavior will go back to the way it was.
  • Regarding compatibility between C++98/03 and C++11/14, here is some documentation about the features you are reasonably likely to encounter. (This only applies to ARM and MSP430 right now, but all targets will be upgraded sooner or later):

    software-dl.ti.com/.../sdto_cgt_C 14-Support-for-ARM-and-MSP-Compilers.html