nemequ / hedley

A C/C++ header to help move #ifdefs out of your code
https://nemequ.github.io/hedley/
Creative Commons Zero v1.0 Universal
774 stars 51 forks source link

HEDLEY_ALWAYS_INLINE w/o inline specifier #23

Closed travisdowns closed 5 years ago

travisdowns commented 5 years ago

The documentation for HEDLEY_ALWAYS_INLINE gives the following example:

HEDLEY_ALWAYS_INLINE
void do_something_quickly(void);

However, even if the function body is included, like:

HEDLEY_ALWAYS_INLINE
void do_something_quickly(void) {}

This will give a warning with -Wall (and fail to compile with -Werror):

warning: always_inline function might not be inlinable [-Wattributes]
 void do_something_quickly(void) {}

See godbolt.

The problem is that the function is not also declared inline. I.e., __attribute__((__always_inline__)) does not imply inline.

Maybe HEDLEY_ALWAYS_INLINE should include inline, but at a minimum the documentation should be updated.

nemequ commented 5 years ago

Maybe HEDLEY_ALWAYS_INLINE should include inline

I think so. What version are you using? HEDLEY_ALWAYS_INLINE should include HEDLEY_INLINE since v7.

If that's not it, what compiler versions and flags are you using?

travisdowns commented 5 years ago

Oops

#define HEDLEY_VERSION 1

Sorry, I copied this from somewhere else locally and I must have gotten this old version. Let me check w/ the newest version.

travisdowns commented 5 years ago

That was the problem, sorry for the noise.

The one consolation is that I think the documentation is still wrong in that the implementation section doesn't show the fact that inline is included:

image

nemequ commented 5 years ago

Thanks for reporting instead of just adding HEDLEY_INLINE to your code; I'd much rather hear about this type of issue.

You're right about the docs being out of date. I just pushed an update, thanks!