Commit b5b87d38 authored by Patrick Monette's avatar Patrick Monette Committed by Commit Bot

ScopedVariant: Remove ambiguity when creating with a "long" value.

This fixes the compilation when building with "-fno-ms-extensions"

Since the underlying storage in VARIANT is a "long", it makes sense
to make the main constructor of ScopedVariant take an integer of this
type.

But even after this change, since there still many callsites using a
"int" variable, that version is still needed to avoid the ambiguity
between the "double" and "long" constructors.

Finally, I've added an explicit version for VT_BOOL, because the
above changes were causing additional compilation errors.

Bug: 1061948
Change-Id: Ib6b22b2c01976dc4e6cbcf641e8a4ed3986c84a7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2110452
Auto-Submit: Patrick Monette <pmonette@chromium.org>
Reviewed-by: default avatarKevin Babbitt <kbabbitt@microsoft.com>
Reviewed-by: default avatarRobert Liao <robliao@chromium.org>
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Cr-Commit-Position: refs/heads/master@{#753246}
parent 1136c260
...@@ -32,12 +32,19 @@ ScopedVariant::ScopedVariant(const wchar_t* str, UINT length) { ...@@ -32,12 +32,19 @@ ScopedVariant::ScopedVariant(const wchar_t* str, UINT length) {
var_.bstrVal = ::SysAllocStringLen(str, length); var_.bstrVal = ::SysAllocStringLen(str, length);
} }
ScopedVariant::ScopedVariant(int value, VARTYPE vt) { ScopedVariant::ScopedVariant(long value, VARTYPE vt) {
var_.vt = vt; var_.vt = vt;
if (vt == VT_BOOL) var_.lVal = value;
var_.boolVal = value ? VARIANT_TRUE : VARIANT_FALSE; }
else
var_.lVal = value; ScopedVariant::ScopedVariant(int value) {
var_.vt = VT_I4;
var_.lVal = value;
}
ScopedVariant::ScopedVariant(bool value) {
var_.vt = VT_BOOL;
var_.boolVal = value ? VARIANT_TRUE : VARIANT_FALSE;
} }
ScopedVariant::ScopedVariant(double value, VARTYPE vt) { ScopedVariant::ScopedVariant(double value, VARTYPE vt) {
......
...@@ -43,8 +43,15 @@ class BASE_EXPORT ScopedVariant { ...@@ -43,8 +43,15 @@ class BASE_EXPORT ScopedVariant {
// Creates a new integral type variant and assigns the value to // Creates a new integral type variant and assigns the value to
// VARIANT.lVal (32 bit sized field). // VARIANT.lVal (32 bit sized field).
// NOTE: VT_BOOL constructs here as VARIANT.boolVal. explicit ScopedVariant(long value, VARTYPE vt = VT_I4);
explicit ScopedVariant(int value, VARTYPE vt = VT_I4);
// Creates a new integral type variant for the int type and assigns the value
// to VARIANT.lVal (32 bit sized field).
explicit ScopedVariant(int value);
// Creates a new boolean (VT_BOOL) variant and assigns the value to
// VARIANT.boolVal.
explicit ScopedVariant(bool value);
// Creates a new double-precision type variant. |vt| must be either VT_R8 // Creates a new double-precision type variant. |vt| must be either VT_R8
// or VT_DATE. // or VT_DATE.
......
...@@ -100,7 +100,7 @@ ScopedVariant SELF(CHILDID_SELF); ...@@ -100,7 +100,7 @@ ScopedVariant SELF(CHILDID_SELF);
#define EXPECT_UIA_BOOL_EQ(node, property_id, expected) \ #define EXPECT_UIA_BOOL_EQ(node, property_id, expected) \
{ \ { \
ScopedVariant expectedVariant(expected, VT_BOOL); \ ScopedVariant expectedVariant(expected); \
ASSERT_EQ(VT_BOOL, expectedVariant.type()); \ ASSERT_EQ(VT_BOOL, expectedVariant.type()); \
ScopedVariant actual; \ ScopedVariant actual; \
ASSERT_HRESULT_SUCCEEDED( \ ASSERT_HRESULT_SUCCEEDED( \
...@@ -135,7 +135,7 @@ ScopedVariant SELF(CHILDID_SELF); ...@@ -135,7 +135,7 @@ ScopedVariant SELF(CHILDID_SELF);
#define EXPECT_UIA_INT_EQ(node, property_id, expected) \ #define EXPECT_UIA_INT_EQ(node, property_id, expected) \
{ \ { \
ScopedVariant expectedVariant(expected, VT_I4); \ ScopedVariant expectedVariant(expected); \
ASSERT_EQ(VT_I4, expectedVariant.type()); \ ASSERT_EQ(VT_I4, expectedVariant.type()); \
ScopedVariant actual; \ ScopedVariant actual; \
ASSERT_HRESULT_SUCCEEDED( \ ASSERT_HRESULT_SUCCEEDED( \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment