How to Disable Long Permanent Permanent Warning from GCC

I have code using large integer literals:

if(nanoseconds < 1'000'000'000'000) 

This gives a compiler warning integer constant is too large for 'long' type [-Wlong-long] . However, if I change it to:

 if(nanoseconds < 1'000'000'000'000ll) 

... Instead, I get a warning use of C++11 long long integer constant [-Wlong-long] .

I would like to disable this warning only for this line, but without disconnecting it for a long time or using -Wno-long-long for the whole project. I tried to surround him:

 #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wlong-long" ... #pragma GCC diagnostic pop 

but it doesn't seem to work with this warning. Is there anything else I can try?

I am -std=gnu++1z with -std=gnu++1z .

Edit: minimum comment example:

 #include <iostream> auto main()->int { double nanoseconds = 10.0; if(nanoseconds < 1'000'000'000'000ll) { std::cout << "hello" << std::endl; } return EXIT_SUCCESS; } 

Building with g++ -std=gnu++1z -Wlong-long test.cpp gives test.cpp:6:20: warning: use of C++11 long long integer constant [-Wlong-long]

I should mention this on a 32-bit Windows platform with MinGW-w64 (gcc 5.1.0) - the first warning does not appear on my 64-bit Linux systems, but the second (with ll suffix) appears on both.

+5
source share
1 answer

It seems that the C ++ 11 warning when using the ll suffix may be a gcc error . (Thanks @praetorian)

A workaround (inspired by @ nate-eldredge's comment) is to avoid using a literal and produce it at compile time using constexpr:

 int64_t constexpr const trillion = int64_t(1'000'000) * int64_t(1'000'000); if(nanoseconds < trillion) ... 
+3
source

Source: https://habr.com/ru/post/1235662/


All Articles