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++
{count} votes

Accepted answer
  1. Viorel 122.6K 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 Answers by the question author, which helps users to know the answer solved the author's problem.