Notes:Exceptions and C++

From Maths
Jump to: navigation, search

Contents

Here I tell the compiler that some functions exist, and make it compile (with -O3) a function that uses them. We compare the results when we disable exception handling, and when we enable it.

Code

#include <string>
#include <vector>
 
template<class T> class DeleteWhenDone;
namespace std {
template<class T>
void swap(DeleteWhenDone<T>&,DeleteWhenDone<T>&) noexcept;
}
 
template<class T>
class DeleteWhenDone {
public:
	DeleteWhenDone() { data = nullptr; }
	DeleteWhenDone(T* source): data(source) { }
	DeleteWhenDone(const DeleteWhenDone&) = delete;
	DeleteWhenDone(DeleteWhenDone&& from) noexcept: data(from.data) { from.data = nullptr; }
	DeleteWhenDone& operator=(const DeleteWhenDone&) = delete;
	DeleteWhenDone& operator=(DeleteWhenDone&& from) {
		DeleteWhenDone tmp(::std::forward<DeleteWhenDone>(from));
		::std::swap(*this,tmp);
		return *this;
	}
	~DeleteWhenDone() { if(data != nullptr) { delete data; } }
 
	T& operator*() const {
		return *data;
	}
private:
	T* data;
 
friend void ::std::swap<>(DeleteWhenDone&,DeleteWhenDone&) noexcept;
};
namespace std {
 
template<class T>
void swap(::DeleteWhenDone<T>& A, ::DeleteWhenDone<T>& B) noexcept {
	T* tmp = A.data;
	A.data = B.data;
	B.data = tmp;
}
 
}
 
class Task {
public:
	virtual void doTask() =0;
	virtual ~Task() { }
};
 
 
/* These functions are NOT noexcept so they may throw - the compiler knows nothing about them*/
/* see http://stackoverflow.com/questions/18543980/symbol-not-found-when-using-template-defined-in-a-library/18544093#18544093 for example*/
void DoSomeTask(Task&);
::std::string IMayAlsoThrow(int group);
::std::vector<DeleteWhenDone<Task>> HiThereIMayThrow(int group);
 
int notMain(int argc, const char** args) {
	::std::vector<::std::string> someStuff = {
		"Hi there",
		"Hello"	};
	someStuff.push_back(IMayAlsoThrow(argc));
 
	::std::vector<DeleteWhenDone<Task>> tasks(HiThereIMayThrow(argc+1));
 
	int count = 0;
	for(auto& thing : tasks) {
		count++;
		DoSomeTask(*thing);
	}
	return count;
}

Result

Just -O3 (~310 instructions) With -fno-exceptions (~200 instructions)
0000000000000000 <notMain(int, char const**)>:
  0:	41 56                	push   %r14
  2:	be 00 00 00 00       	mov    $0x0,%esi
  7:	41 55                	push   %r13
  9:	41 89 fd             	mov    %edi,%r13d
  c:	41 54                	push   %r12
  e:	55                   	push   %rbp
  f:	53                   	push   %rbx
 10:	48 83 ec 60          	sub    $0x60,%rsp
 14:	48 8d 54 24 0e       	lea    0xe(%rsp),%rdx
 19:	48 8d 7c 24 40       	lea    0x40(%rsp),%rdi
 1e:	e8 00 00 00 00       	callq  23 <notMain(int, char const**)+0x23>
 23:	48 8d 7c 24 48       	lea    0x48(%rsp),%rdi
 28:	48 8d 54 24 0f       	lea    0xf(%rsp),%rdx
 2d:	be 00 00 00 00       	mov    $0x0,%esi
 32:	e8 00 00 00 00       	callq  37 <notMain(int, char const**)+0x37>
 37:	bf 10 00 00 00       	mov    $0x10,%edi
 3c:	48 c7 44 24 20 00 00 	movq   $0x0,0x20(%rsp)
 43:	00 00 
 45:	48 c7 44 24 28 00 00 	movq   $0x0,0x28(%rsp)
 4c:	00 00 
 4e:	48 c7 44 24 30 00 00 	movq   $0x0,0x30(%rsp)
 55:	00 00 
 57:	e8 00 00 00 00       	callq  5c <notMain(int, char const**)+0x5c>
 5c:	48 8d 6c 24 40       	lea    0x40(%rsp),%rbp
 61:	49 89 c6             	mov    %rax,%r14
 64:	48 89 44 24 20       	mov    %rax,0x20(%rsp)
 69:	48 8d 40 10          	lea    0x10(%rax),%rax
 6d:	4c 89 f3             	mov    %r14,%rbx
 70:	4c 8d 65 10          	lea    0x10(%rbp),%r12
 74:	48 89 44 24 30       	mov    %rax,0x30(%rsp)
 79:	0f 1f 80 00 00 00 00 	nopl   0x0(%rax)
 80:	48 85 db             	test   %rbx,%rbx
 83:	74 0b                	je     90 <notMain(int, char const**)+0x90>
 85:	48 89 ee             	mov    %rbp,%rsi
 88:	48 89 df             	mov    %rbx,%rdi
 8b:	e8 00 00 00 00       	callq  90 <notMain(int, char const**)+0x90>
 90:	48 83 c5 08          	add    $0x8,%rbp
 94:	48 83 c3 08          	add    $0x8,%rbx
 98:	4c 39 e5             	cmp    %r12,%rbp
 9b:	75 e3                	jne    80 <notMain(int, char const**)+0x80>
 9d:	48 8b 44 24 48       	mov    0x48(%rsp),%rax
 a2:	48 89 5c 24 28       	mov    %rbx,0x28(%rsp)
 a7:	48 8d 78 e8          	lea    -0x18(%rax),%rdi
 ab:	48 81 ff 00 00 00 00 	cmp    $0x0,%rdi
 b2:	0f 85 7d 01 00 00    	jne    235 <notMain(int, char const**)+0x235>
 b8:	4c 8d 64 24 10       	lea    0x10(%rsp),%r12
 bd:	48 8b 44 24 40       	mov    0x40(%rsp),%rax
 c2:	48 8d 78 e8          	lea    -0x18(%rax),%rdi
 c6:	48 81 ff 00 00 00 00 	cmp    $0x0,%rdi
 cd:	0f 85 cf 02 00 00    	jne    3a2 <notMain(int, char const**)+0x3a2>
 d3:	44 89 ee             	mov    %r13d,%esi
 d6:	4c 89 e7             	mov    %r12,%rdi
 d9:	e8 00 00 00 00       	callq  de <notMain(int, char const**)+0xde>
 de:	48 8b 44 24 28       	mov    0x28(%rsp),%rax
 e3:	48 3b 44 24 30       	cmp    0x30(%rsp),%rax
 e8:	0f 84 0e 01 00 00    	je     1fc <notMain(int, char const**)+0x1fc>
 ee:	48 85 c0             	test   %rax,%rax
 f1:	48 8b 54 24 10       	mov    0x10(%rsp),%rdx
 f6:	74 11                	je     109 <notMain(int, char const**)+0x109>
 f8:	48 89 10             	mov    %rdx,(%rax)
 fb:	48 c7 44 24 10 00 00 	movq   $0x0,0x10(%rsp)
