@@ -1258,6 +1258,24 @@ namespace Microsoft {
12581258
12591259 class WeakRef ;
12601260
1261+ namespace Details {
1262+ template <typename T>
1263+ class ComPtrRef {
1264+ public:
1265+ using InterfaceType = T;
1266+
1267+ ComPtrRef (T*);
1268+
1269+ InterfaceType* const * GetAddressOf () const ;
1270+ InterfaceType** ReleaseAndGetAddressOf ();
1271+
1272+ operator InterfaceType**();
1273+ operator T*();
1274+ operator void **() const ;
1275+ InterfaceType* operator *();
1276+ };
1277+ }
1278+
12611279 template <typename T>
12621280 class ComPtr
12631281 {
@@ -1301,7 +1319,22 @@ namespace Microsoft {
13011319 void Swap (ComPtr &&r);
13021320
13031321 void Swap (ComPtr &r);
1304- };
1322+
1323+ Details::ComPtrRef<ComPtr<T>> operator &();
1324+ const Details::ComPtrRef<const ComPtr<T>> operator &() const ;
1325+
1326+ InterfaceType* operator ->() const ; // return type simplified from Microsoft::WRL::Details::RemoveIUnknown<InterfaceType>*
1327+
1328+ ComPtr& operator =(T *);
1329+ template <typename U>
1330+ ComPtr& operator =(U *);
1331+ ComPtr& operator =(const ComPtr &);
1332+ template <class U >
1333+ ComPtr& operator =(const ComPtr<U>&);
1334+ ComPtr& operator =(ComPtr &&);
1335+ template <class U >
1336+ ComPtr& operator =(ComPtr<U>&&);
1337+ };
13051338
13061339 }
13071340}
@@ -1331,9 +1364,9 @@ void test_As()
13311364{
13321365 int x = source<int >();
13331366 Microsoft::WRL::ComPtr<int > p1 (new int (x));
1334- Microsoft::WRL::ComPtr<int > p2;
1335- p1.As (& p2);
1336- sink (*p2. Get ()); // $ ir MISSING: ast
1367+ Microsoft::WRL::ComPtr<int >* p2;
1368+ p1.As (p2);
1369+ sink (*p2-> Get ()); // $ ir MISSING: ast
13371370}
13381371
13391372void test_CopyTo ()
@@ -1377,4 +1410,52 @@ void test_GetAddressOf()
13771410 Microsoft::WRL::ComPtr<int > p3 (new int (x));
13781411 int **pp = p3.ReleaseAndGetAddressOf ();
13791412 sink (**pp); // $ ir MISSING: ast
1413+ }
1414+
1415+ struct S {
1416+ int x;
1417+ };
1418+
1419+ void test_address_of_deref_operators () {
1420+ int x = source<int >();
1421+ Microsoft::WRL::ComPtr<int > p1 (new int (x));
1422+ Microsoft::WRL::Details::ComPtrRef<Microsoft::WRL::ComPtr<int >> pp = &p1;
1423+ Microsoft::WRL::ComPtr<int >* qq = *pp;
1424+ sink (*qq->Get ()); // $ MISSING: ast,ir
1425+
1426+ const Microsoft::WRL::ComPtr<int > p2 (new int (x));
1427+ Microsoft::WRL::Details::ComPtrRef<const Microsoft::WRL::ComPtr<int >> pp2 = &p2;
1428+ const Microsoft::WRL::ComPtr<int >* qq2 = *pp2;
1429+ sink (*qq2->Get ()); // $ MISSING: ast,ir
1430+
1431+ S s;
1432+ s.x = source<int >();
1433+ Microsoft::WRL::ComPtr<S> p3 (&s);
1434+ sink (p3->x ); // $ MISSING: ast,ir
1435+ }
1436+
1437+ void test_assignments () {
1438+ Microsoft::WRL::ComPtr<int > p1;
1439+ p1 = new int (source<int >());
1440+ sink (*p1.Get ()); // $ MISSING: ast,ir
1441+
1442+ Microsoft::WRL::ComPtr<int > p2;
1443+ p2 = new long (source<long >());
1444+ sink (*p2.Get ()); // $ MISSING: ast,ir
1445+
1446+ Microsoft::WRL::ComPtr<int > p3;
1447+ p3 = p1;
1448+ sink (*p3.Get ()); // $ MISSING: ast,ir
1449+
1450+ Microsoft::WRL::ComPtr<long > p4;
1451+ p4 = p1;
1452+ sink (*p4.Get ()); // $ MISSING: ast,ir
1453+
1454+ Microsoft::WRL::ComPtr<int > p5;
1455+ p5 = std::move (p1);
1456+ sink (*p5.Get ()); // $ MISSING: ast,ir
1457+
1458+ Microsoft::WRL::ComPtr<long > p6;
1459+ p6 = std::move (p1);
1460+ sink (*p6.Get ()); // $ MISSING: ast,ir
13801461}
0 commit comments