Make smart pointers great again [#118594399] [#118323445]#22
Make smart pointers great again [#118594399] [#118323445]#22
Conversation
|
Hello d! Thanks for submitting this pull request! All pull request authors must have a Contributor License Agreement (CLA) on-file with us. Please sign the appropriate CLA (individual or corporate). When sending signed CLA please provide your github username in case of individual CLA or the list of github usernames that can make pull requests on behalf of your organization. If you are confident that you're covered under a Corporate CLA, please make sure you've publicized your membership in the appropriate Github Org, per these instructions. |
|
duh i'm gonna fix this by being openly pivotal i guess |
| #ifndef GPOS_CAutoP_H | ||
| #define GPOS_CAutoP_H | ||
|
|
||
| #include <type_traits> |
|
Hello d! Thanks for submitting this pull request! All pull request authors must have a Contributor License Agreement (CLA) on-file with us. Please sign the appropriate CLA (individual or corporate). When sending signed CLA please provide your github username in case of individual CLA or the list of github usernames that can make pull requests on behalf of your organization. If you are confident that you're covered under a Corporate CLA, please make sure you've publicized your membership in the appropriate Github Org, per these instructions. |
|
Hello d! Thanks for submitting this pull request! I'm here to inform the recipients of the pull request that you've already signed the CLA. |
Both snippets should fail at compile-time:
```
GPOS_RESULT AutoPShouldBlowUpGivenRefCount()
{
// create memory pool
CAutoMemoryPool amp;
IMemoryPool *pmp = amp.Pmp();
CAutoP<CRefCount> aprf(GPOS_NEW(pmp) CRefCount());
return GPOS_OK;
}
```
```
static GPOS_RESULT AutoRefShouldBlowUpGivenNonRefCount()
{
// create memory pool
CAutoMemoryPool amp;
IMemoryPool *pmp = amp.Pmp();
CAutoRef<int> aprf(GPOS_NEW(pmp) int());
return GPOS_OK;
}
```
This patch makes
gpos::CAutoPandgpos::CAutoRefa bit friendlier to developers: when used with wrong template parameter, they blow up at compile time.Correct usage should always use
CAutoPwith NonCRefCountobject, andCAutoRefwithCRefCountobject (which hasRelease()method).We also removed the VERY DANGEROUS
reinterpret_castinCAutoRef::~CAutoRef(), which would corrupt the object.@d and @xinzweb