Homec4science

Fix -Wmicrosoft-cast warnings when using gtest with clang on Windows.

Authored by Nico Weber <thakis@chromium.org> on May 15 2017, 23:21.

Description

Fix -Wmicrosoft-cast warnings when using gtest with clang on Windows.

This upstreams a Google-internal change.

Original CL description:
The C++ standard says that function pointers are not implicitly
convertible to object pointers. Visual Studio disregards that and allows
implicit conversion between function pointers and object points, and
enough code relies on this that clang follows suit in
Microsoft-compatibility mode.

However, clang emits a -Wmicrosoft-cast warning when such a conversion
is done:

E:\b\c\b\win_clang\src\sandbox\win\src\sync_dispatcher.cc(42,7):

warning: implicit conversion between pointer-to-function and
         pointer-to-object is a Microsoft extension [-Wmicrosoft-cast]

This change fixes this warning in gtest, while hopefully not changing
any behavior. The change does two things:

  1. It replaces the if in DefaultPrintTo with SFINAE
  2. In C++11 mode, it uses enable_if<is_function<>> instead of ImplicitlyConvertible<T*, const void*> to check if the explicit cast is needed.

With this change, functions will use the branch with the reintpret_casts
with Visual Studio and clang/win, and clang no longer needs to warn
that it implicitly converts a function pointer to a void pointer.

Details

Committed
Nico Weber <thakis@chromium.org>May 15 2017, 23:21
Pushed
trottetDec 4 2019, 13:52
Parents
R9484:294f72bc773c: Merge pull request #725 from donhuff/xcode-headers
Branches
Unknown
Tags
Unknown
[HTTP/500] Internal Server Error FilesystemException: Failed to create a temporary directory: the disk is full.

Event Timeline

Nico Weber <thakis@chromium.org> committed R9484:b2cbbec04c14: Fix -Wmicrosoft-cast warnings when using gtest with clang on Windows. (authored by Nico Weber <thakis@chromium.org>).May 15 2017, 23:21