-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcrash-gdb.cpp
52 lines (45 loc) · 986 Bytes
/
crash-gdb.cpp
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
42
43
44
45
46
47
48
49
50
51
52
/*
a sample code to crash gdb 7.7
g++ crash-gdb.cpp -std=c++11 && gdb ./a.out
clang++ crash-gdb.cpp -std=c++11 && gdb ./a.out
g++ 4.6.3 -std=c++0x
g++ 4.8.2 -std=c++11
clang 3.5-1ubuntu1 -std=c++11
gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04 ; not crash
gdb (Ubuntu 7.7-Oubuntu3.1) 7.7 ; crash
gdb 7.8.50.20140612-cvs ; not crash
*/
#include <utility>
#include <stdio.h>
struct BaseHolder { };
template<class Func>
struct Holder : public BaseHolder {
Func func;
explicit Holder(Func&& func)
: func(std::forward<Func>(func))
{
}
};
struct Runner {
BaseHolder *holder_;
template<class Func>
explicit Runner(Func && func)
: holder_(new Holder<Func>(func)) { }
~Runner() { delete holder_; }
};
template<class T>
void f(T &)
{
auto g =[&](){ };
Runner{g};
}
int main()
{
int a = 0;
f(a);
#ifdef __clang__
printf("clang %d %d\n", __clang_major__, __clang_minor__);
#elif defined(__GNUC__)
printf("gcc %d %d\n", __GNUC__, __GNUC_MINOR__);
#endif
}