[cfe-dev] wrong printing of typedefs?

Daniel Dunbar daniel at zuster.org
Thu Jun 10 10:08:47 PDT 2010


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

On Wed, Jun 9, 2010 at 1:00 PM, Maximilian Odendahl
<maxodendahl at gmail.com> wrote:
> 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
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>




More information about the cfe-dev mailing list