Inline failed

I'm working on a project, and I'm getting a pesky error:
Inlining failed in call to 'Element::~Element()': call is unlikely and code size would grow

The problem is, the line it says the error is on is return table; where table is a vector of Element.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#ifndef ELEMENT_H
#define ELEMENT_H
#include <string>
#include <vector>
using std::vector;

class Element {
	public:
		std::string name, symbol;
		unsigned short number;
		double mass;
		
		Element(void) {
			clear();
		}
		~Element(void) {
			clear();
		}
		Element(std::string _n, std::string s, short n, double m)
		{
			set(_n,s,n,m);
		}
		void set(std::string _n, std::string s, short n, double m)
		{
			name=_n;
			symbol=s;
			number=n;
			mass=m;
			return;
		}
		void clear(void)
		{
			name=symbol="";
			number=0;
			mass=0.0;
		}
};

vector<Element> InitTable(vector<Element>& table);

#endif 


Is there anything in the class which might cause this problem?
Your compiler is smart: it is telling you that you are doing something that is totally unnecessary when you destruct an 'Element' -- it isn't saying it won't do it -- it is just saying that it isn't going to inline it, because it would bloat your code with a lot of unnecessary doings.
The problem is that it gave that error even before I had the ~Element() defined.
And it errors on return tables

A shortened version of the function:
1
2
3
4
5
6
7
8
9
10
11
12
13
vector<Element> InitTable(vector<Element>& table)
{
	Element data;
	data.set("Hydrogen", "H", 1, 1.00794);
	table.push_back(data);
	// ...big incomplete list...
	data.set("Vanadium", "V", 23, 50.9415);
	table.push_back(data);
	data.set("Chromium", "Cr", 24, 51.9961);
	table.push_back(data);
	
	return table; // Herein lies the error
}
Last edited on
I'm just guessing: local variables/objects are destroyed when a function returns, and data is destroyed on that line (the compiler calls the destructor).
Yeah, but it did that when I didn't have ~Element(), which means that it thinks that {} is still too big...

Is anything wrong with the Element class itself that might be causing the problem?
Nothing to do with original question but InitTable function seems a bit strange to me.

It is called with a reference to a vector of elements vector<Element>& table.
we fill this vector with (I assume) all the elements of the periodic table.

We then copy it to another vector as the return value of the function ( return table)
Last edited on
I think calling the clear function in the destructor is pointless.
Yeah it is, but I was just testing ~Element() at that time. It really doesn't matter, doing it with or without it still gives the error.

@guest: Yeah, it's a bit strange looking at it now, but I don't see how it would cause a problem...
Topic archived. No new replies allowed.