always_inline and attribute placement on functions

Jonathan Wakely
Thu Sep 5 12:44:00 GMT 2013

This is a sort of follow-up to

The docs for the always_inline attribute at say:

"For functions declared inline, this attribute inlines the function
even if no optimization level is specified."

But testing and Ian's mail at say that you
don't need the "inline" keyword on an "always_inline" function.
Should the docs be clarified?

For this code:
$ cat
inline void f() __attribute((always_inline)) { }

$ g++ -std=gnu++0x -Wall -c -O3 error: attributes are not allowed on a function-definition

However, moving the attribute shows that actually it is allowed:

$ cat
inline __attribute((always_inline)) void f() { }

$ g++ -std=gnu++0x -Wall -c -O3

If placing the attribute at that location is valid then the wording of
the diagnostic is misleading, at best.

More information about the Gcc-help mailing list