Skip to content

Commit c342c0b

Browse files
authored
Add -Wshadow to align with windows compiler warnings (#2735)
Continuing the work proposed in #2385. I noticed this as more compiler warnings were raised in other work for windows CI. Add `-Wshadow` to non windows compile path. This aligns us a little closer with the strict Windows path warnings, making it easier to catch build errors locally before hitting CI. Fixed some shadowing issues in Metal code-path that were missed previously because of mis-matched compiler warnings. Need to add `-Wno-shadow` for dependency builds (IMGui/NanoGui). Also adding `-Wno-nontrivial-memcall` because of recent clang warnings building IMGui.
1 parent d6ecee3 commit c342c0b

File tree

8 files changed

+35
-35
lines changed

8 files changed

+35
-35
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ if(MSVC)
312312
add_compile_options(/WX)
313313
endif()
314314
else()
315-
add_compile_options(-Wall -Wunused-parameter -Wno-missing-braces)
315+
add_compile_options(-Wall -Wunused-parameter -Wshadow -Wno-missing-braces)
316316
if(MATERIALX_WARNINGS_AS_ERRORS)
317317
add_compile_options(-Werror)
318318
endif()

source/MaterialXGenOsl/LibsToOso.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
namespace mx = MaterialX;
2626

27-
const std::string options =
27+
const std::string argOptions =
2828
" Options: \n"
2929
" --outputOsoPath [DIRPATH] TODO\n"
3030
" --libraryRelativeOsoPath [DIRPATH] TODO\n"
@@ -263,7 +263,7 @@ int main(int argc, char* const argv[])
263263
std::cout << " - Compiled with liboslcomp";
264264
#endif
265265
std::cout << std::endl;
266-
std::cout << options << std::endl;
266+
std::cout << argOptions << std::endl;
267267

268268
return 0;
269269
}

source/MaterialXGraphEditor/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ endif()
99
if(MSVC)
1010
add_compile_options(-wd4100 -wd4152 -wd4201 -wd4244 -wd4456)
1111
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
12-
add_compile_options(-Wno-unused -Wno-deprecated -Wno-comment -Wno-unused-variable -Wno-unused-parameter)
12+
add_compile_options(-Wno-unused -Wno-deprecated -Wno-comment -Wno-unused-variable -Wno-unused-parameter -Wno-shadow)
1313
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
14-
add_compile_options(-Wno-format-truncation -Wno-use-after-free -Wno-comment -Wno-unused-but-set-variable -Wno-unused-parameter)
14+
add_compile_options(-Wno-format-truncation -Wno-use-after-free -Wno-comment -Wno-unused-but-set-variable -Wno-unused-parameter -Wno-shadow)
1515
endif()
1616

1717
file(GLOB materialx_source "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")

source/MaterialXRenderGlsl/GlslMaterial.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -324,30 +324,30 @@ VariableBlock* GlslMaterial::getPublicUniforms() const
324324

