Bug 204870 - [MSVC] WebResourceLoadStatisticsStore.h is reporting warning C4804: '/': unsafe use of type 'bool' in operation
Summary: [MSVC] WebResourceLoadStatisticsStore.h is reporting warning C4804: '/': unsa...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Kate Cheney
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-12-04 19:47 PST by Fujii Hironori
Modified: 2019-12-05 10:30 PST (History)
4 users (show)

See Also:


Attachments
Patch (1.75 KB, patch)
2019-12-05 08:47 PST, Kate Cheney
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Fujii Hironori 2019-12-04 19:47:34 PST
[MSVC] WebResourceLoadStatisticsStore.h is reporting warning C4804: '/': unsafe use of type 'bool' in operation

Since r253118 (Bug 203432)
https://build.webkit.org/builders/WinCairo%2064-bit%20WKL%20Release%20%28Build%29/builds/13884

[18/43] Building CXX object Source\WebKit\CMakeFiles\WebKit.dir\__\__\WebKit\DerivedSources\NetworkProcessMessageReceiver.cpp.obj
C:\WebKit-BuildWorker\wincairo-wkl-release\build\WebKitBuild\Release\WTF\Headers\wtf/text/IntegerToStringConversion.h(104): warning C4804: '/=': unsafe use of type 'bool' in operation
C:\WebKit-BuildWorker\wincairo-wkl-release\build\WebKitBuild\Release\WTF\Headers\wtf/text/IntegerToStringConversion.h(124): note: see reference to function template instantiation 'unsigned int WTF::lengthOfNumberAsStringImpl<UnsignedIntegerType,WTF::PositiveNumber>(UnsignedIntegerType)' being compiled
        with
        [
            UnsignedIntegerType=bool
        ]
C:\WebKit-BuildWorker\wincairo-wkl-release\build\WebKitBuild\Release\WTF\Headers\wtf/text/StringConcatenateNumbers.h(58): note: see reference to function template instantiation 'unsigned int WTF::lengthOfNumberAsStringUnsigned<UnsignedInt>(UnsignedIntegerType)' being compiled
        with
        [
            UnsignedInt=bool,
            UnsignedIntegerType=bool
        ]
C:\WebKit-BuildWorker\wincairo-wkl-release\build\WebKitBuild\Release\WTF\Headers\wtf/text/StringConcatenateNumbers.h(58): note: while compiling class template member function 'unsigned int WTF::StringTypeAdapter<bool,void>::length(void) const'
C:\WebKit-BuildWorker\wincairo-wkl-release\build\WebKitBuild\Release\WTF\Headers\wtf/text/StringConcatenate.h(319): note: see reference to function template instantiation 'unsigned int WTF::StringTypeAdapter<bool,void>::length(void) const' being compiled
C:\WebKit-BuildWorker\wincairo-wkl-release\build\WebKitBuild\Release\WTF\Headers\wtf/text/StringConcatenate.h(348): note: see reference to class template instantiation 'WTF::StringTypeAdapter<bool,void>' being compiled
C:\WebKit-BuildWorker\wincairo-wkl-release\build\WebKitBuild\Release\WTF\Headers\wtf/text/StringConcatenate.h(354): note: see reference to function template instantiation 'WTF::String WTF::tryMakeString<const char*,WTF::String,const char*,bool>(const char *,WTF::String,const char *,bool)' being compiled
C:\WebKit-BuildWorker\wincairo-wkl-release\build\Source\WebKit\NetworkProcess\Classifier\WebResourceLoadStatisticsStore.h(87): note: see reference to function template instantiation 'WTF::String WTF::makeString<const char*,WTF::String,const char*,bool>(const char *,WTF::String,const char *,bool)' being compiled
C:\WebKit-BuildWorker\wincairo-wkl-release\build\WebKitBuild\Release\WTF\Headers\wtf/text/IntegerToStringConversion.h(104): warning C4804: '/': unsafe use of type 'bool' in operation
C:\WebKit-BuildWorker\wincairo-wkl-release\build\WebKitBuild\Release\WTF\Headers\wtf/text/IntegerToStringConversion.h(72): warning C4804: '%': unsafe use of type 'bool' in operation
C:\WebKit-BuildWorker\wincairo-wkl-release\build\WebKitBuild\Release\WTF\Headers\wtf/text/IntegerToStringConversion.h(94): note: see reference to function template instantiation 'void WTF::writeNumberToBufferImpl<CharacterType,UnsignedIntegerType,WTF::PositiveNumber>(UnsignedIntegerType,CharacterType *)' being compiled
        with
        [
            CharacterType=LChar,
            UnsignedIntegerType=bool
        ]
C:\WebKit-BuildWorker\wincairo-wkl-release\build\WebKitBuild\Release\WTF\Headers\wtf/text/StringConcatenateNumbers.h(60): note: see reference to function template instantiation 'void WTF::writeNumberToBufferUnsigned<CharacterType,UnsignedInt>(UnsignedIntegerType,CharacterType *)' being compiled
        with
        [
            CharacterType=LChar,
            UnsignedInt=bool,
            UnsignedIntegerType=bool
        ]
C:\WebKit-BuildWorker\wincairo-wkl-release\build\WebKitBuild\Release\WTF\Headers\wtf/text/StringConcatenate.h(305): note: see reference to function template instantiation 'void WTF::StringTypeAdapter<bool,void>::writeTo<ResultType>(CharacterType *) const' being compiled
        with
        [
            ResultType=LChar,
            CharacterType=LChar
        ]
