diff --git a/include/nlohmann/detail/macro_scope.hpp b/include/nlohmann/detail/macro_scope.hpp
index ef138100..e41180a9 100644
--- a/include/nlohmann/detail/macro_scope.hpp
+++ b/include/nlohmann/detail/macro_scope.hpp
@@ -18,6 +18,14 @@
     #endif
 #endif
 
+// C++ language standard detection
+#if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464
+    #define JSON_HAS_CPP_17
+    #define JSON_HAS_CPP_14
+#elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1)
+    #define JSON_HAS_CPP_14
+#endif
+
 // disable float-equal warnings on GCC/clang
 #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
     #pragma GCC diagnostic push
@@ -42,7 +50,11 @@
 // allow for portable nodiscard warnings
 #if defined(__has_cpp_attribute)
     #if __has_cpp_attribute(nodiscard)
-        #define JSON_NODISCARD [[nodiscard]]
+        #if defined(__clang__) && !defined(JSON_HAS_CPP_17) // issue #1535
+            #define JSON_NODISCARD
+        #else
+            #define JSON_NODISCARD [[nodiscard]]
+        #endif
     #elif __has_cpp_attribute(gnu::warn_unused_result)
         #define JSON_NODISCARD [[gnu::warn_unused_result]]
     #else
@@ -95,14 +107,6 @@
     #define JSON_UNLIKELY(x)    x
 #endif
 
-// C++ language standard detection
-#if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464
-    #define JSON_HAS_CPP_17
-    #define JSON_HAS_CPP_14
-#elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1)
-    #define JSON_HAS_CPP_14
-#endif
-
 /*!
 @brief macro to briefly define a mapping between an enum and JSON
 @def NLOHMANN_JSON_SERIALIZE_ENUM
diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp
index 5003a4fa..1f11538c 100644
--- a/single_include/nlohmann/json.hpp
+++ b/single_include/nlohmann/json.hpp
@@ -469,6 +469,14 @@ class other_error : public exception
     #endif
 #endif
 
+// C++ language standard detection
+#if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464
+    #define JSON_HAS_CPP_17
+    #define JSON_HAS_CPP_14
+#elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1)
+    #define JSON_HAS_CPP_14
+#endif
+
 // disable float-equal warnings on GCC/clang
 #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
     #pragma GCC diagnostic push
@@ -493,7 +501,11 @@ class other_error : public exception
 // allow for portable nodiscard warnings
 #if defined(__has_cpp_attribute)
     #if __has_cpp_attribute(nodiscard)
-        #define JSON_NODISCARD [[nodiscard]]
+        #if defined(__clang__) && !defined(JSON_HAS_CPP_17) // issue #1535
+            #define JSON_NODISCARD
+        #else
+            #define JSON_NODISCARD [[nodiscard]]
+        #endif
     #elif __has_cpp_attribute(gnu::warn_unused_result)
         #define JSON_NODISCARD [[gnu::warn_unused_result]]
     #else
@@ -546,14 +558,6 @@ class other_error : public exception
     #define JSON_UNLIKELY(x)    x
 #endif
 
-// C++ language standard detection
-#if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464
-    #define JSON_HAS_CPP_17
-    #define JSON_HAS_CPP_14
-#elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1)
-    #define JSON_HAS_CPP_14
-#endif
-
 /*!
 @brief macro to briefly define a mapping between an enum and JSON
 @def NLOHMANN_JSON_SERIALIZE_ENUM