Fix or suppress GCC warnings during build.
Summary: Currently a number of GCC warnings are emitted when building libc++. This patch fixes or ignores all of them. The primary changes are: * Work around strict aliasing issues in `typeinfo::hash_code()` by using __attribute__((may_alias)). However I think a non-aliasing `hash_code()` implementation is possible. Further investigation needed. * Add `_LIBCPP_UNREACHABLE()` to switch in `strstream.cpp` to avoid -Wpotentially-uninitialized. * Fix -Wunused-value warning in `__all` by adding a void cast. * Ignore -Wattributes for now. There are a number of real attribute issues when using GCC but enabling the warning is too noisy. * Ignore -Wliteral-suffix since it warns about the use of reserved identifiers. Note Only GCC 7.0 supports disabling this warning. * Ignore -Wc++14-compat since it warns about the sized new/delete overloads. Reviewers: EricWF Differential Revision: https://reviews.llvm.org/D24003 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@280007 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -322,10 +322,19 @@ add_compile_flags_if_supported(-nostdinc++)
|
|||||||
# Warning flags ===============================================================
|
# Warning flags ===============================================================
|
||||||
add_definitions(-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
add_definitions(-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||||
add_compile_flags_if_supported(
|
add_compile_flags_if_supported(
|
||||||
-Wall -W -Wwrite-strings
|
-Wall -Wextra -W -Wwrite-strings
|
||||||
-Wno-unused-parameter -Wno-long-long -Wno-user-defined-literals
|
-Wno-unused-parameter -Wno-long-long
|
||||||
-Wno-covered-switch-default
|
|
||||||
-Werror=return-type)
|
-Werror=return-type)
|
||||||
|
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
|
||||||
|
add_compile_flags_if_supported(
|
||||||
|
-Wno-user-defined-literals
|
||||||
|
-Wno-covered-switch-default)
|
||||||
|
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
|
||||||
|
add_compile_flags_if_supported(
|
||||||
|
-Wno-attributes # FIXME: Fix -Wattribute warnings.
|
||||||
|
-Wno-literal-suffix
|
||||||
|
-Wno-c++14-compat)
|
||||||
|
endif()
|
||||||
if (LIBCXX_ENABLE_WERROR)
|
if (LIBCXX_ENABLE_WERROR)
|
||||||
add_compile_flags_if_supported(-Werror)
|
add_compile_flags_if_supported(-Werror)
|
||||||
add_compile_flags_if_supported(-WX)
|
add_compile_flags_if_supported(-WX)
|
||||||
|
|||||||
@@ -691,6 +691,12 @@ template <unsigned> struct __static_assert_check {};
|
|||||||
#define _NOALIAS
|
#define _NOALIAS
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#define _LIBCPP_MAY_ALIAS __attribute__((__may_alias__))
|
||||||
|
#else
|
||||||
|
#define _LIBCPP_MAY_ALIAS
|
||||||
|
#endif
|
||||||
|
|
||||||
#if __has_feature(cxx_explicit_conversions) || defined(__IBMCPP__)
|
#if __has_feature(cxx_explicit_conversions) || defined(__IBMCPP__)
|
||||||
# define _LIBCPP_EXPLICIT explicit
|
# define _LIBCPP_EXPLICIT explicit
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -374,7 +374,7 @@ template <bool ..._Preds>
|
|||||||
struct __all_dummy;
|
struct __all_dummy;
|
||||||
|
|
||||||
template <bool ..._Pred>
|
template <bool ..._Pred>
|
||||||
using __all = is_same<__all_dummy<_Pred...>, __all_dummy<(_Pred, true)...>>;
|
using __all = is_same<__all_dummy<_Pred...>, __all_dummy<((void)_Pred, true)...>>;
|
||||||
|
|
||||||
struct __tuple_sfinae_base {
|
struct __tuple_sfinae_base {
|
||||||
template <template <class, class...> class _Trait,
|
template <template <class, class...> class _Trait,
|
||||||
|
|||||||
@@ -89,6 +89,12 @@ void *aligned_alloc(size_t alignment, size_t size); // C11
|
|||||||
#pragma GCC system_header
|
#pragma GCC system_header
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#define _LIBCPP_UNREACHABLE() __builtin_unreachable()
|
||||||
|
#else
|
||||||
|
#define _LIBCPP_UNREACHABLE() _VSTD::abort()
|
||||||
|
#endif
|
||||||
|
|
||||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||||
|
|
||||||
using ::size_t;
|
using ::size_t;
|
||||||
|
|||||||
@@ -73,6 +73,9 @@ class _LIBCPP_EXCEPTION_ABI type_info
|
|||||||
{
|
{
|
||||||
type_info& operator=(const type_info&);
|
type_info& operator=(const type_info&);
|
||||||
type_info(const type_info&);
|
type_info(const type_info&);
|
||||||
|
|
||||||
|
typedef size_t _LIBCPP_MAY_ALIAS _ASizeT; // Avoid strict-aliasing issues.
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
#ifndef _LIBCPP_NONUNIQUE_RTTI_BIT
|
#ifndef _LIBCPP_NONUNIQUE_RTTI_BIT
|
||||||
const char* __type_name;
|
const char* __type_name;
|
||||||
@@ -113,7 +116,7 @@ public:
|
|||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
size_t hash_code() const _NOEXCEPT
|
size_t hash_code() const _NOEXCEPT
|
||||||
#ifndef _LIBCPP_NONUNIQUE_RTTI_BIT
|
#ifndef _LIBCPP_NONUNIQUE_RTTI_BIT
|
||||||
{return *reinterpret_cast<const size_t*>(&__type_name);}
|
{return *reinterpret_cast<const _ASizeT *>(&__type_name);}
|
||||||
#else
|
#else
|
||||||
{if (!(__type_name & _LIBCPP_NONUNIQUE_RTTI_BIT)) return __type_name;
|
{if (!(__type_name & _LIBCPP_NONUNIQUE_RTTI_BIT)) return __type_name;
|
||||||
const char *__ptr = name();
|
const char *__ptr = name();
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include "algorithm"
|
#include "algorithm"
|
||||||
#include "climits"
|
#include "climits"
|
||||||
#include "cstring"
|
#include "cstring"
|
||||||
|
#include "cstdlib"
|
||||||
#include "__debug"
|
#include "__debug"
|
||||||
|
|
||||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||||
@@ -266,6 +267,8 @@ strstreambuf::seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmod
|
|||||||
case ios::end:
|
case ios::end:
|
||||||
newoff = seekhigh - eback();
|
newoff = seekhigh - eback();
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
_LIBCPP_UNREACHABLE();
|
||||||
}
|
}
|
||||||
newoff += __off;
|
newoff += __off;
|
||||||
if (0 <= newoff && newoff <= seekhigh - eback())
|
if (0 <= newoff && newoff <= seekhigh - eback())
|
||||||
|
|||||||
Reference in New Issue
Block a user