Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!

enum namespace conflict

jimdempseyatthecove
Black Belt
180 Views

C++ from Parallel Studio XE 2017 Cluster Edition, Windows 7

enum StiffnessModel
{
    Seed = 1,
    Chord = 2
};

Produces namespace collision with

C:\Program Files (x86)\Windows Kits\8.1\Include\um\wingdi.h(3615): error : "Chord" has already been declared in the current scope
1>     WINGDIAPI BOOL  WINAPI Chord( _In_ HDC hdc, _In_ int x1, _In_ int y1, _In_ int x2, _In_ int y2, _In_ int x3, _In_ int y3, _In_ int x4, _In_ int y4);

My work around is to change the name in the enum (Chord_sm).

Jim Dempsey

0 Kudos
5 Replies
jimdempseyatthecove
Black Belt
180 Views

Note, using C++ from Parallel Studio XE 2017 Cluster Edition, Linux produces no err (due to no wingdi.h).

Minor annoyance.

Jim Dempsey

Judith_W_Intel
Employee
180 Views

 

The Intel compiler just uses the Windows headers on the system so I don't think we can do anything about namespace pollution from the Microsoft supplied headers. Microsoft gives a similar error so this is not a compiler bug.

!% cat foo.cpp

#include <windows.h>

enum StiffnessModel
{
    Seed = 1,
    Chord = 2
};

!% cl -c foo.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24210 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

foo.cpp
foo.cpp(8): error C2365: 'Chord': redefinition; previous definition was 'functio
n'
//hrcna01a.nh.intel.com/wref1/ref/vs2015u3/Windows Kits/10/include/10.0.10586.0/
um\wingdi.h(3676): note: see declaration of 'Chord'
!%

jimdempseyatthecove
Black Belt
180 Views

The following comment (opinion) may be more of a C++ language thing...

Due to the fact that the C++ compiler can understand:

    StifnessModel::Chord

IOW in the scope of the enum StiffnessModel...

And that the compiler can disambiguate between different signature functions, say Chord with different arguments...

... given the fact (additional information) that the statement in question scoped the enum:

if (layer.materialType == MaterialType::unbound && layer.unbound.stiffModel == StiffnessModel::Chord)

The explicit scoping should have removed any ambiguity as to what to reference.

Jim Dempsey

Judith_W_Intel
Employee
180 Views

 

If you want the enumerator names to be hidden then you can use the c++11 scoped enum feature, i.e. this compiles fine (notice the class keyword after enum):

enum class StiffnessModel
{
    Seed = 1,
    Chord = 2
};

http://stackoverflow.com/questions/18335861/why-is-enum-class-preferred-over-plain-enum

Judy

jimdempseyatthecove
Black Belt
180 Views

Thanks Judy.

Jim Dempsey

Reply