summaryrefslogtreecommitdiff
path: root/src/base
diff options
context:
space:
mode:
Diffstat (limited to 'src/base')
-rw-r--r--src/base/compiler.hh14
-rw-r--r--src/base/cprintf.cc6
-rw-r--r--src/base/imgwriter.cc2
3 files changed, 21 insertions, 1 deletions
diff --git a/src/base/compiler.hh b/src/base/compiler.hh
index 2fdd323b9..6920dad10 100644
--- a/src/base/compiler.hh
+++ b/src/base/compiler.hh
@@ -63,6 +63,20 @@
# define M5_CLASS_VAR_USED
#endif
+// This can be removed once all compilers support C++17
+#if defined __has_cpp_attribute
+ // Note: We must separate this if statement because GCC < 5.0 doesn't
+ // support the function-like syntax in #if statements.
+ #if __has_cpp_attribute(fallthrough)
+ #define M5_FALLTHROUGH [[fallthrough]]
+ #else
+ #define M5_FALLTHROUGH
+ #endif
+#else
+ // Unsupported (and no warning) on GCC < 7.
+ #define M5_FALLTHROUGH
+#endif
+
// std::make_unique redefined for C++11 compilers
namespace m5
{
diff --git a/src/base/cprintf.cc b/src/base/cprintf.cc
index 5daf196f1..caf1bb847 100644
--- a/src/base/cprintf.cc
+++ b/src/base/cprintf.cc
@@ -35,6 +35,8 @@
#include <iostream>
#include <sstream>
+#include "base/compiler.hh"
+
using namespace std;
namespace cp {
@@ -138,6 +140,7 @@ Print::process_flag()
case 'X':
fmt.uppercase = true;
+ M5_FALLTHROUGH;
case 'x':
fmt.base = Format::hex;
fmt.format = Format::integer;
@@ -159,6 +162,7 @@ Print::process_flag()
case 'G':
fmt.uppercase = true;
+ M5_FALLTHROUGH;
case 'g':
fmt.format = Format::floating;
fmt.float_format = Format::best;
@@ -167,6 +171,7 @@ Print::process_flag()
case 'E':
fmt.uppercase = true;
+ M5_FALLTHROUGH;
case 'e':
fmt.format = Format::floating;
fmt.float_format = Format::scientific;
@@ -213,6 +218,7 @@ Print::process_flag()
fmt.fill_zero = true;
break;
}
+ M5_FALLTHROUGH;
case '1':
case '2':
case '3':
diff --git a/src/base/imgwriter.cc b/src/base/imgwriter.cc
index 40de3d7cc..13ff86c30 100644
--- a/src/base/imgwriter.cc
+++ b/src/base/imgwriter.cc
@@ -59,7 +59,7 @@ createImgWriter(Enums::ImageFormat type, const FrameBuffer *fb)
// gem5 will try PNG first, and it will fallback to BMP if not
// available.
- /* FALLTHROUGH */
+ M5_FALLTHROUGH;
#if USE_PNG
case Enums::Png:
return std::unique_ptr<PngWriter>(new PngWriter(fb));