diff --git a/indra/llcommon/llsdutil.cpp b/indra/llcommon/llsdutil.cpp
index 384b6cb8f774b0e7827f61c10c105ccbdbb19d96..f53e7981e2b57ecd3c97c9a9c40dd454b4515e85 100644
--- a/indra/llcommon/llsdutil.cpp
+++ b/indra/llcommon/llsdutil.cpp
@@ -47,7 +47,7 @@
 #include <set>
 #include <boost/range.hpp>
 
-#if LL_GNUC
+#if LL_GNUC && GCC_VERSION >= 80000
 #pragma GCC diagnostic ignored "-Wstringop-truncation"
 #endif
 
diff --git a/indra/llcommon/llstring.h b/indra/llcommon/llstring.h
index b4bc7fbd84419fdb96e4b712bc3faa6e0c4755a5..461e7fd4942342e5e22fd29646b6c56494be204c 100644
--- a/indra/llcommon/llstring.h
+++ b/indra/llcommon/llstring.h
@@ -33,7 +33,7 @@
 #endif
 #include <boost/optional/optional.hpp>
 #include <absl/container/flat_hash_map.h>
-#if LL_GNUC
+#if LL_GNUC && GCC_VERSION >= 90000
 #pragma GCC diagnostic pop
 #endif
 #include <string>
diff --git a/indra/llmessage/llnamevalue.cpp b/indra/llmessage/llnamevalue.cpp
index 3a26b906116bc56db15371776223729bfe015878..23b8cf98683d313495bd0a508269957e74d9a55b 100644
--- a/indra/llmessage/llnamevalue.cpp
+++ b/indra/llmessage/llnamevalue.cpp
@@ -35,7 +35,7 @@
 #include "llstring.h"
 #include "llstringtable.h"
 
-#if LL_GNUC
+#if LL_GNUC && GCC_VERSION >= 80000
 #pragma GCC diagnostic ignored "-Wstringop-truncation"
 #endif