• Nico Weber's avatar
    Make v8 build with -Wmicrosoft-cast under clang-cl. · 58b386c4
    Nico Weber authored
    gcc and clang (and the standard) don't allow implicit conversion of
    function pointers to object pointers. MSVC does allow that, and since
    system headers require this to work, clang-cl allows it too -- but
    it emits a -Wmicrosoft-cast warning (which we currently suppress in
    the Chromium build, but which we want to enable.)
    
    As a side effect, when printing a function pointer to a stream, MSVC
    (and clang-cl) will pick the operator<<(void*) overload, while gcc
    and clang will pick operator<<(bool) since the best allowed conversion
    they find is from function pointer to bool.
    
    To prevent the clang-cl warning, we need to make sure that we never
    directly print a function pointer to a stream. In v8, this requires
    two changes:
    
    1. Give PrintCheckOperand() an explicit specialization for function
       pointers and explicitly cast to void* there.  This ports
       https://codereview.chromium.org/2515283002/ to V8, and also fixes a
       bug on non-Windows where DCHECK() of function pointers would print
       "(1 vs 1)" instead of the function's addresses.
       (The bug remains with member function pointers,
       where it's not clear what to print instead of the 1.)
    
    2. has_output_operator<T> must not use operator<< on its argument
       in an evaluated context if T is a function pointer.  This patch
       modifies has_output_operator<> to use an unevaluated context instead,
       which is simpler than the current approach (and matches what Chromium's
       base does), but changes behavior    in minor (boring) ways
       (see template-utils-unittest.cc), since operator<<() is now
       called with a temporary and only operator<<() implementations callable
       with a temporary are considered.
       A more complicated but behavior-preserving alternative would be to
       add an explicit specialization for function pointers. You can see
       this variant in patch set 1 on gerrit.
    
    Bug: chromium:550065
    Change-Id: Idc2854d6c258b7fc0b959604006d8952a79eca3d
    Reviewed-on: https://chromium-review.googlesource.com/940004
    Commit-Queue: Nico Weber <thakis@chromium.org>
    Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#51636}
    58b386c4
Name
Last commit
Last update
benchmarks Loading commit data...
build_overrides Loading commit data...
docs Loading commit data...
gni Loading commit data...
include Loading commit data...
infra Loading commit data...
samples Loading commit data...
src Loading commit data...
test Loading commit data...
testing Loading commit data...
third_party Loading commit data...
tools Loading commit data...
.clang-format Loading commit data...
.editorconfig Loading commit data...
.git-blame-ignore-revs Loading commit data...
.gitignore Loading commit data...
.gn Loading commit data...
.vpython Loading commit data...
.ycm_extra_conf.py Loading commit data...
AUTHORS Loading commit data...
BUILD.gn Loading commit data...
CODE_OF_CONDUCT.md Loading commit data...
ChangeLog Loading commit data...
DEPS Loading commit data...
LICENSE Loading commit data...
LICENSE.fdlibm Loading commit data...
LICENSE.strongtalk Loading commit data...
LICENSE.v8 Loading commit data...
LICENSE.valgrind Loading commit data...
OWNERS Loading commit data...
PRESUBMIT.py Loading commit data...
README.md Loading commit data...
WATCHLISTS Loading commit data...
codereview.settings Loading commit data...
snapshot_toolchain.gni Loading commit data...