Bug 234504

Summary: [Win] MSVC reports "DownloadBundleWin.cpp(87): error C2362: initialization of 'magic' is skipped by 'goto exit'" with /std:c++20
Product: WebKit Reporter: Fujii Hironori <Hironori.Fujii>
Component: PlatformAssignee: Fujii Hironori <Hironori.Fujii>
Status: RESOLVED FIXED    
Severity: Normal CC: achristensen, darin, don.olmstead, ross.kirsling, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 233448    
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch none

Description Fujii Hironori 2021-12-19 22:22:22 PST
[Win] MSVC reports "DownloadBundleWin.cpp(87): error C2362: initialization of 'magic' is skipped by 'goto exit'" with /std:c++20

> Source\WebCore\platform\network\win\DownloadBundleWin.cpp(87): error C2362: initialization of 'magic' is skipped by 'goto exit'
> Source\WebCore\platform\network\win\DownloadBundleWin.cpp(80): note: see declaration of 'magic'
> Source\WebCore\platform\network\win\DownloadBundleWin.cpp(87): note: see declaration of 'exit'
> Source\WebCore\platform\network\win\DownloadBundleWin.cpp(173): error C2362: initialization of 'footerStartPosition' is skipped by 'goto exit'
> Source\WebCore\platform\network\win\DownloadBundleWin.cpp(150): note: see declaration of 'footerStartPosition'
> Source\WebCore\platform\network\win\DownloadBundleWin.cpp(173): note: see declaration of 'exit'
> Source\WebCore\platform\network\win\DownloadBundleWin.cpp(173): error C2362: initialization of 'footerLength' is skipped by 'goto exit'
> Source\WebCore\platform\network\win\DownloadBundleWin.cpp(143): note: see declaration of 'footerLength'
> Source\WebCore\platform\network\win\DownloadBundleWin.cpp(173): note: see declaration of 'exit'
> Source\WebCore\platform\network\win\DownloadBundleWin.cpp(173): error C2362: initialization of 'footerLengthPosition' is skipped by 'goto exit'
> Source\WebCore\platform\network\win\DownloadBundleWin.cpp(135): note: see declaration of 'footerLengthPosition'
> Source\WebCore\platform\network\win\DownloadBundleWin.cpp(173): note: see declaration of 'exit'
> Source\WebCore\platform\network\win\DownloadBundleWin.cpp(173): error C2362: initialization of 'footerMagicNumber' is skipped by 'goto exit'
> Source\WebCore\platform\network\win\DownloadBundleWin.cpp(122): note: see declaration of 'footerMagicNumber'
> Source\WebCore\platform\network\win\DownloadBundleWin.cpp(173): note: see declaration of 'exit'
> Source\WebCore\platform\network\win\DownloadBundleWin.cpp(173): error C2362: initialization of 'footerMagicNumberPosition' is skipped by 'goto exit'
> Source\WebCore\platform\network\win\DownloadBundleWin.cpp(115): note: see declaration of 'footerMagicNumberPosition'
> Source\WebCore\platform\network\win\DownloadBundleWin.cpp(173): note: see declaration of 'exit'
Comment 1 Fujii Hironori 2021-12-19 22:25:12 PST
Created attachment 447584 [details]
Patch
Comment 2 Fujii Hironori 2021-12-20 12:50:37 PST
Created attachment 447624 [details]
Patch
Comment 3 Fujii Hironori 2021-12-20 12:57:48 PST
Created attachment 447626 [details]
Patch
Comment 4 EWS 2021-12-20 23:20:54 PST
Committed r287299 (245451@main): <https://commits.webkit.org/245451@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 447626 [details].
Comment 5 Radar WebKit Bug Importer 2021-12-20 23:21:16 PST
<rdar://problem/86755997>
Comment 6 Darin Adler 2021-12-21 01:07:27 PST
Comment on attachment 447626 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=447626&action=review

> Source/WebCore/platform/network/win/DownloadBundleWin.cpp:47
> +};

There should not be a semicolon here.

> Source/WebCore/platform/network/win/DownloadBundleWin.cpp:72
> +    std::unique_ptr<FILE, decltype(&fileCloser)> bundle(bundlePtr, &fileCloser);

Should be able to just write std::unique_ptr with no template arguments and rely on the deduction guide to deduce the argument types.

> Source/WebCore/platform/network/win/DownloadBundleWin.cpp:107
> +    std::unique_ptr<FILE, decltype(&fileCloser)> bundle(bundlePtr, &fileCloser);

Ditto.
Comment 7 Fujii Hironori 2021-12-21 12:06:33 PST
reopened.
Comment 8 Fujii Hironori 2021-12-21 14:05:04 PST
Comment on attachment 447626 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=447626&action=review

>> Source/WebCore/platform/network/win/DownloadBundleWin.cpp:72
>> +    std::unique_ptr<FILE, decltype(&fileCloser)> bundle(bundlePtr, &fileCloser);
> 
> Should be able to just write std::unique_ptr with no template arguments and rely on the deduction guide to deduce the argument types.

std::unique_ptr doesn't have the deduction guide.

  c++ - Why does std::unique_ptr not permit type inference? - Stack Overflow
  https://stackoverflow.com/q/41162868

  c++ - Why can't unique_ptr's template arguments be deduced? - Stack Overflow
  https://stackoverflow.com/q/51109767

And, I want to specify a deleter in this case.
And, C++17 lambda type doesn't have the default constructor.
C++20 can compile the following code.
> std::unique_ptr<FILE, decltype(&fileCloser)> bundle(bundlePtr);
Comment 9 Darin Adler 2021-12-21 14:38:33 PST
(In reply to Fujii Hironori from comment #8)
> std::unique_ptr doesn't have the deduction guide.

I understand why it can’t have one without a deleter; too bad it can’t have one with a deleter. Glad you investigated.
Comment 10 Fujii Hironori 2021-12-21 16:57:03 PST
Created attachment 447765 [details]
Patch
Comment 11 EWS 2021-12-24 13:40:58 PST
Committed r287432 (245567@main): <https://commits.webkit.org/245567@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 447765 [details].