clang: export symbols of implicitly instantiated functions with O3
问题 TL,DR: How can I force clang to export the symbols of implicitly instantiated functions even when -O3 is active? Let's take the following code: #include <iostream> #include <llvm/Support/DynamicLibrary.h> #include <llvm/ExecutionEngine/ExecutionEngine.h> #include <llvm/ExecutionEngine/RTDyldMemoryManager.h> template <typename T> __attribute__((noinline)) int twice(const T& t) { return t * 2; } int thrice(const int& t) { return t * 3; } int main() { std::cout << twice(5) << std::endl; std: