C-style cast from const pointer to non-const pointer causes -Wcast-qual warning in gcc. Fix the problem by casting away const with const_cast. Additionally, replace C-style cast with appropriate C++-style cast.
Details
Diff Detail
Event Timeline
Thank you for fixing most of warnings. Now it says "cc1plus: warning: unrecognized command line option "-Wno-c++14-compat"" though.
No worries, it was driving me nuts. The addition of -Wno-c++14-compat and -Wno-literal-suffix targets GCC 5.x+ and 7.0+ respectively. It's almost impossible to detect the validity of -Wno-<warning> flags, I fear these warnings are here to stay for older GCC versions. Thankfully GCC does not emit a "unrecognized command line option" diagnostic on otherwise warning-free code, so if we can fix the other diagnostics we can suppress this one.
The reason I'm dragging my feet on this patch is I'm not sure the two formulations are *exactly* equivalent. I need to re-read the standard to be sure.
What's the motivation for fixing a warning which libc++ never tests against? Normally the headers are treated as system headers so all warnings are ignored.
We have libc++ in our source tree and compile it as part of our build process. All code in the source tree uses -Werror by default, so I am having compile errors on gcc 4.9.
! In D23831#528668, @EricWF wrote:
Are you also compiling with -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER?
No. Libc++ buildbots doesn't set this option either and we do see warnings there. So the pragma doesn't help with compiling libc++ itself.
False alarm. I figured out that only -Wattributes warnings ignore gcc system_header pragma. So this -Wcast-qual and other warnings doesn't block us.