Reputation: 1
I have a template class simplified as following:
template<typename R>
struct MyStruct
{
template<typename T>
using ConstnessType = std::conditional_t<std::is_const_v<R>, std::add_const_t<T>, T>;
char* name() const{return "MyStruct";};
ConstnessType<int> myInt;
}
As it can be seen that type R is not actually instantiated other than used to define the other type. I have expected that using different Rs should result in the same instantiated code. However, when I compiled with -g and with different Rs, I found the compilation memory usage and final object file size are proportional to the complexity of Rs. Depending on the complexity of Rs, I had seen almost 10 times difference in the memory usage and final object file. Is this desired behavior? Or is there some compiler option to let the compiler smartly recognize there is no need to generate the debug info for the un-instantiated template parameter? Thanks!
Upvotes: 0
Views: 328
Reputation: 6332
Welcome to Stack Overflow!
It's not entirely clear to me what your desired result is other than less memory usage.
You don't mention what compiler or debugger versions you are using, but here are four things you could try:
-g
does the platform default, -ggdb
does gdb-specific info, -gdwarf
does DWARF info)-ggdb1
vs. -ggdb2
and -ggdb3
, and -gdwarf4
is a different format entirely). Tinkering with these may yield different debug info more to your liking. Or not.strip
command to remove debug symbols where you don't want them.-O
switches, or you can do it for blocks of code with pragmas, as described here, e.g.,#pragma GCC push_options
#pragma GCC optimize ("O3")
/*
* Code that needs optimizing
*/
#pragma GCC pop_options
Upvotes: 1