File tree Expand file tree Collapse file tree 4 files changed +27
-5
lines changed Expand file tree Collapse file tree 4 files changed +27
-5
lines changed Original file line number Diff line number Diff line change @@ -19,16 +19,20 @@ extern int type_naming_counter;
19
19
20
20
template <typename T, typename V=void >
21
21
struct type_namer {
22
- static std::string obtained_name;
22
+ // Use a pointer to a string instead of
23
+ // a string because it is possible get_type_name is called
24
+ // from global constructors before obtained_name is initialized
25
+ static std::string *obtained_name;
23
26
static std::string get_type_name () {
24
- if (obtained_name == " " ) {
25
- obtained_name = " custom_struct" + std::to_string (type_naming_counter++);
27
+ if (obtained_name == nullptr ) {
28
+ obtained_name = new std::string ();
29
+ *obtained_name = " custom_struct" + std::to_string (type_naming_counter++);
26
30
}
27
- return obtained_name;
31
+ return * obtained_name;
28
32
}
29
33
};
30
34
template <typename T, typename V>
31
- std::string type_namer<T, V>::obtained_name = " " ;
35
+ std::string * type_namer<T, V>::obtained_name = nullptr ;
32
36
33
37
template <typename T>
34
38
struct type_namer <T, typename check_valid_type<decltype (T::type_name)>::type> {
Original file line number Diff line number Diff line change @@ -39,6 +39,12 @@ FUNC_DECL
39
39
VAR (a_0)
40
40
INT_CONST (1)
41
41
INT_CONST (1)
42
+ EXPR_STMT
43
+ ASSIGN_EXPR
44
+ MEMBER_ACCESS_EXPR (mem0)
45
+ VAR_EXPR
46
+ VAR (p)
47
+ INT_CONST (0)
42
48
struct custom_struct0 {
43
49
int mem0;
44
50
float mem1;
@@ -53,5 +59,6 @@ void bar (void) {
53
59
a_0.nested = b_1;
54
60
(a_0.nested).mem0 = a_0.mem0;
55
61
((a_0.nested).mem1 = (a_0.nested).mem1 + 1) - 1;
62
+ p.mem0 = 0;
56
63
}
57
64
Original file line number Diff line number Diff line change @@ -39,6 +39,12 @@ FUNC_DECL
39
39
VAR (var0)
40
40
INT_CONST (1)
41
41
INT_CONST (1)
42
+ EXPR_STMT
43
+ ASSIGN_EXPR
44
+ MEMBER_ACCESS_EXPR (mem0)
45
+ VAR_EXPR
46
+ VAR (p)
47
+ INT_CONST (0)
42
48
struct custom_struct0 {
43
49
int mem0;
44
50
float mem1;
@@ -53,5 +59,6 @@ void bar (void) {
53
59
var0.nested = var1;
54
60
(var0.nested).mem0 = var0.mem0;
55
61
((var0.nested).mem1 = (var0.nested).mem1 + 1) - 1;
62
+ p.mem0 = 0;
56
63
}
57
64
Original file line number Diff line number Diff line change @@ -21,6 +21,9 @@ struct my_type {
21
21
dyn_var<int > another;
22
22
};
23
23
24
+
25
+ dyn_var<struct_type> p = builder::as_global(" p" );
26
+
24
27
static void bar (void ) {
25
28
dyn_var<my_type> a;
26
29
dyn_var<struct_type> b;
@@ -29,6 +32,7 @@ static void bar(void) {
29
32
a.nested .x = a.another ;
30
33
31
34
a.nested .y ++;
35
+ p.x = 0 ;
32
36
}
33
37
34
38
int main (int argc, char *argv[]) {
You can’t perform that action at this time.
0 commit comments