Share via

Why call to function through a constexpr function pointer is not inlined?

HD86 26 Reputation points
2020-10-08T02:20:11.76+00:00

When the following code is compiled with the latest MSVC compiler, the call to the function foo is not inlined. Is there a valid reason for this, or is it a compiler deficiency?

template <auto V>
struct Wrapper
{ 
    static constexpr decltype(V) VALUE = V; 
};

void foo(int i) { std::cout << i; }

template <typename T>
void bar(T) { T::VALUE(8); }

int main()
{
    bar(Wrapper<&foo>());
}
Developer technologies | C++
Developer technologies | C++

A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.


Answer accepted by question author

  1. Viorel 126.9K Reputation points
    2020-10-08T09:18:21.38+00:00

    Try using this linker option (in Project Properties) — Link Time Code Generation: “Use Link Time Code Generation (/LTCG)”.

    How did you check the inlining results?

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.