325325
ShaderPort* GlslMaterial::findUniform(const std::string& path) const
326326
{
327-
ShaderPort* port = nullptr;
327+
ShaderPort* shaderPort = nullptr;
328328
VariableBlock* publicUniforms = getPublicUniforms();
329329
if (publicUniforms)
330330
{
331331
// Scan block based on path match predicate
332-
port = publicUniforms->find([path](ShaderPort* port)
332+
shaderPort = publicUniforms->find([path](ShaderPort* port)
333333
{
334334
return (port && stringEndsWith(port->getPath(), path));
335335
});
336-
if (!port)
336+
if (!shaderPort)
337337
{
338-
port = publicUniforms->find([path](ShaderPort* port)
338+
shaderPort = publicUniforms->find([path](ShaderPort* port)
339339
{
340340
return (port && stringEndsWith(path, port->getName()));
341341
});
342342
}
343343

344344
// Check if the uniform exists in the shader program
345-
if (port && !_glProgram->getUniformsList().count(port->getVariable()))
345+
if (shaderPort && !_glProgram->getUniformsList().count(shaderPort->getVariable()))
346346
{
347-
port = nullptr;
347+
shaderPort = nullptr;
348348
}
349349
}
350-
return port;
350+
return shaderPort;
351351
}
352352

353353
void GlslMaterial::modifyUniform(const std::string& path, ConstValuePtr value, std::string valueString)

source/MaterialXRenderGlsl/GlslProgram.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -942,9 +942,9 @@ const GlslProgram::InputMap& GlslProgram::updateUniformsList()
942942
continue;
943943
}
944944

945-
for (size_t i = 0; i < uniforms.size(); ++i)
945+
for (size_t uniformIndex = 0; uniformIndex < uniforms.size(); ++uniformIndex)
946946
{
947-
const ShaderPort* v = uniforms[i];
947+
const ShaderPort* v = uniforms[uniformIndex];
948948

949949
const auto& variablePath = v->getPath();
950950
const auto& variableUnit = v->getUnit();
@@ -957,15 +957,15 @@ const GlslProgram::InputMap& GlslProgram::updateUniformsList()
957957
{
958958
auto populateUniformInput_impl =
959959
[this, variablePath, variableUnit, variableColorspace, variableSemantic, &errors, uniforms, &uniformTypeMismatchFound]
960-
(TypeDesc typedesc, const string& variableName, ConstValuePtr variableValue, auto& populateUniformInput_ref) -> void
960+
(TypeDesc typedesc_impl, const string& variableName_impl, ConstValuePtr variableValue_impl, auto& populateUniformInput_ref) -> void
961961
{
962-
if (!typedesc.isStruct())
962+
if (!typedesc_impl.isStruct())
963963
{
964964
// Handle non-struct types
965-
int glType = mapTypeToOpenGLType(typedesc);
965+
int glType = mapTypeToOpenGLType(typedesc_impl);
966966

967967
// There is no way to match with an unnamed variable
968-
if (variableName.empty())
968+
if (variableName_impl.empty())
969969
{
970970
return;
971971
}
@@ -976,26 +976,26 @@ const GlslProgram::InputMap& GlslProgram::updateUniformsList()
976976
return;
977977
}
978978

979-
auto inputIt = _uniformList.find(variableName);
979+
auto inputIt = _uniformList.find(variableName_impl);
980980
if (inputIt != _uniformList.end())
981981
{
982982
Input* input = inputIt->second.get();
983983
input->path = variablePath;
984984
input->unit = variableUnit;
985985
input->colorspace = variableColorspace;
986-
input->value = variableValue;
986+
input->value = variableValue_impl;
987987
if (input->gltype == glType)
988988
{
989-
input->typeString = typedesc.getName();
989+
input->typeString = typedesc_impl.getName();
990990
}
991991
else
992992
{
993993
errors.push_back(
994994
"Pixel shader uniform block type mismatch [" + uniforms.getName() + "]. "
995-
+ "Name: \"" + variableName
996-
+ "\". Type: \"" + typedesc.getName()
995+
+ "Name: \"" + variableName_impl
996+
+ "\". Type: \"" + typedesc_impl.getName()
997997
+ "\". Semantic: \"" + variableSemantic
998-
+ "\". Value: \"" + (variableValue ? variableValue->getValueString() : "<none>")
998+
+ "\". Value: \"" + (variableValue_impl ? variableValue_impl->getValueString() : "<none>")
999999
+ "\". Unit: \"" + (!variableUnit.empty() ? variableUnit : "<none>")
10001000
+ "\". Colorspace: \"" + (!variableColorspace.empty() ? variableColorspace : "<none>")
10011001
+ "\". GLType: " + std::to_string(glType));
@@ -1005,16 +1005,16 @@ const GlslProgram::InputMap& GlslProgram::updateUniformsList()
10051005
}
10061006
else
10071007
{
1008-
auto variableStructMembers = typedesc.getStructMembers();
1008+
auto variableStructMembers = typedesc_impl.getStructMembers();
10091009
if (variableStructMembers)
10101010
{
10111011
// If we're a struct - we need to loop over each member
1012-
auto aggregateValue = std::static_pointer_cast<const AggregateValue>(variableValue);
1012+
auto aggregateValue = std::static_pointer_cast<const AggregateValue>(variableValue_impl);
10131013

10141014
for (size_t i = 0, n = variableStructMembers->size(); i < n; ++i)
10151015
{
10161016
const auto& structMember = (*variableStructMembers)[i];
1017-
auto memberVariableName = variableName + "." + structMember.getName();
1017+
auto memberVariableName = variableName_impl + "." + structMember.getName();
10181018
auto memberVariableValue = aggregateValue->getMemberValue(i);
10191019

10201020
populateUniformInput_ref(structMember.getType(), memberVariableName, memberVariableValue, populateUniformInput_ref);

source/MaterialXRenderMsl/MslPipelineStateObject.mm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -687,8 +687,8 @@ int GetStrideOfMetalType(MTLDataType type)
687687

688688
// Set the number of active light sources
689689
size_t lightCount = lightHandler->getLightSources().size();
690-
auto input = uniformList.find(HW::NUM_ACTIVE_LIGHT_SOURCES);
691-
if (input == uniformList.end())
690+
auto numActiveLightSourcesInput = uniformList.find(HW::NUM_ACTIVE_LIGHT_SOURCES);
691+
if (numActiveLightSourcesInput == uniformList.end())
692692
{
693693
// No lighting information so nothing further to do
694694
lightCount = 0;
@@ -746,8 +746,8 @@ int GetStrideOfMetalType(MTLDataType type)
746746
// Bind direct lighting properties.
747747
if (hasUniform(HW::NUM_ACTIVE_LIGHT_SOURCES))
748748
{
749-
int lightCount = lightHandler->getDirectLighting() ? (int) lightHandler->getLightSources().size() : 0;
750-
bindUniform(HW::NUM_ACTIVE_LIGHT_SOURCES, Value::createValue(lightCount));
749+
lightCount = lightHandler->getDirectLighting() ? lightCount : 0;
750+
bindUniform(HW::NUM_ACTIVE_LIGHT_SOURCES, Value::createValue(static_cast<int>(lightCount)));
751751
LightIdMap idMap = lightHandler->computeLightIdMap(lightHandler->getLightSources());
752752
size_t index = 0;
753753
for (NodePtr light : lightHandler->getLightSources())

source/MaterialXTest/MaterialXRender/RenderUtil.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,9 @@ void ShaderRenderTester::addAdditionalTestStreams(mx::MeshPtr mesh)
450450
mesh->addStream(geomColor4Stream);
451451
}
452452

453-
auto sineData = [](float uv, float freq){
453+
auto sineData = [](float texCoord, float freq){
454454
const float PI = std::acos(-1.0f);
455-
float angle = uv * 2 * PI * freq;
455+
float angle = texCoord * 2 * PI * freq;
456456
return std::sin(angle) / 2.0f + 1.0f;
457457
};
458458
if (!uv.empty())

source/MaterialXView/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ else()
7171
if(MSVC)
7272
add_compile_options(-wd4389)
7373
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
74-
add_compile_options(-Wno-deprecated -Wno-unused-parameter)
74+
add_compile_options(-Wno-deprecated -Wno-unused-parameter -Wno-shadow)
7575
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
76-
add_compile_options(-Wno-format-truncation -Wno-stringop-overflow -Wno-use-after-free -Wno-unused-parameter)
76+
add_compile_options(-Wno-format-truncation -Wno-stringop-overflow -Wno-use-after-free -Wno-unused-parameter -Wno-shadow)
7777
endif()
7878

7979
# Disable NanoGUI compiler modifications for Clang

0 commit comments

Comments
 (0)