Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22016

How to suppress GCC compiler warning: inline variables are only available with -std=c++1z or -std=gnu++1z

$
0
0

I am using an inline global variable which works well for the purpose of it.

class MyClass {
public:
    void Func() {
    }
}

inline MyClass myClass;  // global inline variable

Above works well for my purpose but I get a warning when my code compiles on gcc with compiler below C++17. Following is the warning

warning: inline variables are only available with -std=c++1z or -std=gnu++1z

Question:
How can I suppress the warning on gcc?

I tried to suppress the warning by using a #pragma like below

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wc++17-extensions"
inline MyClass myClass;
#pragma GCC diagnostic pop

Above #pragma technique works on clang, but looks like GCC to not understand the #pragma? I just want to brute force suppress the warning on GCC. How can I do that?

Looks like gcc warning options list does not even mention about this? https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html

I am using gcc (GCC) 5.3.1


Viewing all articles
Browse latest Browse all 22016

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>