Skip to content

Commit 1868b88

Browse files
dharesignGitHub Enterprise
authored andcommitted
bslma::ManagedPtr: Fix Unit Test Pre-C++17 (#5600)
BSLS_COMPILERFEATURES_GUARANTEED_COPY_ELISION is defined for Clang and GCC builds prior to C++17 as the compilers do elide the copy, however they do perform the additional checks that makes the code fail to compile prior to C++17. With C++11 and move constructors, the conversion sequence does not attempt to go through `ManagedPtr(const ManagedPtr&)`, so it successfully builds even without the new copy-elision rules from C++17. Update the tests to be predicated on the availability of move constructors.
1 parent 1545cf5 commit 1868b88

1 file changed

Lines changed: 11 additions & 13 deletions

File tree

groups/bsl/bslma/bslma_managedptr.t.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,16 +1712,7 @@ consumeManagedPtr(bslma::ManagedPtr<MyTestObject>,
17121712
{
17131713
ASSERTV(checkValue, *numDels, checkValue == *numDels);
17141714
}
1715-
#endif //defined(BSLMF_MOVABLEREF_USES_RVALUE_REFERENCES)
1716-
1717-
template <typename MANAGEDPTR_TYPE>
1718-
static void
1719-
consumeManagedPtrCRNP(const MANAGEDPTR_TYPE&)
1720-
{
1721-
// Will be called with a null pointer constant to test implicit conversion.
1722-
}
17231715

1724-
#if defined(BSLS_COMPILERFEATURES_GUARANTEED_COPY_ELISION)
17251716
template <typename MANAGEDPTR_TYPE>
17261717
static void
17271718
consumeManagedPtrNP(MANAGEDPTR_TYPE)
@@ -1736,7 +1727,14 @@ returnManagedPtrNP()
17361727
// Ensure implicit conversion works on return values.
17371728
return 0;
17381729
}
1739-
#endif //defined(BSLS_COMPILERFEATURES_GUARANTEED_COPY_ELISION)
1730+
#endif //defined(BSLMF_MOVABLEREF_USES_RVALUE_REFERENCES)
1731+
1732+
template <typename MANAGEDPTR_TYPE>
1733+
static void
1734+
consumeManagedPtrCRNP(const MANAGEDPTR_TYPE&)
1735+
{
1736+
// Will be called with a null pointer constant to test implicit conversion.
1737+
}
17401738

17411739
static void
17421740
consumeManagedPtrCR(const bslma::ManagedPtr<MyTestObject>&,
@@ -13848,7 +13846,7 @@ int main(int argc, char *argv[])
1384813846

1384913847
consumeManagedPtrCRNP<Obj>(0);
1385013848

13851-
#if defined(BSLS_COMPILERFEATURES_GUARANTEED_COPY_ELISION)
13849+
#if defined(BSLMF_MOVABLEREF_USES_RVALUE_REFERENCES)
1385213850
consumeManagedPtrNP<Obj>(0);
1385313851
Obj o = returnManagedPtrNP<Obj>();
1385413852
ASSERT(0 == o.get());
@@ -13866,7 +13864,7 @@ int main(int argc, char *argv[])
1386613864

1386713865
consumeManagedPtrCRNP<VObj>(0);
1386813866

13869-
#if defined(BSLS_COMPILERFEATURES_GUARANTEED_COPY_ELISION)
13867+
#if defined(BSLMF_MOVABLEREF_USES_RVALUE_REFERENCES)
1387013868
consumeManagedPtrNP<VObj>(0);
1387113869
VObj o = returnManagedPtrNP<VObj>();
1387213870
ASSERT(0 == o.get());
@@ -13884,7 +13882,7 @@ int main(int argc, char *argv[])
1388413882

1388513883
consumeManagedPtrCRNP<bslma::ManagedPtr<const int> >(0);
1388613884

13887-
#if defined(BSLS_COMPILERFEATURES_GUARANTEED_COPY_ELISION)
13885+
#if defined(BSLMF_MOVABLEREF_USES_RVALUE_REFERENCES)
1388813886
consumeManagedPtrNP<bslma::ManagedPtr<const int> >(0);
1388913887
bslma::ManagedPtr<const int> o =
1389013888
returnManagedPtrNP<bslma::ManagedPtr<const int> >();

0 commit comments

Comments
 (0)