Skip to content

Commit fa079fb

Browse files
authored
Address variable name collisions in generated consume methods (#1455)
Why is this change being made? Someone discovered a subtle compatibility issue with the cast result checking changes and certain projected methods. The variables in the consume_ method, such as the generically-named code variable, can shadow the parameters to the function. This led to a build break where a function took an int16_t named code and that was shadowed by the int32_t named code with the HRESULT in it. Fortunately the compiler had our back and flagged the size truncation as a build break so it was noticed. Briefly summarize what changed The variable names in these generated functions are now much uglier (and therefore less likely to collide by coincidence). They have an underscore prefix and then lowercase which should put them into an unofficial namespace that shouldn't collide with anything else. The code variable is now named _winrt_cast_result_code for example. While I was renaming everything I realized that my previous names mismatched the cppwinrt naming convention of snake_case so I fixed them up.
1 parent 2aed347 commit fa079fb

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

cppwinrt/code_writers.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,15 +1137,15 @@ namespace cppwinrt
11371137
{%
11381138
if constexpr (!std::is_same_v<D, %>)
11391139
{
1140-
auto const [castedResult, code] = impl::try_as_with_reason<%, D const*>(static_cast<D const*>(this));
1141-
check_hresult(code);
1142-
auto const abiType = *(abi_t<%>**)&castedResult;
1143-
abiType->%(%);
1140+
auto const [_winrt_casted_result, _winrt_cast_result_code] = impl::try_as_with_reason<%, D const*>(static_cast<D const*>(this));
1141+
check_hresult(_winrt_cast_result_code);
1142+
auto const _winrt_abi_type = *(abi_t<%>**)&_winrt_casted_result;
1143+
_winrt_abi_type->%(%);
11441144
}
11451145
else
11461146
{
1147-
auto const abiType = *(abi_t<%>**)this;
1148-
abiType->%(%);
1147+
auto const _winrt_abi_type = *(abi_t<%>**)this;
1148+
_winrt_abi_type->%(%);
11491149
}%
11501150
}
11511151
)";
@@ -1156,15 +1156,15 @@ namespace cppwinrt
11561156
{%
11571157
if constexpr (!std::is_same_v<D, %>)
11581158
{
1159-
auto const [castedResult, code] = impl::try_as_with_reason<%, D const*>(static_cast<D const*>(this));
1160-
check_hresult(code);
1161-
auto const abiType = *(abi_t<%>**)&castedResult;
1162-
WINRT_VERIFY_(0, abiType->%(%));
1159+
auto const [_winrt_casted_result, _winrt_cast_result_code] = impl::try_as_with_reason<%, D const*>(static_cast<D const*>(this));
1160+
check_hresult(_winrt_cast_result_code);
1161+
auto const _winrt_abi_type = *(abi_t<%>**)&_winrt_casted_result;
1162+
WINRT_VERIFY_(0, _winrt_abi_type->%(%));
11631163
}
11641164
else
11651165
{
1166-
auto const abiType = *(abi_t<%>**)this;
1167-
WINRT_VERIFY_(0, abiType->%(%));
1166+
auto const _winrt_abi_type = *(abi_t<%>**)this;
1167+
WINRT_VERIFY_(0, _winrt_abi_type->%(%));
11681168
}%
11691169
}
11701170
)";
@@ -1176,15 +1176,15 @@ namespace cppwinrt
11761176
{%
11771177
if constexpr (!std::is_same_v<D, %>)
11781178
{
1179-
auto const [castedResult, code] = impl::try_as_with_reason<%, D const*>(static_cast<D const*>(this));
1180-
check_hresult(code);
1181-
auto const abiType = *(abi_t<%>**)&castedResult;
1182-
check_hresult(abiType->%(%));
1179+
auto const [_winrt_casted_result, _winrt_cast_result_code] = impl::try_as_with_reason<%, D const*>(static_cast<D const*>(this));
1180+
check_hresult(_winrt_cast_result_code);
1181+
auto const _winrt_abi_type = *(abi_t<%>**)&_winrt_casted_result;
1182+
check_hresult(_winrt_abi_type->%(%));
11831183
}
11841184
else
11851185
{
1186-
auto const abiType = *(abi_t<%>**)this;
1187-
check_hresult(abiType->%(%));
1186+
auto const _winrt_abi_type = *(abi_t<%>**)this;
1187+
check_hresult(_winrt_abi_type->%(%));
11881188
}%
11891189
}
11901190
)";

0 commit comments

Comments
 (0)