Fixits for invalid main declarations

So I thought I'd try my hand at some bugs & I found this:
http://llvm.org/bugs/show_bug.cgi?id=8104

But I thought I'd just start at the top (of Sema::CheckMain (in
SemaDecl.cpp)) & see about adding fixits to all the various warnings &
errors I came across.

The first one is a warning (error in C++) for main being declared
inline or static. But I can't seem to figure out how to get the
SourceRange of the static/inline keyword from the FunctionDecl. Is
this possible? Could someone point me to the right place to find those
SourceRanges?

[I have a sneaking suspicion that maybe this level of source
information isn't kept through to semantic analysis here... ]

Thanks,
- David

I don't think we maintain that information in the FunctionDecl. It's in the DeclSpec, if it's still hanging around.

  - Doug

[sorry Doug, meant to reply to the list]

I can’t seem to figure out how to get the
SourceRange of the static/inline keyword from the FunctionDecl. Is
this possible? Could someone point me to the right place to find those
SourceRanges?

I don’t think we maintain that information in the FunctionDecl. It’s in the DeclSpec, if it’s still hanging around.

Thanks Doug - that at least got me looking for the right type (the DeclSpec).

It seems (according to http://clang.llvm.org/doxygen/classclang_1_1Sema.html#a9b8436b6e81170462bf184c4755ba180 ) there are 3 callers of CheckFunctionDeclaration:

The first actually has access to the DeclSpec (through the Declarator parameter).
The latter two are for member functions and templates - & I don’t believe main can be templated, can it?

No, main cannot be a template.

So should we just push the isMain/checkMain checking up into ActOnFunctionDeclarator instead? Then it wouldn’t add any overhead to irrelevant contexts (methods & templates) & the checking could be more descriptive.

Works for me!

  • Doug