Skip to content

Fix modern MSVC compilation error on experimental/filesystem#8469

Merged
bob80905 merged 7 commits into
microsoft:mainfrom
bob80905:update_containertest_headers
May 26, 2026
Merged

Fix modern MSVC compilation error on experimental/filesystem#8469
bob80905 merged 7 commits into
microsoft:mainfrom
bob80905:update_containertest_headers

Conversation

@bob80905
Copy link
Copy Markdown
Collaborator

Modern MSVC deperecated experimental/filesystem.
This causes build failures when building DXC with MSVC.
The deprecation occurred on version 1922, so we should account for this removal, instead of silencing deprecation warnings.

@bob80905 bob80905 changed the title Fix modern MSVC compilation error Fix modern MSVC compilation error on experimental/filesystem May 21, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 21, 2026

✅ With the latest revision this PR passed the C/C++ code formatter.

namespace fs = std::filesystem;
#else
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Not sure which compiler this else case covers?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I consulted an AI, and basically it looks like really old compilers would be covered by this case:
GCC 5.3 – 7.x
Pre-2014 GCC / Clang without __has_include
Clang with an old libstdc++/libc++

are some examples.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do we even support compilers that old for building dxc? LLVM has a cut off. Not sure if DXC ever required a minimum compiler version.

Copy link
Copy Markdown
Member

@hekota hekota May 22, 2026

Choose a reason for hiding this comment

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

GCC 8 came out in 2018, and I don't think we should support compilers older than that. I think you can remove the #elif condition and just fall back to #include <filesystem>.

namespace fs = std::filesystem;
#endif
#elif defined(__has_include) && __has_include(<filesystem>) && \
(defined(__clang__) || !defined(__GNUC__) || __GNUC__ >= 8)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why do we need to check && \ (defined(__clang__) || !defined(__GNUC__) || __GNUC__ >= 8) why isn't just checking for the feature sufficient?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

As for GNUC >= 8: GCC 7 ships but doesn't actually define std::filesystem. Header exists, namespace doesn't -> compile error. GCC 8 is the first version where it really works.
For the defined(clang) check: Clang sets GNUC == 4, so the >= 8 check would wrongly reject it. The clause basically says "if it's Clang, skip the GCC version check."

Copy link
Copy Markdown
Collaborator

@farzonl farzonl left a comment

Choose a reason for hiding this comment

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

This looks correct. some stuff seems a bit extra but not a reason to hold up the pr.


#if defined(_MSC_VER)
// MSVC removed <experimental/filesystem> starting in VS 2019 16.3 (_MSC_VER >= 1922)
#if _MSC_VER < 1922
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
#if _MSC_VER < 1922
#if (_MSC_VER >= 1920) && (_MSC_VER < 1922)

experimental::filesystem was enabled since version 1920, so it needs to be included in the check.

namespace fs = std::filesystem;
#else
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
Copy link
Copy Markdown
Member

@hekota hekota May 22, 2026

Choose a reason for hiding this comment

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

GCC 8 came out in 2018, and I don't think we should support compilers older than that. I think you can remove the #elif condition and just fall back to #include <filesystem>.

@bob80905 bob80905 enabled auto-merge (squash) May 26, 2026 20:42
@bob80905 bob80905 merged commit d4240bc into microsoft:main May 26, 2026
13 checks passed
@github-project-automation github-project-automation Bot moved this from New to Done in HLSL Roadmap May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants