mirror of
https://github.com/chromium/crashpad.git
synced 2025-03-09 14:06:33 +00:00
GCC 7.2 support (-Wnoexcept-type)
P0012R1, accepted into C++17, makes a function’s “noexcept” (or “throw()”) specification part of its signature. GCC 7.2 provides a warning, -Wnoexcept-type, that is triggered when a function pointer type with an exception specification is used in pre-C++17 code in such a way as to pose an ABI incompatibility with C++17 code. https://gcc.gnu.org/onlinedocs/gcc-7.2.0/gcc/C_002b_002b-Dialect-Options.html#index-Wnoexcept-type Warnings are of the form: In file included from ../../util/misc/from_pointer_cast_test.cc:15:0: ../../util/misc/from_pointer_cast.h:64:1: error: mangled name for ‘typename std::enable_if<(std::is_pointer<From>::value && std::is_pointer<_Tp>::value), To>::type crashpad::FromPointerCast(From) [with To = const volatile void*; From = void* (*)(long unsigned int) throw ()]’ will change in C++17 because the exception specification is part of a function type [-Werror=noexcept-type] FromPointerCast(From from) { ^~~~~~~~~~~~~~~ ../../util/misc/from_pointer_cast.h:64:1: error: mangled name for ‘typename std::enable_if<(std::is_pointer<From>::value && std::is_pointer<_Tp>::value), To>::type crashpad::FromPointerCast(From) [with To = volatile void*; From = void* (*)(long unsigned int) throw ()]’ will change in C++17 because the exception specification is part of a function type [-Werror=noexcept-type] In Crashpad, this warning is triggered by the two FromPointerCast<>() variants that accept function pointer “From” arguments. This occurs when using glibc as the standard C library, since glibc declares its functions as “throw()”. FromPointerCast<>() is used with pointers to glibc functions such as malloc() and getpid(). The warning is disabled for the FromPointerCast<>() variants that would trigger it. The warning is not useful or actionable in this internal Crashpad code where ABI changes due to language version (including mangling changes) are not a concern. Clang 4.0 has the similar -Wc++1z-compat-mangling option (also available as -Wc++17-compat-mangling and the GCC-compatible -Wnoexcept-type in Clang 5.0) but it is not triggered by this pattern. Change-Id: Id293db3954be415f67a55476ca72bfb7d399aa3b Reviewed-on: https://chromium-review.googlesource.com/738292 Reviewed-by: Joshua Peraza <jperaza@chromium.org> Commit-Queue: Mark Mentovai <mark@chromium.org>
This commit is contained in:
parent
6d5bd1d04d
commit
fbc365fa9e
@ -21,6 +21,7 @@
|
||||
#include <type_traits>
|
||||
|
||||
#include "base/numerics/safe_conversions.h"
|
||||
#include "build/build_config.h"
|
||||
|
||||
namespace crashpad {
|
||||
|
||||
@ -56,6 +57,20 @@ FromPointerCast(From) {
|
||||
return To();
|
||||
}
|
||||
|
||||
// FromPointerCast<>() with a function pointer “From” type raises
|
||||
// -Wnoexcept-type in GCC 7.2 if the function pointer type has a throw() or
|
||||
// noexcept specification. This is the case for all standard C library functions
|
||||
// provided by glibc. Various tests make use of FromPointerCast<>() with
|
||||
// pointers to standard C library functions.
|
||||
//
|
||||
// Clang has the similar -Wc++1z-compat-mangling, which is not triggered by this
|
||||
// pattern.
|
||||
#if defined(COMPILER_GCC) && !defined(__clang__) && \
|
||||
(__GNUC__ > 7 || (__GNUC__ == 7 && __GNUC_MINOR__ >= 2))
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wnoexcept-type"
|
||||
#endif
|
||||
|
||||
// Cast a pointer to any other pointer type.
|
||||
template <typename To, typename From>
|
||||
typename std::enable_if<std::is_pointer<From>::value &&
|
||||
@ -88,6 +103,11 @@ FromPointerCast(From from) {
|
||||
return base::checked_cast<To>(intermediate);
|
||||
}
|
||||
|
||||
#if defined(COMPILER_GCC) && !defined(__clang__) && \
|
||||
(__GNUC__ > 7 || (__GNUC__ == 7 && __GNUC_MINOR__ >= 2))
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
#endif // DOXYGEN
|
||||
|
||||
} // namespace crashpad
|
||||
|
Loading…
x
Reference in New Issue
Block a user