base: Add M5 flag for [[nodiscard]] attribute
authorNikos Nikoleris <nikos.nikoleris@arm.com>
Tue, 15 May 2018 07:30:40 +0000 (08:30 +0100)
committerNikos Nikoleris <nikos.nikoleris@arm.com>
Thu, 17 May 2018 14:16:24 +0000 (14:16 +0000)
This change adds the M5_NODISCARD keyword to allow use of the
[[nodiscard]] attribute with compilers that support C++17. Currently,
C++17 is not a requirement and therefore the M5_NODISCARD has not
effect and does not break compilation for older compilers.

Change-Id: Ifc5c8f34764da3c7291066dcb2ff908c97738c3d
Reviewed-on: https://gem5-review.googlesource.com/10441
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Reviewed-by: Anthony Gutierrez <anthony.gutierrez@amd.com>
Maintainer: Jason Lowe-Power <jason@lowepower.com>
Maintainer: Anthony Gutierrez <anthony.gutierrez@amd.com>

src/base/compiler.hh

index 6b0091410cca1f771dd23b2e6992ebf03e0620c4..4765adc367f2fb24528a527ada7f6e2383402d14 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012,2017 ARM Limited
+ * Copyright (c) 2012,2017-2018 ARM Limited
  * All rights reserved
  *
  * The license below extends only to copyright in the software and shall
     #else
         #define M5_FALLTHROUGH
     #endif
+
+    #if __has_cpp_attribute(nodiscard)
+        #define M5_NODISCARD [[nodiscard]]
+    #else
+        #define M5_NODISCARD
+    #endif
 #else
     // Unsupported (and no warning) on GCC < 7.
     #define M5_FALLTHROUGH
+
+    #define M5_NODISCARD
 #endif
 
 // std::make_unique redefined for C++11 compilers