File tree Expand file tree Collapse file tree 3 files changed +28
-1
lines changed Expand file tree Collapse file tree 3 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -2407,13 +2407,20 @@ namespace {
2407
2407
}
2408
2408
}
2409
2409
2410
+ bool forceMemberwiseInitializer = false ;
2411
+ if (cxxRecordDecl && cxxRecordDecl->isInStdNamespace () &&
2412
+ cxxRecordDecl->getIdentifier () &&
2413
+ cxxRecordDecl->getName () == " pair" ) {
2414
+ forceMemberwiseInitializer = true ;
2415
+ }
2410
2416
// We can assume that it is possible to correctly construct the object by
2411
2417
// simply initializing its member variables to arbitrary supplied values
2412
2418
// only when the same is possible in C++. While we could check for that
2413
2419
// exactly, checking whether the C++ class is an aggregate
2414
2420
// (C++ [dcl.init.aggr]) has the same effect.
2415
2421
bool isAggregate = !cxxRecordDecl || cxxRecordDecl->isAggregate ();
2416
- if (hasReferenceableFields && hasMemberwiseInitializer && isAggregate) {
2422
+ if ((hasReferenceableFields && hasMemberwiseInitializer && isAggregate) ||
2423
+ forceMemberwiseInitializer) {
2417
2424
// The default zero initializer suppresses the implicit value
2418
2425
// constructor that would normally be formed, so we have to add that
2419
2426
// explicitly as well.
Original file line number Diff line number Diff line change 1
1
#pragma once
2
2
3
3
#include < utility>
4
+ #include < string>
4
5
5
6
using PairInts = std::pair<int , int >;
7
+ using PairStrings = std::pair<std::string, std::string>;
6
8
7
9
inline const PairInts &getIntPairPointer () {
8
10
static PairInts value = { 4 , 9 };
Original file line number Diff line number Diff line change @@ -9,6 +9,24 @@ import Cxx
9
9
10
10
var StdPairTestSuite = TestSuite ( " StdPair " )
11
11
12
+ StdPairTestSuite . test ( " StdPairInts.init " ) {
13
+ let pi = PairInts ( first: 1 , second: 2 )
14
+ expectEqual ( pi. first, 1 )
15
+ expectEqual ( pi. second, 2 )
16
+ }
17
+
18
+ #if !os(Windows) // FIXME: enable once swiftCxxStdlib is built on Windows (https://github.com/apple/swift/issues/67649)
19
+ StdPairTestSuite . test ( " StdPairStrings.init " ) {
20
+ let ps = PairStrings ( first: std. string ( ) , second: std. string ( ) )
21
+ expectEqual ( ps. first, std. string ( ) )
22
+ expectEqual ( ps. second, std. string ( ) )
23
+
24
+ let ps2 = PairStrings ( first: std. string ( " abc " ) , second: std. string ( " 123 " ) )
25
+ expectEqual ( ps2. first, std. string ( " abc " ) )
26
+ expectEqual ( ps2. second, std. string ( " 123 " ) )
27
+ }
28
+ #endif
29
+
12
30
StdPairTestSuite . test ( " StdPair.elements " ) {
13
31
var pi = getIntPair ( )
14
32
expectEqual ( pi. first, - 5 )
You can’t perform that action at this time.
0 commit comments