[cfe-dev] Warning generation for non-static inline functions.

David Blaikie dblaikie at gmail.com
Tue Sep 11 08:09:34 PDT 2012


On Tue, Sep 11, 2012 at 2:29 AM, arsen <hakobyan.ars at gmail.com> wrote:
> Hi all,
>
> I am trying to generate a warning message when the there is a non-static
> inline function in source code. For instance I have the following case.
> inline int foo (int);
> int main()
> {
>     int b = 2;
>     int c = foo(b);
>     return 0;
> }
> int foo(int a)
> {
>     return a;
> }
>
> I Need to add the checking (and also the warning message generation) in
> ParseAST phase. I have looked into the source codes and I guess that the
> checking can be placed in ../source/tools/clang/lib/Parse/Parser.cpp  in
> function Parser::DeclGroupPtrTy
> Parser::ParseDeclarationOrFunctionDefinition(ParsingDeclSpec &DS,
> AccessSpecifier AS) {} (at line ~772)
> There is a "ParseDeclarationSpecifiers(DS, ParsedTemplateInfo(), AS,
> DSC_top_level);" function call here. And I thing after this it is possible
> to check has function inlinehint attribute and the static keyword is
> specifies for the function (I am going to check that by StorageClassSpec).
>
> Can anybody give me an advice am I right to do that here, or if there is
> another better solution I will be very thankful if someone could help me
> with this.

Have you considered other examples of inline functions, such as class
members that are implicitly inline:

struct foo {
  void func() { // because the function definition is within the
class, it is implicitly 'inline'
  }
};

There might be a more general way to catch these cases, probably later
on in the front-end, similar to where we warn about unused (static)
functions. (look for the implementation of the unused function warning
& you should be pretty close) That's just a rough guess & by no means
strictly better/correct.

- David



More information about the cfe-dev mailing list