jeudi 26 mars 2020

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

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;

But above does not work since it looks like GCC to not understand the #pragma? I just want to brute force suppress the warning. How can I do that?

Aucun commentaire:

Enregistrer un commentaire