Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F148784383
D50217.id154991.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D50217.id154991.diff
View Options
diff --git a/sys/sys/cdefs.h b/sys/sys/cdefs.h
--- a/sys/sys/cdefs.h
+++ b/sys/sys/cdefs.h
@@ -258,7 +258,8 @@
* clang and gcc have different semantics for __warn_unused_result__: the latter
* does not permit the use of a void cast to suppress the warning. Use
* __result_use_or_ignore_check in places where a void cast is acceptable.
- * This can be implemented by [[nodiscard]] from C23.
+ *
+ * This macro is deprecated; use __nodiscard in new code.
*/
#define __result_use_or_ignore_check __result_use_check
#else
@@ -295,6 +296,33 @@
#define __noexcept_if(__c)
#endif
+/*
+ * nodiscard attribute added in C++17 and C23, but supported by both LLVM and
+ * GCC in earlier language versions, so we use __has_c{,pp}_attribute to test
+ * for it.
+ *
+ * __nodiscard may be used on a function:
+ * __nodiscard int f();
+ *
+ * or on a struct, union or enum:
+ * struct __nodiscard S{};
+ * struct S f();
+ *
+ * or in C++, on an object constructor.
+ */
+
+#if defined(__cplusplus) && defined(__has_cpp_attribute)
+#if __has_cpp_attribute(nodiscard)
+#define __nodiscard [[nodiscard]]
+#endif
+#elif defined(__STDC_VERSION__) && defined(__has_c_attribute)
+#if __has_c_attribute(__nodiscard__)
+#define __nodiscard [[__nodiscard__]]
+#endif
+#else
+#define __nodiscard
+#endif
+
/*
* We use `__restrict' as a way to define the `restrict' type qualifier
* without disturbing older software that is unaware of C99 keywords.
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Mar 21, 5:17 AM (18 h, 32 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
30062680
Default Alt Text
D50217.id154991.diff (1 KB)
Attached To
Mode
D50217: sys/cdefs.h: add __nodiscard annotation
Attached
Detach File
Event Timeline
Log In to Comment