c++11 - Variadic template argument deduction - c++11 - many functions linked to one
问题描述
I'm experiencing some strange occurrences regarding varidaic templates that I never saw before. In order to keep it simple i'll give a simple example of what I was trying to achieve, the real code is a bit more involved.
So I have one function that looks like:
template <typename T, typename F, typename ... Args>
static T Func( std::string str, Args&& ... args )
{
... Do something
}
I then call this function a number of times from different locations, where most times the passed types are different. But when I debug this, when I look for the symbol of Func, I get that the same function address has a number of different symbols:
00000000`70ba4ae0 Func<unsigned long,unsigned long (__stdcall*)(wchar_t const *),wchar_t const *>
00000000`70ba4ae0 Func<void *,void * (__stdcall*)(unsigned int),unsigned int>
00000000`70ba4ae0 Func<int,int (__stdcall*)(void *),void *>
So they are all basically the same function. When I try to call for example:
call Func<void *,void * (__stdcall*)(unsigned int),unsigned int>
In the debugger I see:
call Func<int,int (__stdcall*)(void *),void *>
I can see that there is a generated symbol for every template function instance, but every such instance that has the same number of arguments and the arguments are the same byte-size are just linked to one function.
While I can understand why this may happen, but is there a way to force each function to be standalone?
解决方案
The issue was indeed COMDAT folding. Turning off the OPT:ICF and OPT:REF flags did the trick. Although worth noting that compiling with VS 2017 with the flags produced more "sensible" results than compiling the same code with VS 2013.
推荐阅读
- node.js - 无法在 Mac 上安装 Ember Octane;NPM 和 NVM 的问题
- c - 使用 MPI 进行并行合并排序
- javascript - 使用 amchart 甘特图的初始日期范围
- wpf - Gong Drag&Drop:订阅drop事件
- jquery - window.onload 在 Firefox 中的 jQuery document.ready 之前触发
- apache - 带有 Apache 反向代理 http2 的 NGINX 网络服务器
- c# - 禁用按钮而不使用 button.Enabled = False 而仅使用 ONE Click Event
- javascript - 如何在 fetch Api 命令中添加局部变量
- r - 更改堆叠图中的颜色,ggplot 2
- javascript - 如果用户没有滚动,如何保持将 div 滚动到底部