This is an archive of the discontinued LLVM Phabricator instance.

[libcxx] Fix gcc 4.9 -Wcast-qual warning.
AbandonedPublic

Authored by halyavin on Aug 24 2016, 4:40 AM.

Details

Summary

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.

Diff Detail

Event Timeline

halyavin updated this revision to Diff 69096.Aug 24 2016, 4:40 AM
halyavin retitled this revision from to Fix gcc 4.9 -Wcast-qual warning..
halyavin updated this object.
halyavin retitled this revision from Fix gcc 4.9 -Wcast-qual warning. to [libcxx] Fix gcc 4.9 -Wcast-qual warning..Aug 24 2016, 4:45 AM

Thank you for fixing most of warnings. Now it says "cc1plus: warning: unrecognized command line option "-Wno-c++14-compat"" though.

EricWF edited edge metadata.Aug 30 2016, 2:56 AM

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.

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.

Are you also compiling with -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER?

! 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.

EricWF resigned from this revision.Dec 30 2016, 2:04 AM
EricWF removed a reviewer: EricWF.

Resigning as a reviewer since this revision is dead.

halyavin abandoned this revision.Jan 1 2017, 10:32 AM