Build fix: POD static_assert check fails on lttng_event_exclusions
[lttng-tools.git] / src / common / compiler.hpp
diff --git a/src/common/compiler.hpp b/src/common/compiler.hpp
new file mode 100644 (file)
index 0000000..bb080ad
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2023 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ */
+
+#ifndef LTTNG_COMPILER_HPP
+#define LTTNG_COMPILER_HPP
+
+/*
+ * A bug in gcc [6.1, 7.4] causes flexible array members to generate a destructor
+ * for compound types. In turn, this makes any type that contains a flexible array
+ * a non-POD object which is a problem under some use-case (e.g., being allocated
+ * using C-style memory management facilities).
+ *
+ * Explicitly specifying a length of zero works around this bug, see:
+ * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70932
+ * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71147
+ */
+#if !defined(__clang__) && defined(__GNUC__) && \
+       ((__GNUC__ == 6 && __GNUC_MINOR__ >= 1) || ((__GNUC__ == 7 && __GNUC_MINOR__ <= 4)))
+#define LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH 0
+#else
+#define LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH
+#endif /* gcc version [6.1, 7.4]. */
+
+#endif /* LTTNG_COMPILER_HPP */
This page took 0.024511 seconds and 4 git commands to generate.