• 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...
cctest Loading commit data...
common Loading commit data...
debugger Loading commit data...
fuzzer Loading commit data...
inspector Loading commit data...
intl Loading commit data...
js-perf-test Loading commit data...
memory Loading commit data...
message Loading commit data...
mjsunit Loading commit data...
mkgrokdump Loading commit data...
mozilla Loading commit data...
preparser Loading commit data...
test262 Loading commit data...
unittests Loading commit data...
wasm-spec-tests Loading commit data...
webkit Loading commit data...
BUILD.gn Loading commit data...
bot_default.isolate Loading commit data...
d8_default.isolate Loading commit data...
default.isolate Loading commit data...
optimize_for_size.isolate Loading commit data...
perf.isolate Loading commit data...