How does compiler decide whether the function should be considered for inline or not?
Unlike linkage, there is no such thing as "inline" conflicts (declarations of same name may have inline or not).
For example, multiple declarations of functions can either have inline or not, such as:
inline static void test(); // declaration with inline
int main()
{
extern void test(); // declaration without inline.
test();
}
static void test() // definition does not have inline
{
}
or
static void test(); // declaration without inline
int main()
{
test();
}
inline static void test() // but definition has inline!
{
}
In each case, does the test() gets inlined?
My real question is, how does compiler discover that the function should be inlined? Does it look at whether the most recent declaration bear the keyword inline or does it look at whether the definition has keyword inline or not?
I tried to search it in the standard, but I could not find any rules concerning this ambiguity. It looks like inline is defined very vague in the standard.
(I initially thought that there should be a "rule" that mandates once a function is declared inline, every declaration of same name has to be inline as well.)
EDIT: I am basically asking how the compiler solves the ambiguity of multiple same-name declarations which only some of them contain inline keyword.
inline static void test() // definition with inline keyword
{
}
int main()
{
extern void test(); // declaration without inline
test(); // Does compiler consider inlining or not?
}