[cfe-dev] Why global variable declarations are treated differently than local ones?

Paolo Bolzoni bolzoni at cs.unipr.it
Mon Dec 22 15:59:53 PST 2008


Example source code:
---<
int a,b,c;
void f() {
  int a,b,c;
}
--->
in this simple code clang sees two top level declarations.
The first is a variable declaration (clang::VarDecl) and you can read all
declarations using getNextDeclarator() of the base class clang::ScopedDecl.

Instead the second is a function declaration. Its definition is a compound
statement, the first statement is a declaration statement (clang::DeclStmt),
here to see all the variables actually declared you need to use the
decl_iterators, where each returns a _single_ clang::VarDecl. 

Since single variable declarations can express chains of declarations I see
strange this difference. Where is the reason?
Wasn't easier connect the DeclStmt with a single Decl, just like global type
or variable declarations?

pb



More information about the cfe-dev mailing list