isl_map_simplify.c: div_find_coalesce: return isl_size
[isl.git] / isl_test_cpp17-generic.cc
blobc6b4bab7d439d621c8ea84007321d4e811629a75
1 /* A class that sets a boolean when an object of the class gets destroyed.
2 */
3 struct S {
4 S(bool *freed) : freed(freed) {}
5 ~S();
7 bool *freed;
8 };
10 /* S destructor.
12 * Set the boolean, a pointer to which was passed to the constructor.
14 S::~S()
16 *freed = true;
19 /* Construct an isl::id with an S object attached that sets *freed
20 * when it gets destroyed.
22 static isl::id construct_id(isl::ctx ctx, bool *freed)
24 auto s = std::make_shared<S>(freed);
25 isl::id id(ctx, "S", s);
26 return id;
29 /* Test id::try_user.
31 * In particular, check that the object attached to an identifier
32 * can be retrieved again, that trying to retrieve an object of the wrong type
33 * or trying to retrieve an object when no object was attached fails.
34 * Furthermore, check that the object attached to an identifier
35 * gets properly freed.
37 static void test_try_user(isl::ctx ctx)
39 isl::id id(ctx, "test", 5);
40 isl::id id2(ctx, "test2");
42 auto maybe_int = id.try_user<int>();
43 auto maybe_s = id.try_user<std::shared_ptr<S>>();
44 auto maybe_int2 = id2.try_user<int>();
46 if (!maybe_int)
47 die("integer cannot be retrieved from isl::id");
48 if (maybe_int.value() != 5)
49 die("wrong integer retrieved from isl::id");
50 if (maybe_s)
51 die("structure unexpectedly retrieved from isl::id");
52 if (maybe_int2)
53 die("integer unexpectedly retrieved from isl::id");
55 bool freed = false;
57 isl::id id = construct_id(ctx, &freed);
58 if (freed)
59 die("data structure freed prematurely");
60 auto maybe_s = id.try_user<std::shared_ptr<S>>();
61 if (!maybe_s)
62 die("structure cannot be retrieved from isl::id");
63 if (maybe_s.value()->freed != &freed)
64 die("invalid structure retrieved from isl::id");
66 if (!freed)
67 die("data structure not freed");