[cfe-dev] Small Patch and VS2005 enum pb

Cédric Venet cedric.venet at student.ecp.fr
Sat Dec 1 04:11:31 PST 2007


Hi,

A small patch for adding:
- a missing include <string> in a header
- a missing file ASTConsumer.cpp in clangAST projet for VS

This allow to compile on VS2005 but there is still the old problem that enum
are signed by default on VS2005. This cause clang to assert on code like

Struct A { int I; }; struct A a;

More specifically, the problem is in DeclSpec.h at the line 64 and 111 and
174:

=========

  enum TST {
    TST_unspecified,
    TST_void,
[... 14 other enumerated type ...]
  };

TST TypeSpecType : 4;

TST getTypeSpecType() const { return TypeSpecType; }

=========

And VS2005 as the good idea to return -4 instead of 12 for struct type (same
problem for all the type >=8).

I don't know what would be the best patch. (It is not the first time I see
this problem and probably not the last time, so I would like to know how
best correct it)

I see three solutions:

1) =======================

- TST TypeSpecType : 4;
+ TST TypeSpecType : 5;

2) =======================
- enum TST {
+ enum TST UNSIGNED_ENUM {

Where UNSIGNED_ENUN is:
#ifdef VS
#define UNSIGNED_ENUN : unsigned
#else
#define UNSIGNED_ENUN
#endif

3) =======================

Something like this (this doesn't work)

- TST getTypeSpecType() const { return TypeSpecType; }
+ TST getTypeSpecType() const { return (TST)(unsigned)TypeSpecType; }

Regards,

-- 
Cédric Venet


-------------- next part --------------
A non-text attachment was scrubbed...
Name: miniclang.patch
Type: application/octet-stream
Size: 1047 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20071201/c4e4a309/attachment.obj>


More information about the cfe-dev mailing list