AcademySoftwareFoundation / AcademySoftwareFoundation/OpenColorIO
Build failure on GCC/MinGW (MXE): std::ifstream constructor mismatch with Platform::filenameToUTF()
- Vorherrschende Sprache
- C++
- Sterne
- 2.1k
- Forks
- 503
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
Description
OpenColorIO 2.5.1 fails to compile under GCC / MinGW-w64 (including MXE cross builds) due to inconsistent file path type handling in `Platform::filenameToUTF()` when used with `std::ifstream` in `FileTransform.cpp`.
The failure occurs when constructing a `std::ifstream` from the result of `Platform::filenameToUTF(filepath)`, where the returned type may vary between `std::string` and `std::wstring` depending on build configuration (`_WIN32 && UNICODE`).
This leads to template overload resolution failures under GCC/libstdc++ when a `std::wstring` is involved in `std::ifstream` construction.
Error observed (GCC / libstdc++)
```bash
error: no matching function for call to
std::basic_ifstream::basic_ifstream(const std::wstring, std::ios_base::openmode)
```
Affected code `src/OpenColorIO/transforms/FileTransform.cpp`:
```cpp
std::ifstream(Platform::filenameToUTF(filepath), mode)
```
Root cause
- `Platform::filenameToUTF()` is conditionally typed:
- `std::wstring` on _WIN32 && UNICODE
- `std::string` otherwise
- `std::ifstream` construction from `std::wstring` is not consistently supported across standard library implementations
- GCC/libstdc++ rejects this usage, while MSVC may accept it depending on STL implementation details
- This creates a portability issue in file I/O path handling
Impact
- Breaks MXE / MinGW-w64 cross compilation
- Causes divergence between MSVC and GCC builds
- Introduces non-portable file path handling in core I/O utilities
Suggested fix
Avoid passing platform-dependent string types directly into `std::ifstream` construction.
This is the C++17-compatible solution that worked:
```cpp
auto path = Platform::filenameToUTF(filepath);
return std::make_unique(path.c_str(), mode);
```
Beitragsleitfaden
Rechercherichtung
Beginnen Sie in src/OpenColorIO/transforms/FileTransform.cpp und untersuchen Sie die Konstruktion von std::ifstream mit Platform::filenameToUTF(filepath). Bauen Sie OpenColorIO mit GCC/MinGW-w64 oder MXE, um den Fehler bei der std::wstring-Überladung zu reproduzieren, und überprüfen Sie anschließend, dass die Pfadverarbeitung in den betroffenen Konfigurationen kompiliert und funktioniert.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- cpp
- Bereich
- build-system
- Issue-Typ
- Bug
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Aktivitätsstatus
- Ruhig
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 78/100