diff --git a/include/nlohmann/detail/macro_scope.hpp b/include/nlohmann/detail/macro_scope.hpp
index fdd1aa12..b1bd1484 100644
--- a/include/nlohmann/detail/macro_scope.hpp
+++ b/include/nlohmann/detail/macro_scope.hpp
@@ -38,10 +38,14 @@
 #endif
 
 // allow for portable nodiscard warnings
-#if defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard)
-    #define JSON_NODISCARD [[nodiscard]]
-#elif defined(__has_cpp_attribute) && __has_cpp_attribute(gnu::warn_unused_result)
-    #define JSON_NODISCARD [[gnu::warn_unused_result]]
+#if defined(__has_cpp_attribute)
+    #if __has_cpp_attribute(nodiscard)
+        #define JSON_NODISCARD [[nodiscard]]
+    #elif __has_cpp_attribute(gnu::warn_unused_result)
+        #define JSON_NODISCARD [[gnu::warn_unused_result]]
+    #else
+        #define JSON_NODISCARD
+    #endif
 #else
     #define JSON_NODISCARD
 #endif
diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp
index 6570f8d1..70412a18 100644
--- a/single_include/nlohmann/json.hpp
+++ b/single_include/nlohmann/json.hpp
@@ -153,10 +153,14 @@ using json = basic_json<>;
 #endif
 
 // allow for portable nodiscard warnings
-#if defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard)
-    #define JSON_NODISCARD [[nodiscard]]
-#elif defined(__has_cpp_attribute) && __has_cpp_attribute(gnu::warn_unused_result)
-    #define JSON_NODISCARD [[gnu::warn_unused_result]]
+#if defined(__has_cpp_attribute)
+    #if __has_cpp_attribute(nodiscard)
+        #define JSON_NODISCARD [[nodiscard]]
+    #elif __has_cpp_attribute(gnu::warn_unused_result)
+        #define JSON_NODISCARD [[gnu::warn_unused_result]]
+    #else
+        #define JSON_NODISCARD
+    #endif
 #else
     #define JSON_NODISCARD
 #endif