It depends on what you mean by "respects". GCC does follow all the rules about inline functions even with lowest optimization level. The compiler doesn't have to actually inline an inline function. I'm not sure how GCC will handle this. Does it really matters?
The code that LB has posted will not compile because func() is defined multiple times in the same translation unit. This has nothing to do with inline.
Oh, if you meant actually inlining the code from the function to where it is used, then that IS a good question.
With optimizations disabled, and an inlined function, and considering that inlining is often an optimization even with functions that are not marked as inline, I can only think of one way to test.
The compiler is not allowed to make such optimizations because that would change the outcome of the program. There are some special rules about temporary objects, so if you pass a temporary object to the function it can optimize so that only one object is created but that could happen even if the function was inlined or not.
With no optimizations:
if it is inlined then the copy constructor will not be called.
if is not inlined then it will make a copy to pass by value.
I don't think that an inline function taking an object by value as it's param, will cause the compile not to call the copy constructor of the class! I am afraid to say that your assumption is not true.
For inline functions, it isn't all or nothing. Sometimes, it can be inlined and sometimes it can't. The only thing you prove by finding a place where it doesn't inline is that it doesn't inline in that particular case.
At optimization level O, some inlining is done, but the inline keyword is never 'respected' if that means it's used as a cue to inline a function.
> does anybody know if the compiler respects the keyword inline at gcc optimization level 0?
Yes. Unless -f-no-inline is also specified. However, no 'automatic inlining' will be done - only those functions which have the inlne specifier will be considered for inlining.
Invoke g++ with this command line: >g++ -O1 -Q --help=optimizers and it will output a list of optimization options along with the enabled/disabled status of each at that optimization level.