102:	00 00 
104:	ba 00 00 00 00       	mov    $0x0,%edx
109:	48 83 c0 08          	add    $0x8,%rax
10d:	48 89 44 24 28       	mov    %rax,0x28(%rsp)
112:	48 8d 7a e8          	lea    -0x18(%rdx),%rdi
116:	48 81 ff 00 00 00 00 	cmp    $0x0,%rdi
11d:	0f 85 ab 02 00 00    	jne    3ce <notMain(int, char const**)+0x3ce>
123:	41 8d 75 01          	lea    0x1(%r13),%esi
127:	48 8d 7c 24 40       	lea    0x40(%rsp),%rdi
12c:	e8 00 00 00 00       	callq  131 <notMain(int, char const**)+0x131>
131:	48 8b 5c 24 40       	mov    0x40(%rsp),%rbx
136:	4c 8b 6c 24 48       	mov    0x48(%rsp),%r13
13b:	4c 39 eb             	cmp    %r13,%rbx
13e:	0f 84 cf 00 00 00    	je     213 <notMain(int, char const**)+0x213>
144:	31 ed                	xor    %ebp,%ebp
146:	66 2e 0f 1f 84 00 00 	nopw   %cs:0x0(%rax,%rax,1)
14d:	00 00 00 
150:	48 8b 3b             	mov    (%rbx),%rdi
153:	83 c5 01             	add    $0x1,%ebp
156:	e8 00 00 00 00       	callq  15b <notMain(int, char const**)+0x15b>
15b:	48 83 c3 08          	add    $0x8,%rbx
15f:	49 39 dd             	cmp    %rbx,%r13
162:	75 ec                	jne    150 <notMain(int, char const**)+0x150>
164:	4c 8b 6c 24 48       	mov    0x48(%rsp),%r13
169:	48 8b 5c 24 40       	mov    0x40(%rsp),%rbx
16e:	49 39 dd             	cmp    %rbx,%r13
171:	74 21                	je     194 <notMain(int, char const**)+0x194>
173:	0f 1f 44 00 00       	nopl   0x0(%rax,%rax,1)
178:	48 8b 3b             	mov    (%rbx),%rdi
17b:	48 85 ff             	test   %rdi,%rdi
17e:	74 06                	je     186 <notMain(int, char const**)+0x186>
180:	48 8b 17             	mov    (%rdi),%rdx
183:	ff 52 10             	callq  *0x10(%rdx)
186:	48 83 c3 08          	add    $0x8,%rbx
18a:	49 39 dd             	cmp    %rbx,%r13
18d:	75 e9                	jne    178 <notMain(int, char const**)+0x178>
18f:	4c 8b 6c 24 40       	mov    0x40(%rsp),%r13
194:	4d 85 ed             	test   %r13,%r13
197:	74 08                	je     1a1 <notMain(int, char const**)+0x1a1>
199:	4c 89 ef             	mov    %r13,%rdi
19c:	e8 00 00 00 00       	callq  1a1 <notMain(int, char const**)+0x1a1>
1a1:	4c 8b 6c 24 28       	mov    0x28(%rsp),%r13
1a6:	48 8b 5c 24 20       	mov    0x20(%rsp),%rbx
1ab:	49 39 dd             	cmp    %rbx,%r13
1ae:	74 47                	je     1f7 <notMain(int, char const**)+0x1f7>
1b0:	b8 00 00 00 00       	mov    $0x0,%eax
1b5:	48 85 c0             	test   %rax,%rax
1b8:	0f 84 58 02 00 00    	je     416 <notMain(int, char const**)+0x416>
1be:	66 90                	xchg   %ax,%ax
1c0:	48 8b 03             	mov    (%rbx),%rax
1c3:	48 8d 78 e8          	lea    -0x18(%rax),%rdi
1c7:	48 81 ff 00 00 00 00 	cmp    $0x0,%rdi
1ce:	75 4d                	jne    21d <notMain(int, char const**)+0x21d>
1d0:	48 83 c3 08          	add    $0x8,%rbx
1d4:	49 39 dd             	cmp    %rbx,%r13
1d7:	75 e7                	jne    1c0 <notMain(int, char const**)+0x1c0>
1d9:	48 8b 7c 24 20       	mov    0x20(%rsp),%rdi
1de:	48 85 ff             	test   %rdi,%rdi
1e1:	74 05                	je     1e8 <notMain(int, char const**)+0x1e8>
1e3:	e8 00 00 00 00       	callq  1e8 <notMain(int, char const**)+0x1e8>
1e8:	48 83 c4 60          	add    $0x60,%rsp
1ec:	89 e8                	mov    %ebp,%eax
1ee:	5b                   	pop    %rbx
1ef:	5d                   	pop    %rbp
1f0:	41 5c                	pop    %r12
1f2:	41 5d                	pop    %r13
1f4:	41 5e                	pop    %r14
1f6:	c3                   	retq   
1f7:	4c 89 ef             	mov    %r13,%rdi
1fa:	eb e2                	jmp    1de <notMain(int, char const**)+0x1de>
1fc:	48 8d 7c 24 20       	lea    0x20(%rsp),%rdi
201:	4c 89 e6             	mov    %r12,%rsi
204:	e8 00 00 00 00       	callq  209 <notMain(int, char const**)+0x209>
209:	48 8b 54 24 10       	mov    0x10(%rsp),%rdx
20e:	e9 ff fe ff ff       	jmpq   112 <notMain(int, char const**)+0x112>
213:	49 89 dd             	mov    %rbx,%r13
216:	31 ed                	xor    %ebp,%ebp
218:	e9 77 ff ff ff       	jmpq   194 <notMain(int, char const**)+0x194>
21d:	ba ff ff ff ff       	mov    $0xffffffff,%edx
222:	f0 0f c1 50 f8       	lock xadd %edx,-0x8(%rax)
227:	85 d2                	test   %edx,%edx
229:	7f a5                	jg     1d0 <notMain(int, char const**)+0x1d0>
22b:	4c 89 e6             	mov    %r12,%rsi
22e:	e8 00 00 00 00       	callq  233 <notMain(int, char const**)+0x233>
233:	eb 9b                	jmp    1d0 <notMain(int, char const**)+0x1d0>
235:	b9 00 00 00 00       	mov    $0x0,%ecx
23a:	48 8d 57 10          	lea    0x10(%rdi),%rdx
23e:	48 85 c9             	test   %rcx,%rcx
241:	0f 84 ed 01 00 00    	je     434 <notMain(int, char const**)+0x434>
247:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
24c:	f0 0f c1 02          	lock xadd %eax,(%rdx)
250:	85 c0                	test   %eax,%eax
252:	4c 8d 64 24 10       	lea    0x10(%rsp),%r12
257:	0f 8f 60 fe ff ff    	jg     bd <notMain(int, char const**)+0xbd>
25d:	4c 89 e6             	mov    %r12,%rsi
260:	e8 00 00 00 00       	callq  265 <notMain(int, char const**)+0x265>
265:	e9 53 fe ff ff       	jmpq   bd <notMain(int, char const**)+0xbd>
26a:	49 89 c4             	mov    %rax,%r12
26d:	48 8b 44 24 10       	mov    0x10(%rsp),%rax
272:	48 8d 74 24 40       	lea    0x40(%rsp),%rsi
277:	48 8d 78 e8          	lea    -0x18(%rax),%rdi
27b:	e8 00 00 00 00       	callq  280 <notMain(int, char const**)+0x280>
280:	48 8b 6c 24 28       	mov    0x28(%rsp),%rbp
285:	48 8b 5c 24 20       	mov    0x20(%rsp),%rbx
28a:	48 39 dd             	cmp    %rbx,%rbp
28d:	0f 84 07 02 00 00    	je     49a <notMain(int, char const**)+0x49a>
293:	b8 00 00 00 00       	mov    $0x0,%eax
298:	48 85 c0             	test   %rax,%rax
29b:	0f 84 db 01 00 00    	je     47c <notMain(int, char const**)+0x47c>
2a1:	48 8b 13             	mov    (%rbx),%rdx
2a4:	48 8d 7a e8          	lea    -0x18(%rdx),%rdi
2a8:	48 81 ff 00 00 00 00 	cmp    $0x0,%rdi
2af:	0f 85 a6 01 00 00    	jne    45b <notMain(int, char const**)+0x45b>
2b5:	48 83 c3 08          	add    $0x8,%rbx
2b9:	48 39 dd             	cmp    %rbx,%rbp
2bc:	75 e3                	jne    2a1 <notMain(int, char const**)+0x2a1>
2be:	48 8b 7c 24 20       	mov    0x20(%rsp),%rdi
2c3:	48 85 ff             	test   %rdi,%rdi
2c6:	74 05                	je     2cd <notMain(int, char const**)+0x2cd>
2c8:	e8 00 00 00 00       	callq  2cd <notMain(int, char const**)+0x2cd>
2cd:	4c 89 e7             	mov    %r12,%rdi
2d0:	e8 00 00 00 00       	callq  2d5 <notMain(int, char const**)+0x2d5>
2d5:	48 89 c7             	mov    %rax,%rdi
2d8:	4c 8d 64 24 10       	lea    0x10(%rsp),%r12
2dd:	e8 00 00 00 00       	callq  2e2 <notMain(int, char const**)+0x2e2>
2e2:	4c 39 f3             	cmp    %r14,%rbx
2e5:	74 18                	je     2ff <notMain(int, char const**)+0x2ff>
2e7:	49 8b 06             	mov    (%r14),%rax
2ea:	4c 89 e6             	mov    %r12,%rsi
2ed:	49 83 c6 08          	add    $0x8,%r14
2f1:	48 8d 78 e8          	lea    -0x18(%rax),%rdi
2f5:	e8 00 00 00 00       	callq  2fa <notMain(int, char const**)+0x2fa>
2fa:	4c 39 f3             	cmp    %r14,%rbx
2fd:	75 e8                	jne    2e7 <notMain(int, char const**)+0x2e7>
2ff:	e8 00 00 00 00       	callq  304 <notMain(int, char const**)+0x304>
304:	4c 8d 64 24 10       	lea    0x10(%rsp),%r12
309:	48 89 c3             	mov    %rax,%rbx
30c:	48 8b 7c 24 20       	mov    0x20(%rsp),%rdi
311:	48 85 ff             	test   %rdi,%rdi
314:	74 05                	je     31b <notMain(int, char const**)+0x31b>
316:	e8 00 00 00 00       	callq  31b <notMain(int, char const**)+0x31b>
31b:	48 8b 44 24 48       	mov    0x48(%rsp),%rax
320:	4c 89 e6             	mov    %r12,%rsi
323:	48 8d 78 e8          	lea    -0x18(%rax),%rdi
327:	e8 00 00 00 00       	callq  32c <notMain(int, char const**)+0x32c>
32c:	48 8b 44 24 40       	mov    0x40(%rsp),%rax
331:	4c 89 e6             	mov    %r12,%rsi
334:	48 8d 78 e8          	lea    -0x18(%rax),%rdi
338:	e8 00 00 00 00       	callq  33d <notMain(int, char const**)+0x33d>
33d:	48 89 df             	mov    %rbx,%rdi
340:	e8 00 00 00 00       	callq  345 <notMain(int, char const**)+0x345>
345:	48 8b 6c 24 48       	mov    0x48(%rsp),%rbp
34a:	48 8b 5c 24 40       	mov    0x40(%rsp),%rbx
34f:	49 89 c4             	mov    %rax,%r12
352:	48 39 dd             	cmp    %rbx,%rbp
355:	74 1e                	je     375 <notMain(int, char const**)+0x375>
357:	48 8b 3b             	mov    (%rbx),%rdi
35a:	48 85 ff             	test   %rdi,%rdi
35d:	74 06                	je     365 <notMain(int, char const**)+0x365>
35f:	48 8b 07             	mov    (%rdi),%rax
362:	ff 50 10             	callq  *0x10(%rax)
365:	48 83 c3 08          	add    $0x8,%rbx
369:	48 39 dd             	cmp    %rbx,%rbp
36c:	75 e9                	jne    357 <notMain(int, char const**)+0x357>
36e:	48 8b 7c 24 40       	mov    0x40(%rsp),%rdi
373:	eb 03                	jmp    378 <notMain(int, char const**)+0x378>
375:	48 89 ef             	mov    %rbp,%rdi
378:	48 85 ff             	test   %rdi,%rdi
37b:	0f 84 ff fe ff ff    	je     280 <notMain(int, char const**)+0x280>
381:	e8 00 00 00 00       	callq  386 <notMain(int, char const**)+0x386>
386:	e9 f5 fe ff ff       	jmpq   280 <notMain(int, char const**)+0x280>
38b:	49 89 c4             	mov    %rax,%r12
38e:	66 90                	xchg   %ax,%ax
390:	e9 eb fe ff ff       	jmpq   280 <notMain(int, char const**)+0x280>
395:	48 89 c3             	mov    %rax,%rbx
398:	e8 00 00 00 00       	callq  39d <notMain(int, char const**)+0x39d>
39d:	e9 6a ff ff ff       	jmpq   30c <notMain(int, char const**)+0x30c>
3a2:	b9 00 00 00 00       	mov    $0x0,%ecx
3a7:	48 8d 57 10          	lea    0x10(%rdi),%rdx
3ab:	48 85 c9             	test   %rcx,%rcx
3ae:	74 4e                	je     3fe <notMain(int, char const**)+0x3fe>
3b0:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
3b5:	f0 0f c1 02          	lock xadd %eax,(%rdx)
3b9:	85 c0                	test   %eax,%eax
3bb:	0f 8f 12 fd ff ff    	jg     d3 <notMain(int, char const**)+0xd3>
3c1:	4c 89 e6             	mov    %r12,%rsi
3c4:	e8 00 00 00 00       	callq  3c9 <notMain(int, char const**)+0x3c9>
3c9:	e9 05 fd ff ff       	jmpq   d3 <notMain(int, char const**)+0xd3>
3ce:	b9 00 00 00 00       	mov    $0x0,%ecx
3d3:	48 8d 47 10          	lea    0x10(%rdi),%rax
3d7:	48 85 c9             	test   %rcx,%rcx
3da:	74 2f                	je     40b <notMain(int, char const**)+0x40b>
3dc:	ba ff ff ff ff       	mov    $0xffffffff,%edx
3e1:	f0 0f c1 10          	lock xadd %edx,(%rax)
3e5:	89 d0                	mov    %edx,%eax
3e7:	85 c0                	test   %eax,%eax
3e9:	0f 8f 34 fd ff ff    	jg     123 <notMain(int, char const**)+0x123>
3ef:	48 8d 74 24 40       	lea    0x40(%rsp),%rsi
3f4:	e8 00 00 00 00       	callq  3f9 <notMain(int, char const**)+0x3f9>
3f9:	e9 25 fd ff ff       	jmpq   123 <notMain(int, char const**)+0x123>
3fe:	8b 50 f8             	mov    -0x8(%rax),%edx
401:	8d 4a ff             	lea    -0x1(%rdx),%ecx
404:	89 48 f8             	mov    %ecx,-0x8(%rax)
407:	89 d0                	mov    %edx,%eax
409:	eb ae                	jmp    3b9 <notMain(int, char const**)+0x3b9>
40b:	8b 42 f8             	mov    -0x8(%rdx),%eax
40e:	8d 48 ff             	lea    -0x1(%rax),%ecx
411:	89 4a f8             	mov    %ecx,-0x8(%rdx)
414:	eb d1                	jmp    3e7 <notMain(int, char const**)+0x3e7>
416:	48 8b 03             	mov    (%rbx),%rax
419:	48 8d 78 e8          	lea    -0x18(%rax),%rdi
41d:	48 81 ff 00 00 00 00 	cmp    $0x0,%rdi
424:	75 1e                	jne    444 <notMain(int, char const**)+0x444>
426:	48 83 c3 08          	add    $0x8,%rbx
42a:	49 39 dd             	cmp    %rbx,%r13
42d:	75 e7                	jne    416 <notMain(int, char const**)+0x416>
42f:	e9 a5 fd ff ff       	jmpq   1d9 <notMain(int, char const**)+0x1d9>
434:	8b 50 f8             	mov    -0x8(%rax),%edx
437:	8d 4a ff             	lea    -0x1(%rdx),%ecx
43a:	89 48 f8             	mov    %ecx,-0x8(%rax)
43d:	89 d0                	mov    %edx,%eax
43f:	e9 0c fe ff ff       	jmpq   250 <notMain(int, char const**)+0x250>
444:	8b 50 f8             	mov    -0x8(%rax),%edx
447:	8d 4a ff             	lea    -0x1(%rdx),%ecx
44a:	85 d2                	test   %edx,%edx
44c:	89 48 f8             	mov    %ecx,-0x8(%rax)
44f:	7f d5                	jg     426 <notMain(int, char const**)+0x426>
451:	4c 89 e6             	mov    %r12,%rsi
454:	e8 00 00 00 00       	callq  459 <notMain(int, char const**)+0x459>
459:	eb cb                	jmp    426 <notMain(int, char const**)+0x426>
45b:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
460:	f0 0f c1 42 f8       	lock xadd %eax,-0x8(%rdx)
465:	85 c0                	test   %eax,%eax
467:	0f 8f 48 fe ff ff    	jg     2b5 <notMain(int, char const**)+0x2b5>
46d:	48 8d 74 24 0f       	lea    0xf(%rsp),%rsi
472:	e8 00 00 00 00       	callq  477 <notMain(int, char const**)+0x477>
477:	e9 39 fe ff ff       	jmpq   2b5 <notMain(int, char const**)+0x2b5>
47c:	48 8b 03             	mov    (%rbx),%rax
47f:	48 8d 78 e8          	lea    -0x18(%rax),%rdi
483:	48 81 ff 00 00 00 00 	cmp    $0x0,%rdi
48a:	75 16                	jne    4a2 <notMain(int, char const**)+0x4a2>
48c:	48 83 c3 08          	add    $0x8,%rbx
490:	48 39 dd             	cmp    %rbx,%rbp
493:	75 e7                	jne    47c <notMain(int, char const**)+0x47c>
495:	e9 24 fe ff ff       	jmpq   2be <notMain(int, char const**)+0x2be>
49a:	48 89 ef             	mov    %rbp,%rdi
49d:	e9 21 fe ff ff       	jmpq   2c3 <notMain(int, char const**)+0x2c3>
4a2:	8b 50 f8             	mov    -0x8(%rax),%edx
4a5:	8d 4a ff             	lea    -0x1(%rdx),%ecx
4a8:	85 d2                	test   %edx,%edx
4aa:	89 48 f8             	mov    %ecx,-0x8(%rax)
4ad:	7f dd                	jg     48c <notMain(int, char const**)+0x48c>
4af:	48 8d 74 24 0f       	lea    0xf(%rsp),%rsi
4b4:	e8 00 00 00 00       	callq  4b9 <notMain(int, char const**)+0x4b9>
4b9:	eb d1                	jmp    48c <notMain(int, char const**)+0x48c>
0000000000000000 <notMain(int, char const**)>:
  0:	41 55                	push   %r13
  2:	41 89 fd             	mov    %edi,%r13d
  5:	be 00 00 00 00       	mov    $0x0,%esi
  a:	41 54                	push   %r12
  c:	55                   	push   %rbp
  d:	53                   	push   %rbx
  e:	48 83 ec 58          	sub    $0x58,%rsp
 12:	48 8d 54 24 0d       	lea    0xd(%rsp),%rdx
 17:	48 8d 7c 24 30       	lea    0x30(%rsp),%rdi
 1c:	48 8d 6c 24 30       	lea    0x30(%rsp),%rbp
 21:	e8 00 00 00 00       	callq  26 <notMain(int, char const**)+0x26>
 26:	48 8d 7c 24 38       	lea    0x38(%rsp),%rdi
 2b:	48 8d 54 24 0e       	lea    0xe(%rsp),%rdx
 30:	be 00 00 00 00       	mov    $0x0,%esi
 35:	4c 8d 65 10          	lea    0x10(%rbp),%r12
 39:	e8 00 00 00 00       	callq  3e <notMain(int, char const**)+0x3e>
 3e:	bf 10 00 00 00       	mov    $0x10,%edi
 43:	48 c7 44 24 10 00 00 	movq   $0x0,0x10(%rsp)
 4a:	00 00 
 4c:	48 c7 44 24 18 00 00 	movq   $0x0,0x18(%rsp)
 53:	00 00 
 55:	48 c7 44 24 20 00 00 	movq   $0x0,0x20(%rsp)
 5c:	00 00 
 5e:	e8 00 00 00 00       	callq  63 <notMain(int, char const**)+0x63>
 63:	48 89 c3             	mov    %rax,%rbx
 66:	48 89 44 24 10       	mov    %rax,0x10(%rsp)
 6b:	48 8d 40 10          	lea    0x10(%rax),%rax
 6f:	48 89 44 24 20       	mov    %rax,0x20(%rsp)
 74:	0f 1f 40 00          	nopl   0x0(%rax)
 78:	48 85 db             	test   %rbx,%rbx
 7b:	74 0b                	je     88 <notMain(int, char const**)+0x88>
 7d:	48 89 ee             	mov    %rbp,%rsi
 80:	48 89 df             	mov    %rbx,%rdi
 83:	e8 00 00 00 00       	callq  88 <notMain(int, char const**)+0x88>
 88:	48 83 c5 08          	add    $0x8,%rbp
 8c:	48 83 c3 08          	add    $0x8,%rbx
 90:	4c 39 e5             	cmp    %r12,%rbp
 93:	75 e3                	jne    78 <notMain(int, char const**)+0x78>
 95:	48 8b 44 24 38       	mov    0x38(%rsp),%rax
 9a:	48 89 5c 24 18       	mov    %rbx,0x18(%rsp)
 9f:	48 8d 78 e8          	lea    -0x18(%rax),%rdi
 a3:	48 81 ff 00 00 00 00 	cmp    $0x0,%rdi
 aa:	0f 85 74 01 00 00    	jne    224 <notMain(int, char const**)+0x224>
 b0:	48 8b 44 24 30       	mov    0x30(%rsp),%rax
 b5:	48 8d 78 e8          	lea    -0x18(%rax),%rdi
 b9:	48 81 ff 00 00 00 00 	cmp    $0x0,%rdi
 c0:	0f 85 92 01 00 00    	jne    258 <notMain(int, char const**)+0x258>
 c6:	48 8d 7c 24 30       	lea    0x30(%rsp),%rdi
 cb:	44 89 ee             	mov    %r13d,%esi
 ce:	e8 00 00 00 00       	callq  d3 <notMain(int, char const**)+0xd3>
 d3:	48 8b 44 24 18       	mov    0x18(%rsp),%rax
 d8:	48 3b 44 24 20       	cmp    0x20(%rsp),%rax
 dd:	0f 84 0e 01 00 00    	je     1f1 <notMain(int, char const**)+0x1f1>
 e3:	48 85 c0             	test   %rax,%rax
 e6:	48 8b 54 24 30       	mov    0x30(%rsp),%rdx
 eb:	74 11                	je     fe <notMain(int, char const**)+0xfe>
 ed:	48 89 10             	mov    %rdx,(%rax)
 f0:	48 c7 44 24 30 00 00 	movq   $0x0,0x30(%rsp)
 f7:	00 00 
 f9:	ba 00 00 00 00       	mov    $0x0,%edx
 fe:	48 83 c0 08          	add    $0x8,%rax
