简体   繁体   中英

How do I suppress the "ISO C++ does not support ‘__int128’ warning?

I'm compiling my code with gcc, with the -Wall -Wextra -Wpedantic switches and a non-extension standard set (say it's -std=c++14 ). But - I want to have an exception and use __int128 , and this gets me a warning:

warning: ISO C++ does not support ‘__int128’ for ‘hge’ [-Wpedantic]

Can I suppress the specific warning about __int128 ? Alternatively, can I temporary suppress -Wpedantic before and after the use of this type?

If we consult the documentation for -Wpedantic we can note the following:

Pedantic warnings are also disabled in the expression that follows __extension__ .

A quick bit of experimentation shows that this allows one to define variables as expected, even under the flag:

__extension__ __int128 hge{};

But of course that's rather cumbersome if we intended to use this type often. The way to make this less intractable is with a type alias. Though we need to be careful here, the __extension__ attribute must precede the entire declaration :

__extension__ typedef __int128 int128;

You can see it working here .


An alternative approach, and one that follows your original line of thought, is to use diagnostic pragmas around the type alias:

namespace my_gcc_ints {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"
    using int128 = __int128;
#pragma GCC diagnostic pop
}

Which also works rather well .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM