wrong printing of typedefs?

Hi,

I have such a typedef in my source file:

typedef struct { int var1; int var2; } type1;

Using this code:

DeclContext *DC = TranslationUnitDecl::castToDeclContext(D);
DeclContext::decl_iterator it = DC->decls_begin(), end = DC->decls_end();
   while (it != end) {
     switch (it->getKind()) {
       case Decl::Typedef:
         if (it->getLocation().isValid() && s.getSourceManager().isFromMainFile(it->getLocation())) {
           it->print (OutFile);

I would have expected to get the same thing back, but I actually get

struct {
     int var1;
     int var2;
};
typedef type1 type1;

which does not compile of course. Using dump returns the same issue.

Is this a bug in clang somewhere?

Thanks for any help,
Max

Hi Max,

Currently, the print() method on Decl's isn't a reliable way to get
back something which is semantically equivalent and will compile.

It would be great if clang -cc1 -ast-print could be used on any input
file, and the output could be expected to compile & have the same
semantics, but right now there are a lot of substantial problems
preventing this from working.

We would like this to work however, so if want to work on this we
would gladly accept patches to improve things.

- Daniel