libcxxrt

git clone https://git.neptards.moe/neptards/libcxxrt.git
Log | Files | Refs | README | LICENSE

test_guard.cc (409B)


      1 #include <stdio.h>
      2 #include "test.h"
      3 
      4 static int static_count;
      5 struct static_struct
      6 {
      7 	int i;
      8 	static_struct()
      9 	{
     10 		static_count++;
     11 		i = 12;
     12 	};
     13 };
     14 
     15 static static_struct ss;
     16 
     17 int init_static(void)
     18 {
     19 	static static_struct s;
     20 	return s.i;
     21 }
     22 
     23 void test_guards(void)
     24 {
     25 	init_static();
     26 	int i = init_static();
     27 	TEST(i == 12, "Static initialized");
     28 	TEST(static_count == 2, "Each static only initialized once");
     29 }