102:	48 89 44 24 18       	mov    %rax,0x18(%rsp)
107:	48 8d 7a e8          	lea    -0x18(%rdx),%rdi
10b:	48 81 ff 00 00 00 00 	cmp    $0x0,%rdi
112:	0f 85 88 01 00 00    	jne    2a0 <notMain(int, char const**)+0x2a0>
118:	41 8d 75 01          	lea    0x1(%r13),%esi
11c:	48 8d 7c 24 30       	lea    0x30(%rsp),%rdi
121:	e8 00 00 00 00       	callq  126 <notMain(int, char const**)+0x126>
126:	48 8b 5c 24 30       	mov    0x30(%rsp),%rbx
12b:	4c 8b 6c 24 38       	mov    0x38(%rsp),%r13
130:	4c 39 eb             	cmp    %r13,%rbx
133:	0f 84 ac 00 00 00    	je     1e5 <notMain(int, char const**)+0x1e5>
139:	31 ed                	xor    %ebp,%ebp
13b:	0f 1f 44 00 00       	nopl   0x0(%rax,%rax,1)
140:	48 8b 3b             	mov    (%rbx),%rdi
143:	48 83 c3 08          	add    $0x8,%rbx
147:	83 c5 01             	add    $0x1,%ebp
14a:	e8 00 00 00 00       	callq  14f <notMain(int, char const**)+0x14f>
14f:	49 39 dd             	cmp    %rbx,%r13
152:	75 ec                	jne    140 <notMain(int, char const**)+0x140>
154:	4c 8b 64 24 38       	mov    0x38(%rsp),%r12
159:	48 8b 5c 24 30       	mov    0x30(%rsp),%rbx
15e:	49 39 dc             	cmp    %rbx,%r12
161:	74 21                	je     184 <notMain(int, char const**)+0x184>
163:	0f 1f 44 00 00       	nopl   0x0(%rax,%rax,1)
168:	48 8b 3b             	mov    (%rbx),%rdi
16b:	48 85 ff             	test   %rdi,%rdi
16e:	74 06                	je     176 <notMain(int, char const**)+0x176>
170:	48 8b 07             	mov    (%rdi),%rax
173:	ff 50 10             	callq  *0x10(%rax)
176:	48 83 c3 08          	add    $0x8,%rbx
17a:	49 39 dc             	cmp    %rbx,%r12
17d:	75 e9                	jne    168 <notMain(int, char const**)+0x168>
17f:	4c 8b 64 24 30       	mov    0x30(%rsp),%r12
184:	4d 85 e4             	test   %r12,%r12
187:	74 08                	je     191 <notMain(int, char const**)+0x191>
189:	4c 89 e7             	mov    %r12,%rdi
18c:	e8 00 00 00 00       	callq  191 <notMain(int, char const**)+0x191>
191:	4c 8b 64 24 18       	mov    0x18(%rsp),%r12
196:	48 8b 5c 24 10       	mov    0x10(%rsp),%rbx
19b:	49 39 dc             	cmp    %rbx,%r12
19e:	74 4c                	je     1ec <notMain(int, char const**)+0x1ec>
1a0:	b8 00 00 00 00       	mov    $0x0,%eax
1a5:	48 85 c0             	test   %rax,%rax
1a8:	0f 84 22 01 00 00    	je     2d0 <notMain(int, char const**)+0x2d0>
1ae:	66 90                	xchg   %ax,%ax
1b0:	48 8b 03             	mov    (%rbx),%rax
1b3:	48 8d 78 e8          	lea    -0x18(%rax),%rdi
1b7:	48 81 ff 00 00 00 00 	cmp    $0x0,%rdi
1be:	75 4a                	jne    20a <notMain(int, char const**)+0x20a>
1c0:	48 83 c3 08          	add    $0x8,%rbx
1c4:	49 39 dc             	cmp    %rbx,%r12
1c7:	75 e7                	jne    1b0 <notMain(int, char const**)+0x1b0>
1c9:	48 8b 7c 24 10       	mov    0x10(%rsp),%rdi
1ce:	48 85 ff             	test   %rdi,%rdi
1d1:	74 05                	je     1d8 <notMain(int, char const**)+0x1d8>
1d3:	e8 00 00 00 00       	callq  1d8 <notMain(int, char const**)+0x1d8>
1d8:	48 83 c4 58          	add    $0x58,%rsp
1dc:	89 e8                	mov    %ebp,%eax
1de:	5b                   	pop    %rbx
1df:	5d                   	pop    %rbp
1e0:	41 5c                	pop    %r12
1e2:	41 5d                	pop    %r13
1e4:	c3                   	retq   
1e5:	49 89 dc             	mov    %rbx,%r12
1e8:	31 ed                	xor    %ebp,%ebp
1ea:	eb 98                	jmp    184 <notMain(int, char const**)+0x184>
1ec:	4c 89 e7             	mov    %r12,%rdi
1ef:	eb dd                	jmp    1ce <notMain(int, char const**)+0x1ce>
1f1:	48 8d 74 24 30       	lea    0x30(%rsp),%rsi
1f6:	48 8d 7c 24 10       	lea    0x10(%rsp),%rdi
1fb:	e8 00 00 00 00       	callq  200 <notMain(int, char const**)+0x200>
200:	48 8b 54 24 30       	mov    0x30(%rsp),%rdx
205:	e9 fd fe ff ff       	jmpq   107 <notMain(int, char const**)+0x107>
20a:	ba ff ff ff ff       	mov    $0xffffffff,%edx
20f:	f0 0f c1 50 f8       	lock xadd %edx,-0x8(%rax)
214:	85 d2                	test   %edx,%edx
216:	7f a8                	jg     1c0 <notMain(int, char const**)+0x1c0>
218:	48 8d 74 24 0f       	lea    0xf(%rsp),%rsi
21d:	e8 00 00 00 00       	callq  222 <notMain(int, char const**)+0x222>
222:	eb 9c                	jmp    1c0 <notMain(int, char const**)+0x1c0>
224:	b9 00 00 00 00       	mov    $0x0,%ecx
229:	48 8d 57 10          	lea    0x10(%rdi),%rdx
22d:	48 85 c9             	test   %rcx,%rcx
230:	74 54                	je     286 <notMain(int, char const**)+0x286>
232:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
237:	f0 0f c1 02          	lock xadd %eax,(%rdx)
23b:	85 c0                	test   %eax,%eax
23d:	0f 8f 6d fe ff ff    	jg     b0 <notMain(int, char const**)+0xb0>
243:	48 8d 74 24 0f       	lea    0xf(%rsp),%rsi
248:	e8 00 00 00 00       	callq  24d <notMain(int, char const**)+0x24d>
24d:	e9 5e fe ff ff       	jmpq   b0 <notMain(int, char const**)+0xb0>
252:	66 0f 1f 44 00 00    	nopw   0x0(%rax,%rax,1)
258:	b9 00 00 00 00       	mov    $0x0,%ecx
25d:	48 8d 57 10          	lea    0x10(%rdi),%rdx
261:	48 85 c9             	test   %rcx,%rcx
264:	74 2d                	je     293 <notMain(int, char const**)+0x293>
266:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
26b:	f0 0f c1 02          	lock xadd %eax,(%rdx)
26f:	85 c0                	test   %eax,%eax
271:	0f 8f 4f fe ff ff    	jg     c6 <notMain(int, char const**)+0xc6>
277:	48 8d 74 24 0f       	lea    0xf(%rsp),%rsi
27c:	e8 00 00 00 00       	callq  281 <notMain(int, char const**)+0x281>
281:	e9 40 fe ff ff       	jmpq   c6 <notMain(int, char const**)+0xc6>
286:	8b 50 f8             	mov    -0x8(%rax),%edx
289:	8d 4a ff             	lea    -0x1(%rdx),%ecx
28c:	89 48 f8             	mov    %ecx,-0x8(%rax)
28f:	89 d0                	mov    %edx,%eax
291:	eb a8                	jmp    23b <notMain(int, char const**)+0x23b>
293:	8b 50 f8             	mov    -0x8(%rax),%edx
296:	8d 4a ff             	lea    -0x1(%rdx),%ecx
299:	89 48 f8             	mov    %ecx,-0x8(%rax)
29c:	89 d0                	mov    %edx,%eax
29e:	eb cf                	jmp    26f <notMain(int, char const**)+0x26f>
2a0:	b9 00 00 00 00       	mov    $0x0,%ecx
2a5:	48 8d 47 10          	lea    0x10(%rdi),%rax
2a9:	48 85 c9             	test   %rcx,%rcx
2ac:	74 40                	je     2ee <notMain(int, char const**)+0x2ee>
2ae:	ba ff ff ff ff       	mov    $0xffffffff,%edx
2b3:	f0 0f c1 10          	lock xadd %edx,(%rax)
2b7:	89 d0                	mov    %edx,%eax
2b9:	85 c0                	test   %eax,%eax
2bb:	0f 8f 57 fe ff ff    	jg     118 <notMain(int, char const**)+0x118>
2c1:	48 8d 74 24 0f       	lea    0xf(%rsp),%rsi
2c6:	e8 00 00 00 00       	callq  2cb <notMain(int, char const**)+0x2cb>
2cb:	e9 48 fe ff ff       	jmpq   118 <notMain(int, char const**)+0x118>
2d0:	48 8b 03             	mov    (%rbx),%rax
2d3:	48 8d 78 e8          	lea    -0x18(%rax),%rdi
2d7:	48 81 ff 00 00 00 00 	cmp    $0x0,%rdi
2de:	75 19                	jne    2f9 <notMain(int, char const**)+0x2f9>
2e0:	48 83 c3 08          	add    $0x8,%rbx
2e4:	49 39 dc             	cmp    %rbx,%r12
2e7:	75 e7                	jne    2d0 <notMain(int, char const**)+0x2d0>
2e9:	e9 db fe ff ff       	jmpq   1c9 <notMain(int, char const**)+0x1c9>
2ee:	8b 42 f8             	mov    -0x8(%rdx),%eax
2f1:	8d 48 ff             	lea    -0x1(%rax),%ecx
2f4:	89 4a f8             	mov    %ecx,-0x8(%rdx)
2f7:	eb c0                	jmp    2b9 <notMain(int, char const**)+0x2b9>
2f9:	8b 50 f8             	mov    -0x8(%rax),%edx
2fc:	8d 4a ff             	lea    -0x1(%rdx),%ecx
2ff:	85 d2                	test   %edx,%edx
301:	89 48 f8             	mov    %ecx,-0x8(%rax)
304:	7f da                	jg     2e0 <notMain(int, char const**)+0x2e0>
306:	48 8d 74 24 0f       	lea    0xf(%rsp),%rsi
30b:	e8 00 00 00 00       	callq  310 <notMain(int, char const**)+0x310>
310:	eb ce                	jmp    2e0 <notMain(int, char const**)+0x2e0>

Why?

Take the following:

  1. AR someFunction(A1 a1, A2 a2, A3 a3, ..., AN an) {
  2.     L1 l1;
  3.     someCallThatMayThrow();
  4.     L2 l2;
  5.     someOtherCall();
  6. }

Suppose line 3 throws, then we must destroy l1 but l2 doesn't exist yet! Suppose line 5 throws instead, then we must destroy both l1 and l2 THEN "unwind the stack" to go to the next caller and destruct its locals correctly until the exception is handled.

This is a lot of work! Evidently.

C++ was able to see the vector push_back and other methods here (and thus inline them) but because it knows nothing about the 3 function prototypes given it must suppose they can do anything, and generate safe code.