Clang (in my case 16 from Xcode 16) warns that expression with side effects will be evaluated despite being used as an operand to 'typeid'. I am building with python3 ./build_scripts/build_usd.py ~/Downloads/usd --build-variant debug --no-imaging -vvv.
This is caused by the pattern of passing the expression result directly to the typeid function. A simple fix would be to move the pointer getting outside of the typeid and pass the result in, to make it clear to the compiler that this is desired.
This would be a great first issue for someone to get to grips with building USD and fixing some of the warnings that might otherwise obscure other issues in the codebase.
Files that include it (but are not limited to):
pxr/usd/sdf/specType.cpp
pxr/usd/sdf/specType.cpp
pxr/usdImaging/usdImaging/indexProxy.cpp
pxr/usdImaging/usdImaging/instanceAdapter.cpp
Examples of the warning are below:
[1250/4632] Building CXX object pxr/usd/sdf/CMakeFiles/sdf.dir/fileFormat.cpp.o
/Users/dhruvgovil/Projects/usd/pxr/usd/sdf/fileFormat.cpp:568:24: warning: expression with side effects will be evaluated despite being used as an operand to 'typeid' [-Wpotentially-evaluated-expression]
568 | typeid(*get_pointer(data)), typeid(*get_pointer(oldData)));
| ^
/Users/dhruvgovil/Projects/usd/pxr/usd/sdf/fileFormat.cpp:568:52: warning: expression with side effects will be evaluated despite being used as an operand to 'typeid' [-Wpotentially-evaluated-expression]
568 | typeid(*get_pointer(data)), typeid(*get_pointer(oldData)));
| ^
2 warnings generated.
/Users/dhruvgovil/Projects/usd/pxr/usd/sdf/fileFormat.cpp:568:24: warning: expression with side effects will be evaluated despite being used as an operand to 'typeid' [-Wpotentially-evaluated-expression]
568 | typeid(*get_pointer(data)), typeid(*get_pointer(oldData)));
| ^
/Users/dhruvgovil/Projects/usd/pxr/usd/sdf/fileFormat.cpp:568:52: warning: expression with side effects will be evaluated despite being used as an operand to 'typeid' [-Wpotentially-evaluated-expression]
568 | typeid(*get_pointer(data)), typeid(*get_pointer(oldData)));
| ^
2 warnings generated.
[1286/4632] Building CXX object pxr/usd/sdf/CMakeFiles/sdf.dir/specType.cpp.o
/Users/dhruvgovil/Projects/usd/pxr/usd/sdf/specType.cpp:197:52: warning: expression with side effects will be evaluated despite being used as an operand to 'typeid' [-Wpotentially-evaluated-expression]
197 | const TfType& schemaType = TfType::Find(typeid(from.GetSchema()));
| ^
/Users/dhruvgovil/Projects/usd/pxr/usd/sdf/specType.cpp:247:56: warning: expression with side effects will be evaluated despite being used as an operand to 'typeid' [-Wpotentially-evaluated-expression]
247 | const TfType& fromSchemaType = TfType::Find(typeid(from.GetSchema()));
| ^
2 warnings generated.
/Users/dhruvgovil/Projects/usd/pxr/usd/sdf/specType.cpp:197:52: warning: expression with side effects will be evaluated despite being used as an operand to 'typeid' [-Wpotentially-evaluated-expression]
197 | const TfType& schemaType = TfType::Find(typeid(from.GetSchema()));
| ^
/Users/dhruvgovil/Projects/usd/pxr/usd/sdf/specType.cpp:247:56: warning: expression with side effects will be evaluated despite being used as an operand to 'typeid' [-Wpotentially-evaluated-expression]
247 | const TfType& fromSchemaType = TfType::Find(typeid(from.GetSchema()));
| ^
2 warnings generated.
[3063/4632] Building CXX object pxr/usdImaging/usdImaging/CMakeFiles/usdImaging.dir/indexProxy.cpp.o
/Users/dhruvgovil/Projects/usd/pxr/usdImaging/usdImaging/indexProxy.cpp:46:45: warning: expression with side effects will be evaluated despite being used as an operand to 'typeid' [-Wpotentially-evaluated-expression]
46 | TfType::GetCanonicalTypeName(typeid(*(adapterToInsert.get()))).c_str());
| ^
/Users/dhruvgovil/Projects/usd/pxr/usdImaging/usdImaging/indexProxy.cpp:277:59: warning: expression with side effects will be evaluated despite being used as an operand to 'typeid' [-Wpotentially-evaluated-expression]
277 | adapter ? TfType::GetCanonicalTypeName(typeid(*adapter)).c_str()
| ^
2 warnings generated.
/Users/dhruvgovil/Projects/usd/pxr/usdImaging/usdImaging/indexProxy.cpp:46:45: warning: expression with side effects will be evaluated despite being used as an operand to 'typeid' [-Wpotentially-evaluated-expression]
46 | TfType::GetCanonicalTypeName(typeid(*(adapterToInsert.get()))).c_str());
| ^
/Users/dhruvgovil/Projects/usd/pxr/usdImaging/usdImaging/indexProxy.cpp:277:59: warning: expression with side effects will be evaluated despite being used as an operand to 'typeid' [-Wpotentially-evaluated-expression]
277 | adapter ? TfType::GetCanonicalTypeName(typeid(*adapter)).c_str()
| ^
2 warnings generated.
[3305/4632] Building CXX object pxr/usdImaging/usdImaging/CMakeFiles/usdImaging.dir/instanceAdapter.cpp.o
/Users/dhruvgovil/Projects/usd/pxr/usdImaging/usdImaging/instanceAdapter.cpp:352:57: warning: expression with side effects will be evaluated despite being used as an operand to 'typeid' [-Wpotentially-evaluated-expression]
352 | TfType::GetCanonicalTypeName(typeid(*primAdapter)).c_str() :
| ^
1 warning generated.
/Users/dhruvgovil/Projects/usd/pxr/usdImaging/usdImaging/instanceAdapter.cpp:352:57: warning: expression with side effects will be evaluated despite being used as an operand to 'typeid' [-Wpotentially-evaluated-expression]
352 | TfType::GetCanonicalTypeName(typeid(*primAdapter)).c_str() :
| ^
1 warning generated.
Description of Issue
Clang (in my case 16 from Xcode 16) warns that
expression with side effects will be evaluated despite being used as an operand to 'typeid'
. I am building withpython3 ./build_scripts/build_usd.py ~/Downloads/usd --build-variant debug --no-imaging -vvv
.This is caused by the pattern of passing the expression result directly to the typeid function. A simple fix would be to move the pointer getting outside of the typeid and pass the result in, to make it clear to the compiler that this is desired.
This would be a great first issue for someone to get to grips with building USD and fixing some of the warnings that might otherwise obscure other issues in the codebase.
Files that include it (but are not limited to):
pxr/usd/sdf/specType.cpp
pxr/usd/sdf/specType.cpp
pxr/usdImaging/usdImaging/indexProxy.cpp
pxr/usdImaging/usdImaging/instanceAdapter.cpp
Examples of the warning are below: