diff --git a/code/Core/Class/BoxedAllocator.h b/code/Core/Class/BoxedAllocator.h index fa8914d3a5..4d8dac6bdb 100644 --- a/code/Core/Class/BoxedAllocator.h +++ b/code/Core/Class/BoxedAllocator.h @@ -33,7 +33,7 @@ class BoxedAllocator Alloc::freeAlign(allocator.top()); } - BoxedType* alloc() + [[nodiscard]] BoxedType* alloc() { #if defined(T_BOXES_USE_MT_LOCK) T_ANONYMOUS_VAR(Acquire< SpinLock >)(m_lock); diff --git a/code/Core/Class/CoreClassFactory1.cpp b/code/Core/Class/CoreClassFactory1.cpp index d12d4fa6a1..f5456b386d 100644 --- a/code/Core/Class/CoreClassFactory1.cpp +++ b/code/Core/Class/CoreClassFactory1.cpp @@ -25,6 +25,7 @@ #include "Core/Io/Utf8Encoding.h" #include "Core/Io/Utf16Encoding.h" #include "Core/Io/Utf32Encoding.h" +#include "Core/Log/Log.h" #include "Core/Serialization/DeepClone.h" #include "Core/Serialization/DeepHash.h" #include "Core/Settings/PropertyArray.h" @@ -85,7 +86,8 @@ int64_t IStream_seek(IStream* self, int64_t origin, int64_t offset) void FileSystem_setCurrentVolumeAndDirectory(FileSystem* self, const Path& directory) { - self->setCurrentVolumeAndDirectory(directory); + if (!self->setCurrentVolumeAndDirectory(directory)) + log::warning << L"Unable to set current volume and directory \"" << directory.getPathName() << L"\"." << Endl; } Path FileSystem_getCurrentVolumeAndDirectory(FileSystem* self) diff --git a/code/Core/Io/FileSystem.h b/code/Core/Io/FileSystem.h index eadd17465d..e05c73b1d4 100644 --- a/code/Core/Io/FileSystem.h +++ b/code/Core/Io/FileSystem.h @@ -98,7 +98,7 @@ class T_DLLCLASS FileSystem * \param directory New current directory. * \return True if successfully changed. */ - bool setCurrentVolumeAndDirectory(const Path& directory); + [[nodiscard]] bool setCurrentVolumeAndDirectory(const Path& directory); /*! Get current volume and directory. */ diff --git a/code/Core/Memory/Alloc.h b/code/Core/Memory/Alloc.h index c6533de796..f934fb2325 100644 --- a/code/Core/Memory/Alloc.h +++ b/code/Core/Memory/Alloc.h @@ -28,13 +28,13 @@ class T_DLLCLASS Alloc { public: /*! Allocate chunk of memory. */ - static void* acquire(size_t size, const char* tag); + [[nodiscard]] static void* acquire(size_t size, const char* tag); /*! Free chunk of memory. */ static void free(void* ptr); /*! Allocate aligned chunk of memory. */ - static void* acquireAlign(size_t size, size_t align, const char* tag); + [[nodiscard]] static void* acquireAlign(size_t size, size_t align, const char* tag); /*! Free aligned chunk of memory. */ static void freeAlign(void* ptr); diff --git a/code/Core/Memory/BlockAllocator.h b/code/Core/Memory/BlockAllocator.h index 0df8ff184b..81d7a29ca1 100644 --- a/code/Core/Memory/BlockAllocator.h +++ b/code/Core/Memory/BlockAllocator.h @@ -34,7 +34,7 @@ class T_DLLCLASS BlockAllocator void* top() { return m_top; } - void* alloc(); + [[nodiscard]] void* alloc(); bool free(void* p); diff --git a/code/Core/Memory/DebugAllocator.h b/code/Core/Memory/DebugAllocator.h index fc0a5881b8..b66a130d50 100644 --- a/code/Core/Memory/DebugAllocator.h +++ b/code/Core/Memory/DebugAllocator.h @@ -31,7 +31,7 @@ class DebugAllocator : public IAllocator virtual ~DebugAllocator(); - virtual void* alloc(size_t size, size_t align, const char* const tag) override final; + [[nodiscard]] virtual void* alloc(size_t size, size_t align, const char* const tag) override final; virtual void free(void* ptr) override final; diff --git a/code/Core/Memory/FastAllocator.h b/code/Core/Memory/FastAllocator.h index 9cd7d8ce97..423ba89b2d 100644 --- a/code/Core/Memory/FastAllocator.h +++ b/code/Core/Memory/FastAllocator.h @@ -29,7 +29,7 @@ class FastAllocator : public IAllocator virtual ~FastAllocator(); - virtual void* alloc(size_t size, size_t align, const char* const tag) override final; + [[nodiscard]] virtual void* alloc(size_t size, size_t align, const char* const tag) override final; virtual void free(void* ptr) override final; diff --git a/code/Core/Memory/IAllocator.h b/code/Core/Memory/IAllocator.h index 269bdd8bd8..daac96c1bc 100644 --- a/code/Core/Memory/IAllocator.h +++ b/code/Core/Memory/IAllocator.h @@ -23,7 +23,7 @@ class IAllocator public: virtual ~IAllocator() {} - virtual void* alloc(size_t size, size_t align, const char* const tag) = 0; + [[nodiscard]] virtual void* alloc(size_t size, size_t align, const char* const tag) = 0; virtual void free(void* ptr) = 0; }; diff --git a/code/Core/Memory/PoolAllocator.h b/code/Core/Memory/PoolAllocator.h index 86c3a8caf2..8038068209 100644 --- a/code/Core/Memory/PoolAllocator.h +++ b/code/Core/Memory/PoolAllocator.h @@ -66,14 +66,14 @@ class T_DLLCLASS PoolAllocator : public Object * \param align Alignment of chunk. * \return Pointer to chunk. */ - void* alloc(uint32_t size, uint32_t align); + [[nodiscard]] void* alloc(uint32_t size, uint32_t align); /*! Allocate object. * * \return Pointer to object. */ template < typename Type > - Type* alloc() + [[nodiscard]] Type* alloc() { void* ptr = alloc((uint32_t)sizeof(Type), (uint32_t)alignOf< Type >()); return new (ptr) Type(); @@ -85,7 +85,7 @@ class T_DLLCLASS PoolAllocator : public Object * \return Pointer to first object. */ template < typename Type > - Type* alloc(uint32_t count) + [[nodiscard]] Type* alloc(uint32_t count) { if (!count) return nullptr; @@ -100,7 +100,7 @@ class T_DLLCLASS PoolAllocator : public Object * \return Pointer to first object pointer. */ template < typename Type > - Type** allocArray(uint32_t count) + [[nodiscard]] Type** allocArray(uint32_t count) { if (!count) return nullptr; diff --git a/code/Core/Memory/StdAllocator.h b/code/Core/Memory/StdAllocator.h index c63f881010..a2b7429ce6 100644 --- a/code/Core/Memory/StdAllocator.h +++ b/code/Core/Memory/StdAllocator.h @@ -22,7 +22,7 @@ namespace traktor class StdAllocator : public IAllocator { public: - virtual void* alloc(size_t size, size_t align, const char* const tag) override final; + [[nodiscard]] virtual void* alloc(size_t size, size_t align, const char* const tag) override final; virtual void free(void* ptr) override final; }; diff --git a/code/Core/Memory/SystemConstruct.h b/code/Core/Memory/SystemConstruct.h index 7529edb1d0..cd719666a9 100644 --- a/code/Core/Memory/SystemConstruct.h +++ b/code/Core/Memory/SystemConstruct.h @@ -15,21 +15,21 @@ namespace traktor { template < typename T > -T* allocConstruct() +[[nodiscard]] T* allocConstruct() { void* p = Alloc::acquireAlign(sizeof(T), alignOf< T >(), "global"); return new (p) T(); } template < typename T, typename A > -T* allocConstruct(A a) +[[nodiscard]] T* allocConstruct(A a) { void* p = Alloc::acquireAlign(sizeof(T), alignOf< T >(), "global"); return new (p) T(a); } template < typename T, typename A, typename B, typename C > -T* allocConstruct(A a, B b, C c) +[[nodiscard]] T* allocConstruct(A a, B b, C c) { void* p = Alloc::acquireAlign(sizeof(T), alignOf< T >(), "global"); return new (p) T(a, b, c); diff --git a/code/Core/Memory/TrackAllocator.h b/code/Core/Memory/TrackAllocator.h index 8bdd2b9cea..c85877d9e2 100644 --- a/code/Core/Memory/TrackAllocator.h +++ b/code/Core/Memory/TrackAllocator.h @@ -29,7 +29,7 @@ class TrackAllocator : public IAllocator virtual ~TrackAllocator(); - virtual void* alloc(size_t size, size_t align, const char* const tag) override final; + [[nodiscard]] virtual void* alloc(size_t size, size_t align, const char* const tag) override final; virtual void free(void* ptr) override final; diff --git a/code/Editor/Build/App/Main.cpp b/code/Editor/Build/App/Main.cpp index 7d8d06f588..427f27e88b 100644 --- a/code/Editor/Build/App/Main.cpp +++ b/code/Editor/Build/App/Main.cpp @@ -138,7 +138,8 @@ int main(int argc, const char** argv) const Path cwd = FileSystem::getInstance().getCurrentVolumeAndDirectory(); const Path executablePath = OS::getInstance().getExecutable().getPathOnly(); - FileSystem::getInstance().setCurrentVolumeAndDirectory(executablePath); + if (!FileSystem::getInstance().setCurrentVolumeAndDirectory(executablePath)) + return 1; while (!FileSystem::getInstance().exist(L"LICENSE.txt")) { @@ -153,7 +154,8 @@ int main(int argc, const char** argv) } OS::getInstance().setEnvironment(L"TRAKTOR_HOME", FileSystem::getInstance().getCurrentVolumeAndDirectory().getPathNameOS()); - FileSystem::getInstance().setCurrentVolumeAndDirectory(cwd); + if (!FileSystem::getInstance().setCurrentVolumeAndDirectory(cwd)) + return 1; } std::wstring settingsFile = L"$(TRAKTOR_HOME)/resources/runtime/configurations/Traktor.Editor.config"; diff --git a/code/Render/Context/RenderContext.h b/code/Render/Context/RenderContext.h index 64e89c9bef..f602e860c7 100644 --- a/code/Render/Context/RenderContext.h +++ b/code/Render/Context/RenderContext.h @@ -45,14 +45,14 @@ class T_DLLCLASS RenderContext : public Object virtual ~RenderContext(); /*! Allocate a unaligned block of memory from context's heap. */ - void* alloc(uint32_t blockSize); + [[nodiscard]] void* alloc(uint32_t blockSize); /*! Allocate a aligned block of memory from context's heap. */ - void* alloc(uint32_t blockSize, uint32_t align); + [[nodiscard]] void* alloc(uint32_t blockSize, uint32_t align); /*! Allocate object from context's heap. */ template < typename ObjectType, typename ... ArgumentTypes > - ObjectType* alloc(ArgumentTypes&& ... args) + [[nodiscard]] ObjectType* alloc(ArgumentTypes&& ... args) { void* object = alloc((uint32_t)sizeof(ObjectType), (uint32_t)alignOf< ObjectType >()); return new (object) ObjectType(std::forward< ArgumentTypes >(args) ...); @@ -60,7 +60,7 @@ class T_DLLCLASS RenderContext : public Object /*! Allocate named object from context's heap. */ template < typename ObjectType, typename ... ArgumentTypes > - ObjectType* allocNamed(const std::wstring_view& name, ArgumentTypes&& ... args) + [[nodiscard]] ObjectType* allocNamed(const std::wstring_view& name, ArgumentTypes&& ... args) { ObjectType* object = alloc< ObjectType, ArgumentTypes... >(std::forward< ArgumentTypes >(args) ...); object->name = name; diff --git a/code/Ui/Theme/App/Main.cpp b/code/Ui/Theme/App/Main.cpp index beed266e50..2989301cee 100644 --- a/code/Ui/Theme/App/Main.cpp +++ b/code/Ui/Theme/App/Main.cpp @@ -56,7 +56,8 @@ int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR szCmdLine, int) log::error << L"No LICENSE.txt file found." << Endl; return 1; } - FileSystem::getInstance().setCurrentVolumeAndDirectory(pwd); + if (!FileSystem::getInstance().setCurrentVolumeAndDirectory(pwd)) + return 1; } const Path cwd = FileSystem::getInstance().getCurrentVolumeAndDirectory();