compiler warning about inline members

I get this compiler warning:
In member function 'SparseVector SparseVector::operator+(const SparseVector&) const':
warning: inlining failed in call to 'SparseVector::~SparseVector() noexcept (true)': call is unlikely and code size would grow [-Winline]
warning: called from here [-Winline]

SparseVector structure is almost this: (SparseVector.h)
1
2
3
4
5
6
7
typedef std::pair<unsigned int, double> SparseElement;

struct SparseVector : public std::vector<SparseElement>   // warning: inlining failed in call.....
{
	// no c'tors / d'tors
	SparseVector operator+(const SparseVector &m) const;
};

And the implementation is this: (SparseVector.cpp)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
SparseVector SparseVector::operator+(const SparseVector &m) const
{
	SparseVector r;
	r.reserve(size() + m.size());
	auto p = begin();
	auto pm = m.begin();
	for(;;)
	{
		if (p >= end()) { r.insert(r.end(), pm, m.end()); return r; }
		if (pm >= m.end()) { r.insert(r.end(), p, end()); return r; }
		if (p->first == pm->first)
		{
			r.push_back({p->first, p->second + pm->second});
			p++; pm++;
		}
		else if (p->first < pm->first) r.push_back(*p++);
		else  r.push_back(*pm++);
	}   // warning: called from here.....
}


Unfortunatelly, I fail to reproduce the warning in smaller piece of code.
What this warning means, why it happens, and how can I kill it? (except for obvious -Winline)
It seems that the problem is that you did not return any value from the function.
GCC says it will not inline the destructor. Probably because it would increase code size to much. This is nothing that will change how your program will behave or anything so I don't think you should care too much about it.

I guess you get this warning because you pass -Winline to gcc. Remove it and the warning should go away.
Last edited on
Topic archived. No new replies allowed.