slycelote / caide-cpp-inliner

Transform a C++ program consisting of multiple source files and headers into a single self-contained source file without any external dependencies (except for standard system headers). Unused code is not included in the resulting file.
Other
32 stars 12 forks source link

Function template is removed while referenced as a function pointer #17

Closed mfornet closed 4 years ago

mfornet commented 4 years ago

If I pass as a default value to a function another function, the passed function is not kept (The minimal example I could reproduce was with functions using templates, which is my use case).

main.cpp

#include <iostream>
#include "lib.hpp"

int main()
{
    A a;

    std::cout << a.f() << std::endl;
}

lib.hpp

#include <functional>

using namespace std;

template <typename T>
T value()
{
    return 42;
}

class A
{
public:
    function<int()> f;

    A(function<int()> f = value<int>) : f(f)
    {
    }
};

result.cpp

#include <iostream>
#include <functional>

using namespace std;

class A
{
public:
    function<int()> f;

    A(function<int()> f = value<int>) : f(f)
    {
    }
};

int main()
{
    A a;

    std::cout << a.f() << std::endl;
}

Notice how declaration of function value was removed. If I use value without any templates it is not removed.

slycelote commented 4 years ago

Thanks for the bug report :) This has been fixed.