Allow ResultOrError to downcast from backend to frontend types

More concretely this makes Result<T*, E*> able to be move-constructed
from Result<ChildClassOfT*, E*> for free.

BUG=dawn:19

Change-Id: Iea2b8997079ac3bfcf270d6b73a79cf5cac2c06f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/11860
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Corentin Wallez
2019-10-08 07:36:03 +00:00
committed by Commit Bot service account
parent 5f53d5302f
commit bd481fc199
2 changed files with 40 additions and 4 deletions

View File

@@ -139,6 +139,31 @@ TEST(ResultBothPointer, ReturningSuccess) {
TestSuccess(&result, &dummySuccess);
}
// Tests converting from a Result<TChild*, E*>
TEST(ResultBothPointer, ConversionFromChildClass) {
struct T {
int a;
};
struct TChild : T {};
TChild child;
T* childAsT = &child;
{
Result<T*, int*> result(&child);
TestSuccess(&result, childAsT);
}
{
Result<TChild*, int*> resultChild(&child);
Result<T*, int*> result(std::move(resultChild));
TestSuccess(&result, childAsT);
}
{
Result<TChild*, int*> resultChild(&child);
Result<T*, int*> result = std::move(resultChild);
TestSuccess(&result, childAsT);
}
}
// Result<const T*, E*>
// Test constructing an error Result<const T*, E*>