MicrosoftDocs / winrt-api

WinRT reference content for developing Microsoft Universal Windows Platform (UWP) apps
Creative Commons Attribution 4.0 International
231 stars 499 forks source link

Static method `TryParse` of classes `JsonArray`, `JsonObject`, and `JsonValue` has incorrect signature. #2336

Open leejy12 opened 1 year ago

leejy12 commented 1 year ago

In each function, result should be a non-const lvalue reference, not const& &;

From:

static bool TryParse(winrt::hstring const& input, [Out] JsonArray const& & result);
static bool TryParse(winrt::hstring const& input, [Out] JsonObject const& & result);
static bool TryParse(winrt::hstring const& input, [Out] JsonValue const& & result);

To:

static bool TryParse(winrt::hstring const& input, [Out] JsonArray& result);
static bool TryParse(winrt::hstring const& input, [Out] JsonObject& result);
static bool TryParse(winrt::hstring const& input, [Out] JsonValue& result);

Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

QuinnRadich commented 1 year ago

The method signatures in our API docs are generated from data in the Windows SDK, not authored manually by us. If you're certain that this a problem between what's displayed for C++/WinRT and how the functions actually operate, I can investigate the back-end causes of this further? But the nature of our publication process means that these details should, in theory, be accurate.

Thanks for bringing this to my attention.

leejy12 commented 1 year ago

I'm certain the API is documented incorrectly. I'm not sure which data from the Windows SDK is used to generate the docs but here are the functions in the header file C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\cppwinrt\winrt\windows.data.json.h and they correctly use & not const &&.

inline auto JsonArray::TryParse(param::hstring const& input, winrt::Windows::Data::Json::JsonArray& result)
{
    return impl::call_factory<JsonArray, IJsonArrayStatics>([&](IJsonArrayStatics const& f) { return f.TryParse(input, result); });
}
inline auto JsonObject::TryParse(param::hstring const& input, winrt::Windows::Data::Json::JsonObject& result)
{
    return impl::call_factory<JsonObject, IJsonObjectStatics>([&](IJsonObjectStatics const& f) { return f.TryParse(input, result); });
}
inline auto JsonValue::TryParse(param::hstring const& input, winrt::Windows::Data::Json::JsonValue& result)
{
    return impl::call_factory<JsonValue, IJsonValueStatics>([&](IJsonValueStatics const& f) { return f.TryParse(input, result); });
}

Thank you for looking into this!