Menu

enum class gives syntax error. Why?

2017-03-17
2019-04-24
  • Sander Bouwhuis

    Sander Bouwhuis - 2017-03-17

    I have the following in a header:

    --- MORE LINES ---
    
    // The display monitor dimensions
    struct DISPLAY_MONITOR_DIMENSIONS
    {
      uint8    u8TotMonitors;
      RECT     pRect[64];
      HMONITOR phMonitors[64];
    
      DISPLAY_MONITOR_DIMENSIONS()
      {
        // Clear the variables
        u8TotMonitors = 0;
        memset(pRect,      NULL, sizeof(pRect));
        memset(phMonitors, NULL, sizeof(phMonitors));
      }
    };
    
    // The taskbar position
    enum class TASKBAR_POS
    {
      left,   // The taskbar is on the left side of the screen
      top,    // The taskbar is on the top side of the screen
      right,  // The taskbar is on the right side of the screen
      bottom  // The taskbar is on the bottom side of the screen
    };
    
    // Function prototypes
    MISCELLANEOUS_EXP void        AppendTextToEditBox(HWND hWndEditbox, const wchar_t *pwcNewText, int32 i32Len = -1);
    MISCELLANEOUS_EXP bool        CheckMemProblem(int8 *pi8Mem, int32 i32Bytes);
    MISCELLANEOUS_EXP void        ClipRect(RECT *pRc, const RECT *pRcClip);
    MISCELLANEOUS_EXP bool        CopyDataToClipboard(const void *pvData, int32 i32Len, uint32 u32Format = CF_UNICODETEXT);
    
    --- MORE LINES ---
    

    I get 'syntax error' on this line:
    enum class TASKBAR_POS

    I'm using enum class in other places and I don't get any error there, so enum class seems to be supported by CppCheck.
    Can someone tell me why I'm getting a syntax error?

     
  • Daniel Marjamäki

    I don't know. And I can't reproduce with your code. Can you reproduce if you just put that code in a file and check it? Or is more stuff required?

     
  • versat

    versat - 2017-03-20

    See https://sourceforge.net/p/cppcheck/discussion/general/thread/8d40c994/
    Is your "enum class" in a .h file? Cppcheck parses .h files as C code and there is no enum class in C.
    You can force Cppcheck to parse it as C++ code with --language=c++. Does it work then?

     
  • Adnan Shaheen

    Adnan Shaheen - 2019-04-22

    I updated to 1.87 from 1.86. Now I am having this issue. I tried to use the fix --language=c++, but doesn't work

     
  • Sergey Burgsdorf

    Hello!
    Having the same problem on 1.87.

    MyHeaderFile.h

    namespace MyNameSpace
    {
      enum ErrorCode
      {
    

    CPPcheck reports a syntax error on the Enum line. --language=c++ doesn't help.
    The error is reported regardless if "enum" or "enum class" is used.

     

    Last edit: Sergey Burgsdorf 2019-04-23
  • Robert Reif

    Robert Reif - 2019-04-23

    Do you have: #define ErrorCode something or typedef something ErrorCode; somewhere?

     
  • Adnan Shaheen

    Adnan Shaheen - 2019-04-24

    My problem was fixed, because the enums were already declared in another library that I was using.

    enum class attr {
        text,
        file
        ...
    };
    

    These were already used, so when I changed the names in enum, my problem was resolved.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.