8

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?

einpoklum
  • 118,144
  • 57
  • 340
  • 684
  • 1
    Have you added a `-std=` flag to select a specific C++ standard? Please tell us *all* flags you pass to the compiler. – Some programmer dude Feb 12 '19 at 11:26
  • @Someprogrammerdude: Edited. – einpoklum Feb 12 '19 at 13:23
  • I did some more experimentation. The original answer had a kludge because the proper use of `__extension__ ` is a bit non-intuitive. The answer is amended with the straightforward solution. – StoryTeller - Unslander Monica Feb 12 '19 at 13:30
  • 1
    With `-std=c++14` you tell the compiler to adhere more strictly to the C++ standard, without GCC extensions. Try e.g. `-std=gnu++14` instead to enable GCC extensions. – Some programmer dude Feb 12 '19 at 13:42
  • 1
    @Someprogrammerdude: I _want_ adherence to the C++ standard. `gnu++14` will allow code that contradicts the standard, while `__int128` is not standardized, but is AFAICT a "legitimate" extension. – einpoklum Feb 12 '19 at 17:31

1 Answers1

12

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.

einpoklum
  • 118,144
  • 57
  • 340
  • 684
StoryTeller - Unslander Monica
  • 165,132
  • 21
  • 377
  • 458