Implemented C++23 deleted nullptr_t constructor/assignment for AZStd string classes (#4158)

* Added string and string_view class constructor overloads which is deleted that prevents initializing them from a nullptr or an integer type

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Fixed locations where string and string_view were initialized with
nullptr

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Fix IArchive::IsInstalledToHDD signature

Updated calls to ConvertAbsolutePathToAliasedPath to use an
list initialization instead of nullptr

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
This commit is contained in:
lumberyard-employee-dm
2021-09-16 12:50:18 -05:00
committed by GitHub
parent f1f35a0ba8
commit 58c227ceb1
18 changed files with 44 additions and 46 deletions
+1 -1
View File
@@ -70,7 +70,7 @@ protected:
m_splineEntries.resize(m_splineEntries.size() + 1);
SplineEntry& entry = m_splineEntries.back();
ISplineSet* pSplineSet = (pCtrl ? pCtrl->m_pSplineSet : nullptr);
entry.id = (pSplineSet ? pSplineSet->GetIDFromSpline(pSpline) : nullptr);
entry.id = (pSplineSet ? pSplineSet->GetIDFromSpline(pSpline) : AZStd::string{});
entry.pSpline = pSpline;
const int numKeys = pSpline->GetKeyCount();
+2 -2
View File
@@ -68,7 +68,7 @@ bool CPakFile::Open(const char* filename, bool bAbsolutePath)
if (bAbsolutePath)
{
m_pArchive = pCryPak->OpenArchive(filename, nullptr, AZ::IO::INestedArchive::FLAGS_ABSOLUTE_PATHS);
m_pArchive = pCryPak->OpenArchive(filename, {}, AZ::IO::INestedArchive::FLAGS_ABSOLUTE_PATHS);
}
else
{
@@ -93,7 +93,7 @@ bool CPakFile::OpenForRead(const char* filename)
{
return false;
}
m_pArchive = pCryPak->OpenArchive(filename, nullptr, AZ::IO::INestedArchive::FLAGS_OPTIMIZED_READ_ONLY | AZ::IO::INestedArchive::FLAGS_ABSOLUTE_PATHS);
m_pArchive = pCryPak->OpenArchive(filename, {}, AZ::IO::INestedArchive::FLAGS_OPTIMIZED_READ_ONLY | AZ::IO::INestedArchive::FLAGS_ABSOLUTE_PATHS);
if (m_pArchive)
{
return true;
@@ -96,6 +96,10 @@ namespace AZStd
&& !is_convertible_v<const T&, const Element*>>>
constexpr basic_fixed_string(const T& convertibleToView, size_type rhsOffset, size_type count);
// #12
constexpr basic_fixed_string(AZStd::nullptr_t) = delete;
constexpr operator AZStd::basic_string_view<Element, Traits>() const;
constexpr auto begin() -> iterator;
@@ -120,6 +124,7 @@ namespace AZStd
constexpr auto operator=(const T& convertible_to_view)
-> AZStd::enable_if_t<is_convertible_v<const T&, basic_string_view<Element, Traits>>
&& !is_convertible_v<const T&, const Element*>, basic_fixed_string&>;
constexpr auto operator=(AZStd::nullptr_t) -> basic_fixed_string& = delete;
constexpr auto operator+=(const basic_fixed_string& rhs) -> basic_fixed_string&;
constexpr auto operator+=(const_pointer ptr) -> basic_fixed_string&;
@@ -168,6 +168,9 @@ namespace AZStd
{
}
// C++23 overload to prevent initializing a string_view via a nullptr or integer type
constexpr basic_string(AZStd::nullptr_t) = delete;
inline ~basic_string()
{
// destroy the string
@@ -197,6 +200,7 @@ namespace AZStd
inline this_type& operator=(AZStd::basic_string_view<Element, Traits> view) { return assign(view); }
inline this_type& operator=(const_pointer ptr) { return assign(ptr); }
inline this_type& operator=(Element ch) { return assign(1, ch); }
inline this_type& operator=(AZStd::nullptr_t) = delete;
inline this_type& operator+=(const this_type& rhs) { return append(rhs); }
inline this_type& operator+=(const_pointer ptr) { return append(ptr); }
inline this_type& operator+=(Element ch) { return append(1, ch); }
@@ -502,6 +502,9 @@ namespace AZStd
swap(other);
}
// C++23 overload to prevent initializing a string_view via a nullptr or integer type
constexpr basic_string_view(AZStd::nullptr_t) = delete;
constexpr const_reference operator[](size_type index) const { return data()[index]; }
/// Returns value, not reference. If index is out of bounds, 0 is returned (can't be reference).
constexpr value_type at(size_type index) const
+1 -15
View File
@@ -1210,9 +1210,6 @@ namespace UnitTest
AZStd::string findStr("Hay");
string_view view3(findStr);
string_view nullptrView4(nullptr);
EXPECT_EQ(emptyView1, nullptrView4);
// copy
const size_t destBufferSize = 32;
@@ -1264,9 +1261,6 @@ namespace UnitTest
AZStd::size_t rfindResult = view3.rfind('a', 2);
EXPECT_EQ(1, rfindResult);
rfindResult = nullptrView4.rfind("");
EXPECT_EQ(string_view::npos, rfindResult);
rfindResult = emptyView1.rfind("");
EXPECT_EQ(string_view::npos, rfindResult);
@@ -1373,17 +1367,11 @@ namespace UnitTest
{
string_view view1("The quick brown fox jumped over the lazy dog");
string_view view2("Needle in Haystack");
string_view nullBeaverView(nullptr);
string_view emptyBeaverView;
string_view superEmptyBeaverView("");
EXPECT_EQ(nullBeaverView, emptyBeaverView);
EXPECT_EQ(superEmptyBeaverView, nullBeaverView);
EXPECT_EQ(emptyBeaverView, superEmptyBeaverView);
EXPECT_EQ(nullBeaverView, "");
EXPECT_EQ(nullBeaverView, nullptr);
EXPECT_EQ("", emptyBeaverView);
EXPECT_EQ(nullptr, superEmptyBeaverView);
EXPECT_EQ("", superEmptyBeaverView);
EXPECT_EQ("The quick brown fox jumped over the lazy dog", view1);
EXPECT_NE("The slow brown fox jumped over the lazy dog", view1);
@@ -1421,8 +1409,6 @@ namespace UnitTest
EXPECT_LE(beaverView, "Busy Beaver");
EXPECT_LE("Likable Beaver", notBeaverView);
EXPECT_LE("Busy Beaver", beaverView);
EXPECT_LE(nullBeaverView, nullBeaverView);
EXPECT_LE(nullBeaverView, lowerBeaverStr);
EXPECT_LE(microBeaverStr, view1);
EXPECT_LE(compareStr, beaverView);
@@ -362,7 +362,7 @@ namespace UnitTest
// Test specific construction case that was failing.
// The constructor calls Name::SetName() which does a move assignment
// Name& Name::operator=(Name&& rhs) was leaving m_view pointing to the m_data in a temporary Name object.
AZ::Name emptyName(AZStd::string_view(nullptr));
AZ::Name emptyName(AZStd::string_view{});
EXPECT_TRUE(emptyName.IsEmpty());
EXPECT_EQ(0, emptyName.GetStringView().data()[0]);
}
@@ -1517,7 +1517,7 @@ namespace SettingsRegistryTests
m_testFolder->push_back(AZ_CORRECT_DATABASE_SEPARATOR);
*m_testFolder += AZ::SettingsRegistryInterface::RegistryFolder;
bool result = m_registry->MergeSettingsFolder(*m_testFolder, { "editor", "test" }, {}, nullptr);
bool result = m_registry->MergeSettingsFolder(*m_testFolder, { "editor", "test" }, {});
EXPECT_TRUE(result);
EXPECT_EQ(4, counter);
@@ -1559,7 +1559,7 @@ namespace SettingsRegistryTests
m_testFolder->push_back(AZ_CORRECT_DATABASE_SEPARATOR);
*m_testFolder += AZ::SettingsRegistryInterface::RegistryFolder;
bool result = m_registry->MergeSettingsFolder(*m_testFolder, { "editor", "test" }, "Special", nullptr);
bool result = m_registry->MergeSettingsFolder(*m_testFolder, { "editor", "test" }, "Special");
EXPECT_TRUE(result);
EXPECT_EQ(6, counter);
@@ -1598,7 +1598,7 @@ namespace SettingsRegistryTests
m_testFolder->push_back(AZ_CORRECT_DATABASE_SEPARATOR);
*m_testFolder += AZ::SettingsRegistryInterface::RegistryFolder;
bool result = m_registry->MergeSettingsFolder(*m_testFolder, { "editor", "test" }, {}, nullptr);
bool result = m_registry->MergeSettingsFolder(*m_testFolder, { "editor", "test" }, {});
EXPECT_TRUE(result);
EXPECT_EQ(4, counter);
@@ -1639,7 +1639,7 @@ namespace SettingsRegistryTests
m_testFolder->push_back(AZ_CORRECT_DATABASE_SEPARATOR);
*m_testFolder += AZ::SettingsRegistryInterface::RegistryFolder;
bool result = m_registry->MergeSettingsFolder(*m_testFolder, { "editor", "test" }, {}, nullptr);
bool result = m_registry->MergeSettingsFolder(*m_testFolder, { "editor", "test" }, {});
EXPECT_TRUE(result);
EXPECT_EQ(4, counter);
@@ -1672,7 +1672,7 @@ namespace SettingsRegistryTests
m_testFolder->push_back(AZ_CORRECT_DATABASE_SEPARATOR);
*m_testFolder += AZ::SettingsRegistryInterface::RegistryFolder;
bool result = m_registry->MergeSettingsFolder(*m_testFolder, { "editor", "test" }, "Special", nullptr);
bool result = m_registry->MergeSettingsFolder(*m_testFolder, { "editor", "test" }, "Special");
EXPECT_TRUE(result);
EXPECT_EQ(1, counter);
@@ -1722,7 +1722,7 @@ namespace SettingsRegistryTests
TEST_F(SettingsRegistryTest, MergeSettingsFolder_EmptyFolder_ReportsSuccessButNothingAdded)
{
bool result = m_registry->MergeSettingsFolder(*m_testFolder, { "editor", "test" }, {}, nullptr);
bool result = m_registry->MergeSettingsFolder(*m_testFolder, { "editor", "test" }, {});
EXPECT_TRUE(result);
EXPECT_EQ(AZ::SettingsRegistryInterface::Type::Object, m_registry->GetType(AZ_SETTINGS_REGISTRY_HISTORY_KEY "/0")); // Folder and specialization settings.
@@ -1734,7 +1734,7 @@ namespace SettingsRegistryTests
constexpr AZStd::fixed_string<AZ::IO::MaxPathLength + 1> path(AZ::IO::MaxPathLength + 1, 'a');
AZ_TEST_START_TRACE_SUPPRESSION;
bool result = m_registry->MergeSettingsFolder(path, { "editor", "test" }, {}, nullptr);
bool result = m_registry->MergeSettingsFolder(path, { "editor", "test" }, {});
AZ_TEST_STOP_TRACE_SUPPRESSION(1);
EXPECT_FALSE(result);
@@ -1751,7 +1751,7 @@ namespace SettingsRegistryTests
AZ_TEST_START_TRACE_SUPPRESSION;
m_testFolder->push_back(AZ_CORRECT_DATABASE_SEPARATOR);
*m_testFolder += AZ::SettingsRegistryInterface::RegistryFolder;
bool result = m_registry->MergeSettingsFolder(*m_testFolder, { "editor", "test" }, {}, nullptr);
bool result = m_registry->MergeSettingsFolder(*m_testFolder, { "editor", "test" }, {});
EXPECT_GT(::UnitTest::TestRunner::Instance().StopAssertTests(), 0);
EXPECT_FALSE(result);
@@ -94,7 +94,7 @@ namespace UnitTest
fileIo->Remove(testArchivePath.c_str());
// ------------ BASIC TEST: Create and read Empty Archive ------------
AZStd::intrusive_ptr<AZ::IO::INestedArchive> pArchive = archive->OpenArchive(testArchivePath.c_str(), nullptr, AZ::IO::INestedArchive::FLAGS_CREATE_NEW);
AZStd::intrusive_ptr<AZ::IO::INestedArchive> pArchive = archive->OpenArchive(testArchivePath.c_str(), {}, AZ::IO::INestedArchive::FLAGS_CREATE_NEW);
EXPECT_NE(nullptr, pArchive);
pArchive.reset();
EXPECT_TRUE(IsPackValid(testArchivePath.c_str()));
@@ -122,7 +122,7 @@ namespace UnitTest
checkSums[pos] = static_cast<uint8_t>(pos % 256);
}
auto pArchive = archive->OpenArchive(testArchivePath.c_str(), nullptr, AZ::IO::INestedArchive::FLAGS_CREATE_NEW);
auto pArchive = archive->OpenArchive(testArchivePath.c_str(), {}, AZ::IO::INestedArchive::FLAGS_CREATE_NEW);
EXPECT_NE(nullptr, pArchive);
// the strategy here is to find errors related to file sizes, alignment, overwrites
@@ -143,7 +143,7 @@ namespace UnitTest
// --------------------------------------------- read it back and verify
pArchive = archive->OpenArchive(testArchivePath.c_str(), nullptr, openFlags);
pArchive = archive->OpenArchive(testArchivePath.c_str(), {}, openFlags);
EXPECT_NE(nullptr, pArchive);
for (int j = 0; j < iterations; ++j)
@@ -241,7 +241,7 @@ namespace UnitTest
// -------------------------------------------------------------------------------------------
// read it back and verify
pArchive = archive->OpenArchive(testArchivePath.c_str(), nullptr, openFlags);
pArchive = archive->OpenArchive(testArchivePath.c_str(), {}, openFlags);
EXPECT_NE(nullptr, pArchive);
for (int j = 0; j < iterations; ++j)
@@ -298,7 +298,7 @@ namespace UnitTest
}
// first, reset the pack to the original state:
auto pArchive = archive->OpenArchive(testArchivePath.c_str(), nullptr, AZ::IO::INestedArchive::FLAGS_CREATE_NEW);
auto pArchive = archive->OpenArchive(testArchivePath.c_str(), {}, AZ::IO::INestedArchive::FLAGS_CREATE_NEW);
EXPECT_NE(nullptr, pArchive);
for (int j = 0; j < iterations; ++j)
@@ -382,7 +382,7 @@ namespace UnitTest
// -------------------------------------------------------------------------------------------
// read it back and verify
pArchive = archive->OpenArchive(testArchivePath.c_str(), nullptr, openFlags);
pArchive = archive->OpenArchive(testArchivePath.c_str(), {}, openFlags);
EXPECT_NE(nullptr, pArchive);
writeCount = 0;
@@ -256,7 +256,7 @@ namespace UnitTest
fileIo->CreatePath("@usercache@/levels/test");
// setup test archive and file
AZStd::intrusive_ptr<AZ::IO::INestedArchive> pArchive = archive->OpenArchive(testArchivePath_withSubfolders.c_str(), nullptr, AZ::IO::INestedArchive::FLAGS_CREATE_NEW);
AZStd::intrusive_ptr<AZ::IO::INestedArchive> pArchive = archive->OpenArchive(testArchivePath_withSubfolders.c_str(), {}, AZ::IO::INestedArchive::FLAGS_CREATE_NEW);
EXPECT_NE(nullptr, pArchive);
EXPECT_EQ(0, pArchive->UpdateFile(fileInArchiveFile, dataString.data(), dataString.size(), AZ::IO::INestedArchive::METHOD_COMPRESS, AZ::IO::INestedArchive::LEVEL_FASTEST));
pArchive.reset();
@@ -291,7 +291,7 @@ namespace UnitTest
archive->ClosePack(filePath.c_str());
fileIo->Remove(filePath.c_str());
auto pArchive = archive->OpenArchive(filePath.c_str(), nullptr, AZ::IO::INestedArchive::FLAGS_CREATE_NEW);
auto pArchive = archive->OpenArchive(filePath.c_str(), {}, AZ::IO::INestedArchive::FLAGS_CREATE_NEW);
EXPECT_NE(nullptr, pArchive);
pArchive.reset();
archive->ClosePack(filePath.c_str());
@@ -478,7 +478,7 @@ namespace UnitTest
bool found_mylevel_file{};
bool found_mylevel_folder{};
AZStd::intrusive_ptr<AZ::IO::INestedArchive> pArchive = archive->OpenArchive(testArchivePath_withMountPoint, nullptr, AZ::IO::INestedArchive::FLAGS_CREATE_NEW);
AZStd::intrusive_ptr<AZ::IO::INestedArchive> pArchive = archive->OpenArchive(testArchivePath_withMountPoint, {}, AZ::IO::INestedArchive::FLAGS_CREATE_NEW);
EXPECT_NE(nullptr, pArchive);
EXPECT_EQ(0, pArchive->UpdateFile("levelinfo.xml", dataString.data(), dataString.size(), AZ::IO::INestedArchive::METHOD_COMPRESS, AZ::IO::INestedArchive::LEVEL_FASTEST));
pArchive.reset();
@@ -629,7 +629,7 @@ namespace UnitTest
normalFileHandle = InvalidHandle;
EXPECT_TRUE(cpfio.Exists("@log@/unittesttemp/realfileforunittest.xml"));
AZStd::intrusive_ptr<AZ::IO::INestedArchive> pArchive = archive->OpenArchive(genericArchiveFileName, nullptr, AZ::IO::INestedArchive::FLAGS_CREATE_NEW);
AZStd::intrusive_ptr<AZ::IO::INestedArchive> pArchive = archive->OpenArchive(genericArchiveFileName, {}, AZ::IO::INestedArchive::FLAGS_CREATE_NEW);
EXPECT_NE(nullptr, pArchive);
EXPECT_EQ(0, pArchive->UpdateFile("testfile.xml", dataString, aznumeric_cast<uint32_t>(dataLen), AZ::IO::INestedArchive::METHOD_COMPRESS, AZ::IO::INestedArchive::LEVEL_FASTEST));
pArchive.reset();
@@ -773,7 +773,7 @@ namespace UnitTest
fileIo->Remove(testArchivePath);
// ------------ BASIC TEST: Create and read Empty Archive ------------
AZStd::intrusive_ptr<AZ::IO::INestedArchive> pArchive = archive->OpenArchive(testArchivePath, nullptr, AZ::IO::INestedArchive::FLAGS_CREATE_NEW);
AZStd::intrusive_ptr<AZ::IO::INestedArchive> pArchive = archive->OpenArchive(testArchivePath, {}, AZ::IO::INestedArchive::FLAGS_CREATE_NEW);
EXPECT_NE(nullptr, pArchive);
EXPECT_EQ(0, pArchive->UpdateFile("foundit.dat", const_cast<char*>("test"), 4, AZ::IO::INestedArchive::METHOD_COMPRESS, AZ::IO::INestedArchive::LEVEL_BEST));
@@ -102,7 +102,7 @@ namespace AzToolsFramework
else
{
AZStd::string error = AZStd::string::format("Could not resolve path name for asset {%s}.", id.ToString<AZStd::string>().c_str());
assetCheckoutAndSaveCallback(false, error, nullptr);
assetCheckoutAndSaveCallback(false, error, AZStd::string{});
}
}
@@ -40,7 +40,7 @@ namespace MCore
CommandHistoryEntry()
: m_commandGroup(nullptr)
, m_executedCommand(nullptr)
, m_parameters(nullptr) {}
{}
/**
* Extended Constructor.
@@ -78,7 +78,7 @@ protected:
m_splineEntries.resize(m_splineEntries.size() + 1);
SplineEntry& entry = m_splineEntries.back();
ISplineSet* pSplineSet = (pCtrl ? pCtrl->m_pSplineSet : 0);
entry.id = (pSplineSet ? pSplineSet->GetIDFromSpline(pSpline) : 0);
entry.id = (pSplineSet ? pSplineSet->GetIDFromSpline(pSpline) : AZStd::string{});
entry.pSpline = pSpline;
const int numKeys = pSpline->GetKeyCount();
@@ -59,7 +59,7 @@ namespace SaveData
////////////////////////////////////////////////////////////////////////////////////////////
//! The absolute path to the application's save data dircetory.
AZStd::string m_saveDataDircetoryPathAbsolute = nullptr;
AZStd::string m_saveDataDircetoryPathAbsolute;
};
////////////////////////////////////////////////////////////////////////////////////////////////
@@ -60,7 +60,7 @@ namespace SaveData
////////////////////////////////////////////////////////////////////////////////////////////
//! The absolute path to the application's save data dircetory.
AZStd::string m_saveDataDircetoryPathAbsolute = nullptr;
AZStd::string m_saveDataDircetoryPathAbsolute;
};
////////////////////////////////////////////////////////////////////////////////////////////////
@@ -62,7 +62,7 @@ namespace SaveData
////////////////////////////////////////////////////////////////////////////////////////////
//! The absolute path to the application's save data dircetory.
AZStd::string m_saveDataDircetoryPathAbsolute = nullptr;
AZStd::string m_saveDataDircetoryPathAbsolute;
};
////////////////////////////////////////////////////////////////////////////////////////////////
@@ -1322,7 +1322,7 @@ namespace ScriptCanvasEditor
if (seperator == AZStd::string_view::npos)
{
categoryTrail = nullptr;
categoryTrail = {};
}
else
{
@@ -131,7 +131,7 @@ namespace ScriptCanvasDeveloper
QString m_nodeName;
AutomationStateModelId m_endpointId = nullptr;
AutomationStateModelId m_endpointId;
AutomationStateModelId m_scenePointId;
AutomationStateModelId m_nodeOutputId;