slang_process: undef DXSDK SAL macros before STL includes (CXX_BUILD)

Under CXX_BUILD=1 the d3d10/d3d11/d3d12 drivers are compiled as C++
and pull in <vector>/<string>/<unordered_map> via slang_process.h.
Those translation units first include the DirectX headers, whose
SAL-compat shims (gfx/common/dxgi_common.h and
gfx/include/dxsdk/dxsdk_sal_compat.h) #define annotation tokens like
__out / __in / __inout to nothing so the bundled DXSDK headers parse.

Those macro names are not reserved against libstdc++'s own internals:
<bits/c++locale.h>'s std::__convert_from_v() has a parameter literally
named __out, and the call

  __builtin_vsnprintf(__out, __size, __fmt, __args)

becomes

  __builtin_vsnprintf( , __size, __fmt, __args)

once the empty __out macro is applied, producing

  c++locale.h:74: error: expected primary-expression before ',' token

(plus a cascade of std::move / tuple template noise as the corrupted
header derails further parsing).

The SAL macros are only needed while the DX headers are being parsed;
nothing downstream of slang_process.h uses them. Undef the full set
immediately before the STL includes (inside the existing __cplusplus
block, so the C build is unaffected). This is the single point every
d3d1x TU funnels through for its STL includes, so one fix covers all
three drivers regardless of which DX header leaked the macro.

Verified the mechanism in isolation: an empty '#define __out'
reproduces the exact c++locale.h error, and '#undef __out' before the
equivalent construct compiles clean.

Follow-up to the CXX_BUILD fixes in 059ca26 / 7712d87 / a624ae1.
This commit is contained in:
libretroadmin authored and libretroadmin committed 2026-06-25 10:00:41 +02:00
1 parent a624ae15bb
commit 8102d806de
1 file changed
+27
+27
View File
@@ -183,6 +183,33 @@ bool slang_process(
RETRO_END_DECLS
#ifdef __cplusplus
/* The DirectX SAL-compat shims (dxgi_common.h / dxsdk_sal_compat.h)
* #define annotation tokens such as __out / __in / __inout to nothing
* so the bundled DXSDK headers parse. Those names collide with real
* identifiers inside libstdc++ -- e.g. std::__convert_from_v() in
* <bits/c++locale.h> has a parameter literally named __out -- so if a
* SAL macro is still live when the STL headers below are parsed, the
* token is erased and the header fails to compile (this only bites
* under CXX_BUILD, where these .c files are compiled as C++ and pull
* in <vector>/<string>/<unordered_map>). Undef them here, after the
* DX headers have already consumed them and before the STL includes. */
#undef __in
#undef __out
#undef __inout
#undef __in_opt
#undef __out_opt
#undef __inout_opt
#undef __in_ecount
#undef __out_ecount
#undef __in_ecount_opt
#undef __out_ecount_opt
#undef __in_bcount
#undef __out_bcount
#undef __in_bcount_opt
#undef __out_bcount_opt
#undef __out_bcount_part
#undef __deref_out_ecount
#include <vector>
#include <string>
#include <unordered_map>