C:\WebKit-BuildWorker\wincairo-wkl-release\build\WebKitBuild\Release\WTF\Headers\wtf/text/StringConcatenate.h(305): note: see reference to function template instantiation 'void WTF::StringTypeAdapter<bool,void>::writeTo<ResultType>(CharacterType *) const' being compiled
        with
        [
            ResultType=LChar,
            CharacterType=LChar
        ]
C:\WebKit-BuildWorker\wincairo-wkl-release\build\WebKitBuild\Release\WTF\Headers\wtf/text/StringConcatenate.h(310): note: see reference to function template instantiation 'void WTF::stringTypeAdapterAccumulator<ResultType,WTF::StringTypeAdapter<bool,void>>(ResultType *,Adapter)' being compiled
        with
        [
            ResultType=LChar,
            Adapter=WTF::StringTypeAdapter<bool,void>
        ]
C:\WebKit-BuildWorker\wincairo-wkl-release\build\WebKitBuild\Release\WTF\Headers\wtf/text/StringConcatenate.h(310): note: see reference to function template instantiation 'void WTF::stringTypeAdapterAccumulator<ResultType,WTF::StringTypeAdapter<const char*,void>,WTF::StringTypeAdapter<bool,void>>(ResultType *,Adapter,WTF::StringTypeAdapter<bool,void>)' being compiled
        with
        [
            ResultType=LChar,
            Adapter=WTF::StringTypeAdapter<const char*,void>
        ]
C:\WebKit-BuildWorker\wincairo-wkl-release\build\WebKitBuild\Release\WTF\Headers\wtf/text/StringConcatenate.h(310): note: see reference to function template instantiation 'void WTF::stringTypeAdapterAccumulator<ResultType,WTF::StringTypeAdapter<WTF::String,void>,WTF::StringTypeAdapter<const char*,void>,WTF::StringTypeAdapter<bool,void>>(ResultType *,Adapter,WTF::StringTypeAdapter<const char*,void>,WTF::StringTypeAdapter<bool,void>)' being compiled
        with
        [
            ResultType=LChar,
            Adapter=WTF::StringTypeAdapter<WTF::String,void>
        ]
C:\WebKit-BuildWorker\wincairo-wkl-release\build\WebKitBuild\Release\WTF\Headers\wtf/text/StringConcatenate.h(317): note: see reference to function template instantiation 'void WTF::stringTypeAdapterAccumulator<LChar,StringTypeAdapter,WTF::StringTypeAdapter<WTF::String,void>,WTF::StringTypeAdapter<const char*,void>,WTF::StringTypeAdapter<bool,void>>(ResultType *,Adapter,WTF::StringTypeAdapter<WTF::String,void>,WTF::StringTypeAdapter<const char*,void>,WTF::StringTypeAdapter<bool,void>)' being compiled
        with
        [
            StringTypeAdapter=WTF::StringTypeAdapter<const char*,void>,
            ResultType=LChar,
            Adapter=WTF::StringTypeAdapter<const char*,void>
        ]
C:\WebKit-BuildWorker\wincairo-wkl-release\build\WebKitBuild\Release\WTF\Headers\wtf/text/StringConcatenate.h(348): note: see reference to function template instantiation 'WTF::String WTF::tryMakeStringFromAdapters<WTF::StringTypeAdapter<const char*,void>,WTF::StringTypeAdapter<WTF::String,void>,WTF::StringTypeAdapter<const char*,void>,WTF::StringTypeAdapter<bool,void>>(StringTypeAdapter,WTF::StringTypeAdapter<WTF::String,void>,WTF::StringTypeAdapter<const char*,void>,WTF::StringTypeAdapter<bool,void>)' being compiled
        with
        [
            StringTypeAdapter=WTF::StringTypeAdapter<const char*,void>
        ]
C:\WebKit-BuildWorker\wincairo-wkl-release\build\WebKitBuild\Release\WTF\Headers\wtf/text/IntegerToStringConversion.h(73): warning C4804: '/=': unsafe use of type 'bool' in operation
C:\WebKit-BuildWorker\wincairo-wkl-release\build\WebKitBuild\Release\WTF\Headers\wtf/text/IntegerToStringConversion.h(73): warning C4804: '/': unsafe use of type 'bool' in operation
Comment 1 Fujii Hironori 2019-12-04 20:14:25 PST
This can be solved by

1. storageAccessGranted ? "0" : "1"
2. unsigned(storageAccessGranted)
3. Change makeString to explitly accept bool type

#3 seems better for MSVC.
Comment 2 Fujii Hironori 2019-12-04 21:19:26 PST
GCC and Clang doesn't report warnings for bool / 10.
https://godbolt.org/z/RjKz-m
Comment 3 Fujii Hironori 2019-12-04 21:57:33 PST
(In reply to Fujii Hironori from comment #1)
> #3 seems better for MSVC.

Filed: Bug 204873 – [MSVC] writeNumberToBufferUnsigned is unsafe for bool type
Comment 4 Darin Adler 2019-12-05 07:33:48 PST
I suggest doing (1) for now. Or could do this more efficient version:

    storageAccessGranted ? '0' : '1'

Then I suggest we consider either adding support for bool or disabling use of bool in makeString. But I don’t think a bool should necessarily serialize as "0"/"1".
Comment 5 Kate Cheney 2019-12-05 08:47:32 PST
Created attachment 384906 [details]
Patch
Comment 6 WebKit Commit Bot 2019-12-05 10:29:22 PST
Comment on attachment 384906 [details]
Patch

Clearing flags on attachment: 384906

Committed r253155: <https://trac.webkit.org/changeset/253155>
Comment 7 WebKit Commit Bot 2019-12-05 10:29:24 PST
All reviewed patches have been landed.  Closing bug.
Comment 8 Radar WebKit Bug Importer 2019-12-05 10:30:20 PST
<rdar://problem/57668408>