Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.
Announcements
This community is designed for sharing of public information. Please do not share Intel or third-party confidential information here.

[Intel C++ 14.0] Macro enum class

Fenix_H_
Beginner
165 Views

Hellow my friends!

In MSVC2013 perfectly works for me this macro (which allow use enum class as flag enum and disallow convert to int):

#pragma once

#define EnumClass(Enum, Type) \
enum class Enum : Type; \
inline Enum  operator &  (Enum x, Enum y)  {return static_cast<Enum> (static_cast<Type>(x) & static_cast<Type>(y));}; \
inline Enum  operator |  (Enum x, Enum y)  {return static_cast<Enum> (static_cast<Type>(x) | static_cast<Type>(y));}; \
inline Enum  operator ^  (Enum x, Enum y)  {return static_cast<Enum> (static_cast<Type>(x) ^ static_cast<Type>(y));}; \
inline Enum  operator ~  (Enum x)          {return static_cast<Enum> (~static_cast<Type>(x));};                       \
inline Enum& operator &= (Enum& x, Enum y) {x = x & y; return x;};                                                    \
inline Enum& operator |= (Enum& x, Enum y) {x = x | y; return x;};                                                    \
inline Enum& operator ^= (Enum& x, Enum y) {x = x ^ y; return x;};                                                    \
enum class Enum : Type


But in Intel C++ 14.0 fails on:

 

                EnumClass(ToolhelpSnapshotFlag, unsigned __int32)
                {
                    List     = 0x00000001,
                    Process  = 0x00000002,
                    Thread   = 0x00000004,
                    Module   = 0x00000008,
                    Module32 = 0x00000010,
                    All      = List | Process | Thread | Module, //error : expression must have a constant value
                    Inherit  = 0x80000000
                };

How to enable works this on Intel C++ 14.0 without converting result of all operators to underlying type?

 

0 Kudos
2 Replies
Georg_Z_Intel
Employee
165 Views

Hello,

I can reproduce the problem and created a ticket for engineering: DPD200515852

On our compiler for Linux this case passes. So, it seems to be some compatibility setting for VS that's in the way. I'll let you know once we've fixed that or whether there's some workaround.

Thank you for reporting & best regards,

Georg Zitzlsberger

Georg_Z_Intel
Employee
165 Views

Hello,

this should be fixed with Intel(R) Composer XE 2013 SP1 Update 3, available soon.

Best regards,

Georg Zitzlsberger

Reply