diff --git a/source/graphics/HeightMipmap.cpp b/source/graphics/HeightMipmap.cpp index d665300d42..fd3ef795ec 100644 --- a/source/graphics/HeightMipmap.cpp +++ b/source/graphics/HeightMipmap.cpp @@ -255,5 +255,5 @@ void CHeightMipmap::DumpToDisk(const VfsPath& filename) const DynArray da; WARN_IF_ERR(t.encode(filename.Extension(), &da)); g_VFS->CreateFile(filename, DummySharedPtr(da.base), da.pos); - (void)da_free(&da); + DISCARD da_free(&da); } diff --git a/source/graphics/TerrainTextureEntry.cpp b/source/graphics/TerrainTextureEntry.cpp index ac2e707737..e05eac9b75 100644 --- a/source/graphics/TerrainTextureEntry.cpp +++ b/source/graphics/TerrainTextureEntry.cpp @@ -266,7 +266,7 @@ void CTerrainTextureEntry::LoadAlphaMaps(VfsPath &amtype) // get its size and make sure they are all equal. // (the packing algo assumes this) size_t this_width = 0, this_height = 0, this_bpp = 0; // fail-safe - (void)ogl_tex_get_size(textures[i], &this_width, &this_height, &this_bpp); + DISCARD ogl_tex_get_size(textures[i], &this_width, &this_height, &this_bpp); if(this_width != this_height) DEBUG_DISPLAY_ERROR(L"Alpha maps are not square"); // .. first iteration: establish size @@ -293,7 +293,7 @@ void CTerrainTextureEntry::LoadAlphaMaps(VfsPath &amtype) { // get src of copy u8* src = 0; - (void)ogl_tex_get_data(textures[i], &src); + DISCARD ogl_tex_get_data(textures[i], &src); size_t srcstep = bpp/8; @@ -329,11 +329,11 @@ void CTerrainTextureEntry::LoadAlphaMaps(VfsPath &amtype) } for (size_t i = 0; i < NUM_ALPHA_MAPS; i++) - (void)ogl_tex_free(textures[i]); + DISCARD ogl_tex_free(textures[i]); // upload the composite texture Tex t; - (void)t.wrap(total_w, total_h, 8, TEX_GREY, data, 0); + DISCARD t.wrap(total_w, total_h, 8, TEX_GREY, data, 0); // uncomment the following to save a png of the generated texture // in the public/ directory, for debugging @@ -353,11 +353,11 @@ void CTerrainTextureEntry::LoadAlphaMaps(VfsPath &amtype) // ret = (Status)bytes_written; } - (void)da_free(&da);*/ + DISCARD da_free(&da);*/ Handle hCompositeAlphaMap = ogl_tex_wrap(&t, g_VFS, key); - (void)ogl_tex_set_filter(hCompositeAlphaMap, GL_LINEAR); - (void)ogl_tex_set_wrap (hCompositeAlphaMap, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE); + DISCARD ogl_tex_set_filter(hCompositeAlphaMap, GL_LINEAR); + DISCARD ogl_tex_set_wrap (hCompositeAlphaMap, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE); ogl_tex_upload(hCompositeAlphaMap, GL_ALPHA, 0, 0); result.m_hCompositeAlphaMap = hCompositeAlphaMap; diff --git a/source/graphics/TextureManager.cpp b/source/graphics/TextureManager.cpp index d4f0741630..e967235162 100644 --- a/source/graphics/TextureManager.cpp +++ b/source/graphics/TextureManager.cpp @@ -95,12 +95,12 @@ public: data.get()[1] = 64; data.get()[2] = 64; Tex t; - (void)t.wrap(1, 1, 24, 0, data, 0); + DISCARD t.wrap(1, 1, 24, 0, data, 0); m_DefaultHandle = ogl_tex_wrap(&t, m_VFS, L"(default texture)"); - (void)ogl_tex_set_filter(m_DefaultHandle, GL_LINEAR); + DISCARD ogl_tex_set_filter(m_DefaultHandle, GL_LINEAR); if (!m_DisableGL) - (void)ogl_tex_upload(m_DefaultHandle); + DISCARD ogl_tex_upload(m_DefaultHandle); } // Error texture (magenta) @@ -112,12 +112,12 @@ public: data.get()[1] = 0; data.get()[2] = 255; Tex t; - (void)t.wrap(1, 1, 24, 0, data, 0); + DISCARD t.wrap(1, 1, 24, 0, data, 0); m_ErrorHandle = ogl_tex_wrap(&t, m_VFS, L"(error texture)"); - (void)ogl_tex_set_filter(m_ErrorHandle, GL_LINEAR); + DISCARD ogl_tex_set_filter(m_ErrorHandle, GL_LINEAR); if (!m_DisableGL) - (void)ogl_tex_upload(m_ErrorHandle); + DISCARD ogl_tex_upload(m_ErrorHandle); // Construct a CTexture to return to callers who want an error texture CTextureProperties props(L"(error texture)"); @@ -134,8 +134,8 @@ public: { UnregisterFileReloadFunc(ReloadChangedFileCB, this); - (void)ogl_tex_free(m_DefaultHandle); - (void)ogl_tex_free(m_ErrorHandle); + DISCARD ogl_tex_free(m_DefaultHandle); + DISCARD ogl_tex_free(m_ErrorHandle); } CTexturePtr GetErrorTexture() @@ -188,14 +188,14 @@ public: // Get some flags for later use size_t flags = 0; - (void)ogl_tex_get_format(h, &flags, NULL); + DISCARD ogl_tex_get_format(h, &flags, NULL); // Initialise base color from the texture - (void)ogl_tex_get_average_color(h, &texture->m_BaseColor); + DISCARD ogl_tex_get_average_color(h, &texture->m_BaseColor); // Set GL upload properties - (void)ogl_tex_set_wrap(h, texture->m_Properties.m_WrapS, texture->m_Properties.m_WrapT); - (void)ogl_tex_set_anisotropy(h, texture->m_Properties.m_Aniso); + DISCARD ogl_tex_set_wrap(h, texture->m_Properties.m_WrapS, texture->m_Properties.m_WrapT); + DISCARD ogl_tex_set_anisotropy(h, texture->m_Properties.m_Aniso); // Prevent ogl_tex automatically generating mipmaps (which is slow and unwanted), // by avoiding mipmapped filters unless the source texture already has mipmaps @@ -214,7 +214,7 @@ public: break; } } - (void)ogl_tex_set_filter(h, filter); + DISCARD ogl_tex_set_filter(h, filter); // Upload to GL if (!m_DisableGL && ogl_tex_upload(h, texture->m_Properties.m_Format) < 0) @@ -604,21 +604,21 @@ void CTexture::SetHandle(Handle handle, bool takeOwnership) size_t CTexture::GetWidth() const { size_t w = 0; - (void)ogl_tex_get_size(m_Handle, &w, 0, 0); + DISCARD ogl_tex_get_size(m_Handle, &w, 0, 0); return w; } size_t CTexture::GetHeight() const { size_t h = 0; - (void)ogl_tex_get_size(m_Handle, 0, &h, 0); + DISCARD ogl_tex_get_size(m_Handle, 0, &h, 0); return h; } bool CTexture::HasAlpha() const { size_t flags = 0; - (void)ogl_tex_get_format(m_Handle, &flags, 0); + DISCARD ogl_tex_get_format(m_Handle, &flags, 0); return (flags & TEX_ALPHA) != 0; } @@ -630,7 +630,7 @@ u32 CTexture::GetBaseColor() const size_t CTexture::GetUploadedSize() const { size_t size = 0; - (void)ogl_tex_get_uploaded_size(m_Handle, &size); + DISCARD ogl_tex_get_uploaded_size(m_Handle, &size); return size; } diff --git a/source/gui/GUIManager.cpp b/source/gui/GUIManager.cpp index 81b76dceed..f18926545e 100644 --- a/source/gui/GUIManager.cpp +++ b/source/gui/GUIManager.cpp @@ -255,7 +255,7 @@ void CGUIManager::SGUIPage::PerformCallbackFunction(ScriptInterface::StructuredC scriptInterface->ReadStructuredClone(args, &argVal); JS::AutoValueVector paramData(rq.cx); - paramData.append(argVal); + DISCARD paramData.append(argVal); JS::RootedValue result(rq.cx); diff --git a/source/gui/ObjectBases/IGUIObject.cpp b/source/gui/ObjectBases/IGUIObject.cpp index 3e56eb7bcd..da8dd4577c 100644 --- a/source/gui/ObjectBases/IGUIObject.cpp +++ b/source/gui/ObjectBases/IGUIObject.cpp @@ -403,7 +403,7 @@ InReaction IGUIObject::SendMouseEvent(EGUIMessageType type, const CStr& eventNam "y", mousePos.y, "buttons", m_pGUI.GetMouseButtons()); JS::AutoValueVector paramData(rq.cx); - (void)paramData.append(mouse); + DISCARD paramData.append(mouse); ScriptEvent(eventName, paramData); return msg.skipped ? IN_PASS : IN_HANDLED; diff --git a/source/gui/ObjectTypes/CMiniMap.cpp b/source/gui/ObjectTypes/CMiniMap.cpp index ba69152007..fb3008679d 100644 --- a/source/gui/ObjectTypes/CMiniMap.cpp +++ b/source/gui/ObjectTypes/CMiniMap.cpp @@ -251,8 +251,8 @@ bool CMiniMap::FireWorldClickEvent(int button, int UNUSED(clicks)) ScriptInterface::ToJSVal(rq, &buttonJs, button); JS::AutoValueVector paramData(rq.cx); - paramData.append(coords); - paramData.append(buttonJs); + DISCARD paramData.append(coords); + DISCARD paramData.append(buttonJs); return ScriptEventWithReturn(EventNameWorldClick, paramData); } diff --git a/source/lib/code_annotation.h b/source/lib/code_annotation.h index 8a2c2e83b2..149624b3f2 100644 --- a/source/lib/code_annotation.h +++ b/source/lib/code_annotation.h @@ -56,6 +56,12 @@ # define UNUSED2(param) ((void)(param)) #endif +/** + * Mark a function return value as discardable to silence [[nodiscard]] warnings. + * (void) would be sufficient but Spidermonkey still uses warn_unused_result, + * and GCC is stricter about that. See https://bugzilla.mozilla.org/show_bug.cgi?id=1571631. + **/ +#define DISCARD (void)! /** * indicate a function will not throw any synchronous exceptions, diff --git a/source/ps/GameSetup/GameSetup.cpp b/source/ps/GameSetup/GameSetup.cpp index 3ffbf6cf96..87f9080786 100644 --- a/source/ps/GameSetup/GameSetup.cpp +++ b/source/ps/GameSetup/GameSetup.cpp @@ -188,11 +188,11 @@ void GUI_DisplayLoadProgress(int percent, const wchar_t* pending_task) JS::AutoValueVector paramData(rq.cx); - paramData.append(JS::NumberValue(percent)); + DISCARD paramData.append(JS::NumberValue(percent)); JS::RootedValue valPendingTask(rq.cx); scriptInterface.ToJSVal(rq, &valPendingTask, pending_task); - paramData.append(valPendingTask); + DISCARD paramData.append(valPendingTask); g_GUI->SendEventToAll(g_EventNameGameLoadProgress, paramData); } diff --git a/source/ps/Util.cpp b/source/ps/Util.cpp index 3a6d7d5474..0a89b9df57 100644 --- a/source/ps/Util.cpp +++ b/source/ps/Util.cpp @@ -195,7 +195,7 @@ Status tex_write(Tex* t, const VfsPath& filename) ret = (Status)bytes_written; } - (void)da_free(&da); + DISCARD da_free(&da); return ret; } diff --git a/source/renderer/Renderer.cpp b/source/renderer/Renderer.cpp index b62d114aef..a994df88cf 100644 --- a/source/renderer/Renderer.cpp +++ b/source/renderer/Renderer.cpp @@ -1795,7 +1795,7 @@ int CRenderer::LoadAlphaMaps() // get its size and make sure they are all equal. // (the packing algo assumes this) size_t this_width = 0, this_height = 0, this_bpp = 0; // fail-safe - (void)ogl_tex_get_size(textures[i], &this_width, &this_height, &this_bpp); + DISCARD ogl_tex_get_size(textures[i], &this_width, &this_height, &this_bpp); if(this_width != this_height) DEBUG_DISPLAY_ERROR(L"Alpha maps are not square"); // .. first iteration: establish size @@ -1822,7 +1822,7 @@ int CRenderer::LoadAlphaMaps() { // get src of copy u8* src = 0; - (void)ogl_tex_get_data(textures[i], &src); + DISCARD ogl_tex_get_data(textures[i], &src); size_t srcstep = bpp/8; @@ -1858,11 +1858,11 @@ int CRenderer::LoadAlphaMaps() } for (size_t i = 0; i < NumAlphaMaps; i++) - (void)ogl_tex_free(textures[i]); + DISCARD ogl_tex_free(textures[i]); // upload the composite texture Tex t; - (void)t.wrap(total_w, total_h, 8, TEX_GREY, data, 0); + DISCARD t.wrap(total_w, total_h, 8, TEX_GREY, data, 0); /*VfsPath filename("blendtex.png"); @@ -1880,11 +1880,11 @@ int CRenderer::LoadAlphaMaps() // ret = (Status)bytes_written; } - (void)da_free(&da);*/ + DISCARD da_free(&da);*/ m_hCompositeAlphaMap = ogl_tex_wrap(&t, g_VFS, key); - (void)ogl_tex_set_filter(m_hCompositeAlphaMap, GL_LINEAR); - (void)ogl_tex_set_wrap (m_hCompositeAlphaMap, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE); + DISCARD ogl_tex_set_filter(m_hCompositeAlphaMap, GL_LINEAR); + DISCARD ogl_tex_set_wrap (m_hCompositeAlphaMap, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE); int ret = ogl_tex_upload(m_hCompositeAlphaMap, GL_ALPHA, 0, 0); return ret; diff --git a/source/renderer/TerrainRenderer.cpp b/source/renderer/TerrainRenderer.cpp index 5be8f322a3..d0ac9f0236 100644 --- a/source/renderer/TerrainRenderer.cpp +++ b/source/renderer/TerrainRenderer.cpp @@ -243,7 +243,7 @@ void TerrainRenderer::RenderTerrainFixed(int cullGroup) // render blends // switch on the composite alpha map texture - (void)ogl_tex_bind(g_Renderer.m_hCompositeAlphaMap, 1); + DISCARD ogl_tex_bind(g_Renderer.m_hCompositeAlphaMap, 1); // switch on second uv set pglClientActiveTextureARB(GL_TEXTURE1); diff --git a/source/scriptinterface/NativeWrapperDefns.h b/source/scriptinterface/NativeWrapperDefns.h index 300643d7e1..b808e2a1e6 100644 --- a/source/scriptinterface/NativeWrapperDefns.h +++ b/source/scriptinterface/NativeWrapperDefns.h @@ -180,7 +180,7 @@ bool ScriptInterface::CallFunction(JS::HandleValue val, const char* name, R& ret ScriptRequest rq(this); JS::RootedValue jsRet(rq.cx); JS::AutoValueVector argv(rq.cx); - (void)argv.resize(sizeof...(Ts)); + DISCARD argv.resize(sizeof...(Ts)); AssignOrToJSValHelper<0>(rq, argv, params...); if (!CallFunction_(val, name, argv, &jsRet)) return false; @@ -193,7 +193,7 @@ bool ScriptInterface::CallFunction(JS::HandleValue val, const char* name, JS::Ro ScriptRequest rq(this); JS::MutableHandle jsRet(ret); JS::AutoValueVector argv(rq.cx); - (void)argv.resize(sizeof...(Ts)); + DISCARD argv.resize(sizeof...(Ts)); AssignOrToJSValHelper<0>(rq, argv, params...); return CallFunction_(val, name, argv, jsRet); } @@ -203,7 +203,7 @@ bool ScriptInterface::CallFunction(JS::HandleValue val, const char* name, JS::Mu { ScriptRequest rq(this); JS::AutoValueVector argv(rq.cx); - (void)argv.resize(sizeof...(Ts)); + DISCARD argv.resize(sizeof...(Ts)); AssignOrToJSValHelper<0>(rq, argv, params...); return CallFunction_(val, name, argv, ret); } @@ -215,7 +215,7 @@ bool ScriptInterface::CallFunctionVoid(JS::HandleValue val, const char* name, co ScriptRequest rq(this); JS::RootedValue jsRet(rq.cx); JS::AutoValueVector argv(rq.cx); - (void)argv.resize(sizeof...(Ts)); + DISCARD argv.resize(sizeof...(Ts)); AssignOrToJSValHelper<0>(rq, argv, params...); return CallFunction_(val, name, argv, &jsRet); } diff --git a/source/simulation2/components/CCmpAIManager.cpp b/source/simulation2/components/CCmpAIManager.cpp index e0edc1e938..42538c387c 100644 --- a/source/simulation2/components/CCmpAIManager.cpp +++ b/source/simulation2/components/CCmpAIManager.cpp @@ -159,7 +159,7 @@ private: } JS::AutoValueVector argv(rq.cx); - argv.append(settings.get()); + DISCARD argv.append(settings.get()); m_ScriptInterface->CallConstructor(ctor, argv, &m_Obj); if (m_Obj.get().isNull()) @@ -458,7 +458,7 @@ public: "templates", m_EntityTemplates); JS::AutoValueVector argv(rq.cx); - argv.append(settings); + DISCARD argv.append(settings); m_ScriptInterface->CallConstructor(ctor, argv, &m_SharedAIObj); if (m_SharedAIObj.get().isNull()) diff --git a/source/simulation2/system/ReplayTurnManager.cpp b/source/simulation2/system/ReplayTurnManager.cpp index 7efeba8409..189b893ca7 100644 --- a/source/simulation2/system/ReplayTurnManager.cpp +++ b/source/simulation2/system/ReplayTurnManager.cpp @@ -91,15 +91,15 @@ void CReplayTurnManager::NotifyFinishedUpdate(u32 turn) JS::AutoValueVector paramData(rq.cx); - paramData.append(JS::NumberValue(turn)); + DISCARD paramData.append(JS::NumberValue(turn)); JS::RootedValue hashVal(rq.cx); scriptInterface.ToJSVal(rq, &hashVal, hash); - paramData.append(hashVal); + DISCARD paramData.append(hashVal); JS::RootedValue expectedHashVal(rq.cx); scriptInterface.ToJSVal(rq, &expectedHashVal, expectedHash); - paramData.append(expectedHashVal); + DISCARD paramData.append(expectedHashVal); g_GUI->SendEventToAll(EventNameReplayOutOfSync, paramData); }