-Werror
compiles a project and I don't want to suppress the entire error because of the Deprecated HeaderOnlyLibrary, but how do I suppress this library only? Is there a common method for gcc, clang, msvc?
Example:
deprecated.hpp
volatile intb=0;
voida(){
b + = 1;
}
main.cpp
#include "deprecated.hpp"
int main() {
a();
return 0;
}
Compilation error indication:
$g++main.cc-Wall-Wextra-Werror-std=gnu++2b
deprecated.hpp:In function 'void a()':
deprecated.hpp:4:6:error:compound assignment with 'volatile'-qualified left operand is deprecated [-Werror=volatile]
4 | b + = 1;
| ~^~~
cc1plus —all warnings being created as errors
I didn't really understand the intent of Deprecated, but if deprecated.hpp
is the system header, I think it's better to write #include<deprecated.hpp>
and if not, correct deprecated.hpp
.
The compiler makes a clear distinction between the system header and the normal header.The former is #include<filename>
, while the latter is #include "filename"
.
In addition, the GCC suppresses the warning if it is a system header (you can enable the warning in -Wsystem-headers
).MSVCs can also suppress alerts to system headers with /external:anglebrackets
.
There is a way to temporarily disable alerts in the preprocessor directive.
//Clang also defines _GNUC__.
# if defined (_clang__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wdeprecated-volatile"
# elif defined (__GNUC__)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored " - Wvolatile"
# elif defined(_MSC_VER)
# pragma warning (push)
//# pragma warning (disable:xxxx)
#endif
# include "hoge.hpp"
# if defined (_clang__)
# pragma clang diagnostic pop
# elif defined (__GNUC__)
# pragma GCC diagnostic pop
# elif defined(_MSC_VER)
# pragma warning (pop)
#endif
In addition, GCC/Clang uses -Wno-error
to always treat -Werror
as a warning instead of an error.
-Wno-error=deprecated-volatile
-Wno-error=volatile
It is not clear if there is a way to partially negate the /WX
on the MSVC to alert only certain numbers.
Refer to the following references for MSVCs:
< u l >In any case, we strongly recommend that you correct the user code without ignoring the warning.
© 2024 OneMinuteCode. All rights reserved.