Wednesday, January 5, 2022

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

Issue

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 make an exception to that rule and use __int128. 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?


Solution

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.



Answered By - StoryTeller - Unslander Monica