Skip to content

Fix WidenFilename deprecation warning on MinGW/Windows#2302

Closed
cary-ilm wants to merge 2 commits intoAcademySoftwareFoundation:mainfrom
cary-ilm:widenfilename-fix
Closed

Fix WidenFilename deprecation warning on MinGW/Windows#2302
cary-ilm wants to merge 2 commits intoAcademySoftwareFoundation:mainfrom
cary-ilm:widenfilename-fix

Conversation

@cary-ilm
Copy link
Copy Markdown
Member

@cary-ilm cary-ilm commented Mar 17, 2026

This fixes the warning:

2026-03-16T22:57:12.4648885Z D:/a/openexr/openexr/src/lib/OpenEXR/ImfMisc.cpp: In function 'std::wstring Imf_4_0::WidenFilename(const char*)':
2026-03-16T22:57:12.4732551Z D:/a/openexr/openexr/src/lib/OpenEXR/ImfMisc.cpp:2002:10: warning: 'template<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc> class std::__cxx11::wstring_convert' is deprecated [-Wdeprecated-declarations]
2026-03-16T22:57:12.4780038Z  2002 |     std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
2026-03-16T22:57:12.5292586Z       |          ^~~~~~~~~~~~~~~

Use MultiByteToWideChar(CP_UTF8) on Windows instead of std::wstring_convert/std::codecvt_utf8, which are deprecated in C++17 and trigger -Wdeprecated-declarations on GCC 15 / MinGW.

On non-Windows, keep using the deprecated API and suppress the warning with pragmas, since the standard library does not yet provide a replacement.

Made with the help of: Cursor / Claude Opus 4.5

Use MultiByteToWideChar(CP_UTF8) on Windows instead of
std::wstring_convert/std::codecvt_utf8, which are deprecated in C++17
and trigger -Wdeprecated-declarations on GCC 15 / MinGW.

On non-Windows, keep using the deprecated API and suppress the warning
with pragmas, since the standard library does not yet provide a
replacement.

Made with the help of: Cursor / Claude Opus 4.5
Signed-off-by: Cary Phillips <cary@ilm.com>
Comment thread src/lib/OpenEXR/ImfMisc.cpp Outdated

#include <codecvt>
#include <locale>
#if defined(_WIN32) || defined(_WIN64)
Copy link
Copy Markdown

@kmilos kmilos Mar 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for _WIN64, simple #ifdef _WIN32 is enough

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, thanks.

Comment thread src/lib/OpenEXR/ImfMisc.cpp Outdated
std::wstring
WidenFilename (const char* filename)
{
#if defined(_WIN32) || defined(_WIN64)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

MultiByteToWideChar (
CP_UTF8, 0, filename, -1, &result[0], len);
return result;
#else
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are wide strings needed on non-Windows platforms at all?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure, but presumably it's to keep the API consistent between Windows and Linux/macOS.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

presumably it's to keep the API consistent between Windows and Linux/macOS

Ok. But is that really required? AFAICT you'd never call WidenFilename outside of Windows anyway? Makes it easier/clear-cut to completely drop in the future potentially IMHO...

Signed-off-by: Cary Phillips <cary@ilm.com>
@cary-ilm
Copy link
Copy Markdown
Member Author

@darbyjohnston, looks like you added the WidenFilename function a while back. I'm try to reduce warnings in the build, and it's generating some. Is this something we can drop from the OpenEXR API entirely?

@darbyjohnston
Copy link
Copy Markdown
Contributor

Looking at my original PR, it looks like the WidenFilename function already existed and I just refactored it so it wasn't duplicated in the source code. It seems to only be used in the tests though, so probably does not need to be part of the public API.

Hmm, poking around some more there is also a version in internal_win32_file_impl.h that uses MultiByteToWideChar. Also the tests in OpenEXRCoreTest use MultiByteToWideChar directly instead of trying to reuse the widen_filename function.

If you don't mind a bit of code duplication we could remove 'WidenFilename' and replace it with MultiByteToWideChar.

@kmilos
Copy link
Copy Markdown

kmilos commented Mar 19, 2026

If you don't mind a bit of code duplication we could remove 'WidenFilename' and replace it with MultiByteToWideChar.

At the same time USE_WIDEN_FILEBUF code paths could be dropped, I think it is safe to assume/require MinGW GCC 9 at this point...

@cary-ilm
Copy link
Copy Markdown
Member Author

Replaced with #2314

@cary-ilm cary-ilm closed this Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants