[libcxx-commits] [libcxx] [libc++] Implement LWG3430 disallow implicit conversion of the source arguments to `std::filesystem::path` when constructing `std::basic_*fstream` (PR #85079)
Nico Weber via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Apr 11 10:15:15 PDT 2024
nico wrote:
This breaks existing code, e.g. this:
```
std::fstream model_file(ml_package_dir()
.Append(kMlPackageDataDir)
.Append(kMlPackageModelFileName)
.value(),
std::ios::out | std::ios::binary);
```
`.value()` returns a `std::wstring`. (This is a Windows-only thing, which is probably why @ldionne didn't encounter it.)
Is the assumption that this will be rarely hit in practice?
<details>
<summary>full diag text</summary>
```
stderr:
../../services/webnn/coreml/graph_builder.cc(586,16): error: no matching constructor for initialization of 'std::fstream' (aka 'basic_fstream<char>')
586 | std::fstream model_file(ml_package_dir()
| ^ ~~~~~~~~~~~~~~~~
587 | .Append(kMlPackageDataDir)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
588 | .Append(kMlPackageModelFileName)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
589 | .value(),
| ~~~~~~~~~
590 | std::ios::out | std::ios::binary);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../third_party/libc++/src/include\fstream(1411,34): note: candidate constructor not viable: no known conversion from 'const StringType' (aka 'const basic_string<wchar_t>') to 'const char *' for 1st argument
1411 | _LIBCPP_HIDE_FROM_ABI explicit basic_fstream(const char* __s,
| ^ ~~~~~~~~~~~~~~~
../../third_party/libc++/src/include\fstream(1414,34): note: candidate constructor not viable: no known conversion from 'const StringType' (aka 'const basic_string<wchar_t>') to 'const wchar_t *' for 1st argument
1414 | _LIBCPP_HIDE_FROM_ABI explicit basic_fstream(const wchar_t* __s,
| ^ ~~~~~~~~~~~~~~~~~~
../../third_party/libc++/src/include\fstream(1417,34): note: candidate constructor not viable: no known conversion from 'const basic_string<wchar_t>' to 'const basic_string<char>' for 1st argument
1417 | _LIBCPP_HIDE_FROM_ABI explicit basic_fstream(const string& __s,
| ^ ~~~~~~~~~~~~~~~~~
../../third_party/libc++/src/include\fstream(1422,74): note: candidate template ignored: requirement 'is_same_v<std::wstring, std::filesystem::path>' was not satisfied [with _Tp = StringType]
1422 | _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY _LIBCPP_HIDE_FROM_ABI explicit basic_fstream(
| ^
../../third_party/libc++/src/include\fstream(1427,25): note: candidate constructor not viable: requires single argument '__rhs', but 2 arguments were provided
1427 | _LIBCPP_HIDE_FROM_ABI basic_fstream(basic_fstream&& __rhs);
| ^ ~~~~~~~~~~~~~~~~~~~~~
../../third_party/libc++/src/include\__fwd/fstream.h(28,28): note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 2 were provided
28 | class _LIBCPP_TEMPLATE_VIS basic_fstream;
| ^~~~~~~~~~~~~
../../third_party/libc++/src/include\fstream(1410,25): note: candidate constructor not viable: requires 0 arguments, but 2 were provided
1410 | _LIBCPP_HIDE_FROM_ABI basic_fstream();
| ^
```
</details>
(https://source.chromium.org/chromium/chromium/src/+/main:services/webnn/coreml/graph_builder.cc;l=586?q=services%2Fwebnn%2Fcoreml%2Fgraph_builder.cc)
https://github.com/llvm/llvm-project/pull/85079
More information about the libcxx-commits
mailing list