aboutsummaryrefslogtreecommitdiff
path: root/third_party/fuchsia/repo/sdk/lib/fit/include/lib/fit/internal/compiler.h
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/fuchsia/repo/sdk/lib/fit/include/lib/fit/internal/compiler.h')
-rw-r--r--third_party/fuchsia/repo/sdk/lib/fit/include/lib/fit/internal/compiler.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/third_party/fuchsia/repo/sdk/lib/fit/include/lib/fit/internal/compiler.h b/third_party/fuchsia/repo/sdk/lib/fit/include/lib/fit/internal/compiler.h
new file mode 100644
index 000000000..1bd806414
--- /dev/null
+++ b/third_party/fuchsia/repo/sdk/lib/fit/include/lib/fit/internal/compiler.h
@@ -0,0 +1,21 @@
+// Copyright 2020 The Fuchsia Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef LIB_FIT_INCLUDE_LIB_FIT_INTERNAL_COMPILER_H_
+#define LIB_FIT_INCLUDE_LIB_FIT_INTERNAL_COMPILER_H_
+
+// Annotate a class or function with C++17's [[nodiscard]] or similar where supported by the
+// compiler.
+//
+// C++14 doesn't support [[nodiscard]], but Clang allows __attribute__((warn_unused_result))
+// to be placed on class declarations. GCC only allows the attribute to be used on methods.
+#if __cplusplus >= 201703L
+#define LIB_FIT_NODISCARD [[nodiscard]]
+#elif defined(__clang__)
+#define LIB_FIT_NODISCARD __attribute__((__warn_unused_result__))
+#else
+#define LIB_FIT_NODISCARD /* nothing */
+#endif
+
+#endif // LIB_FIT_INCLUDE_LIB_FIT_INTERNAL_COMPILER_H_