From 28c1f84e689e1380867c16d3dce38df406316ae3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 19 Dec 2022 12:32:50 +0100 Subject: [PATCH] Fix various variable shadowing warnings on MSVC. --- doc/changelog.dox | 1 + doc/snippets/Magnum.cpp | 3 +++ src/Magnum/GL/Context.cpp | 6 ++--- src/Magnum/MeshTools/Compile.cpp | 6 ++--- src/Magnum/SceneTools/sceneconverter.cpp | 30 ++++++++++----------- src/Magnum/Trade/AbstractSceneConverter.cpp | 4 +-- src/Magnum/Trade/MaterialData.cpp | 10 +++---- src/Magnum/Vk/Device.cpp | 4 +-- 8 files changed, 34 insertions(+), 30 deletions(-) diff --git a/doc/changelog.dox b/doc/changelog.dox index 1fb3a5ad1..2402235a1 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -745,6 +745,7 @@ See also: - Worked around a MSVC2022 bug with constexpr conversion operators if C++20 is used, causing most @ref Math tests to fail compilation (see [mosra/magnum#602](https://github.com/mosra/magnum/pull/602)) +- Fixed various variable shadowing warings on MSVC (see [mosra/magnum#611](https://github.com/mosra/magnum/issues/611)) @subsection changelog-latest-bugfixes Bug fixes diff --git a/doc/snippets/Magnum.cpp b/doc/snippets/Magnum.cpp index 2d6b530a1..e67c2fe42 100644 --- a/doc/snippets/Magnum.cpp +++ b/doc/snippets/Magnum.cpp @@ -44,6 +44,7 @@ using namespace Magnum; using namespace Magnum::Math::Literals; #ifdef MAGNUM_TARGET_GL +namespace Wew { Containers::Pointer mesh; bool found = false; @@ -63,6 +64,7 @@ class MeshResourceLoader: public AbstractResourceLoader { } }; /* [AbstractResourceLoader-implementation] */ +} #endif int main() { @@ -304,6 +306,7 @@ Resource shader = } { +using namespace Wew; typedef ResourceManager MyResourceManager; /* [AbstractResourceLoader-use] */ MyResourceManager manager; diff --git a/src/Magnum/GL/Context.cpp b/src/Magnum/GL/Context.cpp index 281cf95b3..73bb860e8 100644 --- a/src/Magnum/GL/Context.cpp +++ b/src/Magnum/GL/Context.cpp @@ -1009,11 +1009,11 @@ bool Context::tryCreate(const Configuration& configuration) { GL::defaultFramebuffer global itself without turning it into a pointer or a function. */ if(!(_configurationFlags & Configuration::Flag::Windowless)) { - Implementation::FramebufferState& state = _state->framebuffer; + Implementation::FramebufferState& framebufferState = _state->framebuffer; GLint viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); - state.defaultViewport = state.viewport = Range2Di::fromSize({viewport[0], viewport[1]}, {viewport[2], viewport[3]}); - CORRADE_INTERNAL_ASSERT(state.defaultViewport != Implementation::FramebufferState::DisengagedViewport); + framebufferState.defaultViewport = framebufferState.viewport = Range2Di::fromSize({viewport[0], viewport[1]}, {viewport[2], viewport[3]}); + CORRADE_INTERNAL_ASSERT(framebufferState.defaultViewport != Implementation::FramebufferState::DisengagedViewport); } /** @todo Get rid of this as well somehow */ Renderer::initializeContextBasedFunctionality(); diff --git a/src/Magnum/MeshTools/Compile.cpp b/src/Magnum/MeshTools/Compile.cpp index 38daa0b6a..3a7443fde 100644 --- a/src/Magnum/MeshTools/Compile.cpp +++ b/src/Magnum/MeshTools/Compile.cpp @@ -565,11 +565,11 @@ Containers::Pair compiledPerVertexJointCount(const Tra continue; const UnsignedInt componentCount = meshData.attributeArraySize(i); - for(UnsignedInt i = 0; i < componentCount; i += 4) { + for(UnsignedInt j = 0; j < componentCount; j += 4) { if(!primaryCount) - primaryCount = Math::min(componentCount - i, 4u); + primaryCount = Math::min(componentCount - j, 4u); else if(!secondaryCount) - secondaryCount = Math::min(componentCount - i, 4u); + secondaryCount = Math::min(componentCount - j, 4u); else break; } } diff --git a/src/Magnum/SceneTools/sceneconverter.cpp b/src/Magnum/SceneTools/sceneconverter.cpp index e312fdc9e..7fbdcfda0 100644 --- a/src/Magnum/SceneTools/sceneconverter.cpp +++ b/src/Magnum/SceneTools/sceneconverter.cpp @@ -750,11 +750,11 @@ well, the IDs reference attributes of the first mesh.)") struct SingleMeshImporter: Trade::AbstractImporter { explicit SingleMeshImporter(Trade::MeshData&& mesh_, Containers::String&& name, Trade::AbstractImporter& original): mesh{std::move(mesh_)}, name{std::move(name)} { for(UnsignedInt i = 0; i != mesh.attributeCount(); ++i) { - const Trade::MeshAttribute name = mesh.attributeName(i); - if(!isMeshAttributeCustom(name)) continue; + const Trade::MeshAttribute attributeName = mesh.attributeName(i); + if(!isMeshAttributeCustom(attributeName)) continue; /* Appending even empty ones so we don't have to special-case "not found" in doMeshAttributeName() */ - arrayAppend(attributeNames, InPlaceInit, meshAttributeCustom(name), original.meshAttributeName(name)); + arrayAppend(attributeNames, InPlaceInit, meshAttributeCustom(attributeName), original.meshAttributeName(attributeName)); } } @@ -1016,10 +1016,10 @@ well, the IDs reference attributes of the first mesh.)") if(images2D) { if(!(Trade::sceneContentsFor(*converter) & Trade::SceneContent::Images2D)) { Warning{} << "Ignoring" << images2D.size() << "2D images not supported by the converter"; - } else for(UnsignedInt i = 0; i != images2D.size(); ++i) { + } else for(UnsignedInt j = 0; j != images2D.size(); ++j) { Trade::Implementation::Duration d{conversionTime}; - if(!converter->add(images2D[i], contents & Trade::SceneContent::Names ? importer->image2DName(i) : Containers::String{})) { - Error{} << "Cannot add 2D image" << i; + if(!converter->add(images2D[j], contents & Trade::SceneContent::Names ? importer->image2DName(j) : Containers::String{})) { + Error{} << "Cannot add 2D image" << j; return 1; } } @@ -1039,10 +1039,10 @@ well, the IDs reference attributes of the first mesh.)") if(images3D) { if(!(Trade::sceneContentsFor(*converter) & Trade::SceneContent::Images3D)) { Warning{} << "Ignoring" << images3D.size() << "3D images not supported by the converter"; - } else for(UnsignedInt i = 0; i != images3D.size(); ++i) { + } else for(UnsignedInt j = 0; j != images3D.size(); ++j) { Trade::Implementation::Duration d{conversionTime}; - if(!converter->add(images3D[i], contents & Trade::SceneContent::Names ? importer->image3DName(i) : Containers::String{})) { - Error{} << "Cannot add 3D image" << i; + if(!converter->add(images3D[j], contents & Trade::SceneContent::Names ? importer->image3DName(j) : Containers::String{})) { + Error{} << "Cannot add 3D image" << j; return 1; } } @@ -1066,18 +1066,18 @@ well, the IDs reference attributes of the first mesh.)") if(meshes) { if(!(Trade::sceneContentsFor(*converter) & Trade::SceneContent::Meshes)) { Warning{} << "Ignoring" << meshes.size() << "meshes not supported by the converter"; - } else for(UnsignedInt i = 0; i != meshes.size(); ++i) { + } else for(UnsignedInt j = 0; j != meshes.size(); ++j) { Trade::Implementation::Duration d{conversionTime}; - const Trade::MeshData& mesh = meshes[i]; + const Trade::MeshData& mesh = meshes[j]; /* Propagate custom attribute names, skip ones that are empty. Compared to data names this is done always to avoid information loss. */ - for(UnsignedInt j = 0; j != mesh.attributeCount(); ++j) { + for(UnsignedInt k = 0; k != mesh.attributeCount(); ++k) { /** @todo have some kind of a map to not have to query the same custom attribute again for each mesh */ - const Trade::MeshAttribute name = mesh.attributeName(j); + const Trade::MeshAttribute name = mesh.attributeName(k); if(!isMeshAttributeCustom(name)) continue; /* The expectation here is that the meshes are coming from the importer instance. If --mesh or --concatenate-meshes @@ -1089,8 +1089,8 @@ well, the IDs reference attributes of the first mesh.)") } } - if(!converter->add(mesh, contents & Trade::SceneContent::Names ? importer->meshName(i) : Containers::String{})) { - Error{} << "Cannot add mesh" << i; + if(!converter->add(mesh, contents & Trade::SceneContent::Names ? importer->meshName(j) : Containers::String{})) { + Error{} << "Cannot add mesh" << j; return 1; } } diff --git a/src/Magnum/Trade/AbstractSceneConverter.cpp b/src/Magnum/Trade/AbstractSceneConverter.cpp index 94b7e56b6..f1fa18864 100644 --- a/src/Magnum/Trade/AbstractSceneConverter.cpp +++ b/src/Magnum/Trade/AbstractSceneConverter.cpp @@ -1312,10 +1312,10 @@ bool AbstractSceneConverter::addImporterContentsInternal(AbstractImporter& impor /* Propagate custom attribute names, skip ones that are empty. Compared to data names this is done always to avoid information loss. */ - for(UnsignedInt j = 0; j != mesh->attributeCount(); ++j) { + for(UnsignedInt k = 0; k != mesh->attributeCount(); ++k) { /** @todo have some kind of a map to not have to query the same custom attribute again for each mesh */ - const Trade::MeshAttribute name = mesh->attributeName(j); + const Trade::MeshAttribute name = mesh->attributeName(k); if(!isMeshAttributeCustom(name)) continue; if(const Containers::String nameString = importer.meshAttributeName(name)) { setMeshAttributeName(name, nameString); diff --git a/src/Magnum/Trade/MaterialData.cpp b/src/Magnum/Trade/MaterialData.cpp index c7461c5f6..68e839878 100644 --- a/src/Magnum/Trade/MaterialData.cpp +++ b/src/Magnum/Trade/MaterialData.cpp @@ -349,11 +349,11 @@ MaterialData::MaterialData(const MaterialTypes types, const DataFlags attributeD CORRADE_ASSERT(begin <= end && end <= _data.size(), "Trade::MaterialData: invalid range (" << Debug::nospace << begin << Debug::nospace << "," << end << Debug::nospace <<") for layer" << i << "with" << _data.size() << "attributes in total", ); - if(end - begin > 1) for(std::size_t i = begin + 1; i != end; ++i) { - CORRADE_ASSERT(_data[i - 1].name() != _data[i].name(), - "Trade::MaterialData: duplicate attribute" << _data[i].name(), ); - CORRADE_ASSERT(_data[i - 1].name() < _data[i].name(), - "Trade::MaterialData:" << _data[i].name() << "has to be sorted before" << _data[i - 1].name() << "if passing non-owned data", ); + if(end - begin > 1) for(std::size_t j = begin + 1; j != end; ++j) { + CORRADE_ASSERT(_data[j - 1].name() != _data[j].name(), + "Trade::MaterialData: duplicate attribute" << _data[j].name(), ); + CORRADE_ASSERT(_data[j - 1].name() < _data[j].name(), + "Trade::MaterialData:" << _data[j].name() << "has to be sorted before" << _data[j - 1].name() << "if passing non-owned data", ); } begin = end; diff --git a/src/Magnum/Vk/Device.cpp b/src/Magnum/Vk/Device.cpp index d6a6f4f23..bd6c3c885 100644 --- a/src/Magnum/Vk/Device.cpp +++ b/src/Magnum/Vk/Device.cpp @@ -842,9 +842,9 @@ Result Device::tryCreateInternal(Instance& instance, const DeviceCreateInfo& inf void Device::initialize(Instance& instance, const Version version, const Containers::StringIterable& enabledExtensions, Containers::Array>& encounteredWorkarounds, const DeviceFeatures& enabledFeatures) { /* Mark all known extensions as enabled */ for(const Containers::StringView extension: enabledExtensions) { - for(const Version version: KnownVersionsForExtensions) { + for(const Version extensionVersion: KnownVersionsForExtensions) { const Containers::ArrayView knownExtensions = - Extension::extensions(version); + Extension::extensions(extensionVersion); const auto found = std::lower_bound(knownExtensions.begin(), knownExtensions.end(), extension, [](const Extension& a, Containers::StringView b) { return a.string() < b; });