Polly 20.0.0git
isl_test_cpp17.cc
Go to the documentation of this file.
1#include <stdlib.h>
2
3#include <exception>
4#include <sstream>
5
6#include <isl/options.h>
7#include <isl/cpp.h>
8
9/* Throw a runtime exception.
10 */
11static void die_impl(const char *file, int line, const char *message)
12{
13 std::ostringstream ss;
14 ss << file << ":" << line << ": " << message;
15 throw std::runtime_error(ss.str());
16}
17
18#define die(msg) die_impl(__FILE__, __LINE__, msg)
19
21
22/* Check that an isl::exception_invalid gets thrown by "fn".
23 */
24static void check_invalid(const std::function<void(void)> &fn)
25{
26 bool caught = false;
27 try {
28 fn();
29 } catch (const isl::exception_invalid &e) {
30 caught = true;
31 }
32 if (!caught)
33 die("no invalid exception was generated");
34}
35
36/* Test id::user.
37 *
38 * In particular, check that the object attached to an identifier
39 * can be retrieved again and that retrieving an object of the wrong type
40 * or retrieving an object when no object was attached results in an exception.
41 */
42static void test_user(isl::ctx ctx)
43{
44 isl::id id(ctx, "test", 5);
45 isl::id id2(ctx, "test2");
46 isl::id id3(ctx, "test3", std::string("s"));
47
48 auto int_user = id.user<int>();
49 if (int_user != 5)
50 die("wrong integer retrieved from isl::id");
51 auto s_user = id3.user<std::string>();
52 if (s_user != "s")
53 die("wrong string retrieved from isl::id");
54 check_invalid([&id] () { id.user<std::string>(); });
55 check_invalid([&id2] () { id2.user<int>(); });
56 check_invalid([&id2] () { id2.user<std::string>(); });
57 check_invalid([&id3] () { id3.user<int>(); });
58}
59
60/* Test the C++17 specific features of the (unchecked) isl C++ interface
61 *
62 * In particular, test
63 * - id::try_user
64 * - id::user
65 */
66int main()
67{
68 isl_ctx *ctx = isl_ctx_alloc();
69
71
72 test_try_user(ctx);
73 test_user(ctx);
74
75 isl_ctx_free(ctx);
76
77 return EXIT_SUCCESS;
78}
void * user() const
isl_ctx * isl_ctx_alloc(void)
Definition: isl_ctx.c:261
void isl_ctx_free(isl_ctx *ctx)
Definition: isl_ctx.c:288
isl_stat isl_stat(* fn)(__isl_take ISL_KEY *key, __isl_take ISL_VAL *val, void *user)
Definition: hmap.h:37
const char * id
Definition: isl_test.c:7279
static void test_try_user(isl::ctx ctx)
static void check_invalid(const std::function< void(void)> &fn)
static void die_impl(const char *file, int line, const char *message)
static void test_user(isl::ctx ctx)
#define die(msg)
int main()
isl_stat isl_options_set_on_error(isl_ctx *ctx, int val)
#define ISL_ON_ERROR_ABORT
Definition: options.h:31