Skip to content

Commit 2dd7c61

Browse files
fredroyhugtalbot
andauthored
[Framework] Fix more warnings (msvc) (sofa-framework#6113)
* fix C4458 C4456 C4244 C4267 C4245 C4701 C4515 warnings * fix warning C4244 C4189 * ignore warning 4589 * fix compilation error with clang --------- Co-authored-by: Hugo <hugo.talbot@sofa-framework.org>
1 parent d8ab500 commit 2dd7c61

27 files changed

Lines changed: 104 additions & 91 deletions

File tree

Sofa/framework/Config/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ endif()
181181
## Windows-specific
182182
if(WIN32)
183183
list(APPEND SOFACONFIG_COMPILE_OPTIONS "/W4")
184+
# MSVC warning suppressions
185+
list(APPEND SOFACONFIG_COMPILE_OPTIONS "/wd4589") # Constructor of abstract class ignores initializer for virtual base class
186+
184187
list(APPEND SOFACONFIG_COMPILE_OPTIONS "-D_USE_MATH_DEFINES")
185188
list(APPEND SOFACONFIG_COMPILE_OPTIONS "-D_CRT_SECURE_NO_WARNINGS")
186189
list(APPEND SOFACONFIG_COMPILE_OPTIONS "-D_CRT_NONSTDC_NO_DEPRECATE")

Sofa/framework/Core/src/sofa/core/CollisionElement.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class BaseCollisionElementIterator
5959
/// Constructor.
6060
/// This constructor should be used in case a vector of indices is used.
6161
BaseCollisionElementIterator(VIterator vit, VIterator vitend)
62-
: index(-1), it(vit), itend(vitend)
62+
: index(static_cast<Index>(-1)), it(vit), itend(vitend)
6363
{
6464
if (it != itend) index = *it;
6565
}

Sofa/framework/Core/src/sofa/core/ComponentLibrary.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace sofa::core
2929
std::string caseInsensitive(const std::string &text)
3030
{
3131
std::string result; result.resize(text.size());
32-
for (unsigned int i=0; i<text.size(); ++i) result[i] = toupper(text[i]);
32+
for (unsigned int i=0; i<text.size(); ++i) result[i] = static_cast<char>(toupper(text[i]));
3333
return result;
3434
}
3535

Sofa/framework/Core/src/sofa/core/DataTracker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ void DataTrackerDDGNode::cleanDirty(const core::ExecParams*)
8787

8888
void DataTrackerDDGNode::updateAllInputsIfDirty()
8989
{
90-
const DDGLinkContainer& inputs = DDGNode::getInputs();
91-
for(const auto input : inputs)
90+
const DDGLinkContainer& ddgInputs = DDGNode::getInputs();
91+
for(const auto input : ddgInputs)
9292
{
9393
static_cast<core::objectmodel::BaseData*>(input)->updateIfDirty();
9494
}

Sofa/framework/Core/src/sofa/core/Mapping.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ namespace sofa::core
2828
{
2929

3030
using namespace sofa::defaulttype;
31-
using namespace core;
3231

3332
template class SOFA_CORE_API Mapping< sofa::defaulttype::Vec1Types, sofa::defaulttype::Vec1Types >;
3433
template class SOFA_CORE_API Mapping< sofa::defaulttype::Vec1Types, sofa::defaulttype::Vec2Types >;

Sofa/framework/Core/src/sofa/core/Mapping.inl

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,12 @@ sofa::linearalgebra::BaseMatrix* Mapping<In,Out>::createMappedMatrix(const behav
135135
template <class In, class Out>
136136
void Mapping<In,Out>::apply(const MechanicalParams* mparams, MultiVecCoordId outPos, ConstMultiVecCoordId inPos)
137137
{
138-
State<In>* fromModel = this->fromModel.get();
139-
State<Out>* toModel = this->toModel.get();
140-
if(fromModel && toModel)
138+
State<In>* from = this->fromModel.get();
139+
State<Out>* to = this->toModel.get();
140+
if(from && to)
141141
{
142-
OutDataVecCoord* out = outPos[toModel].write();
143-
const InDataVecCoord* in = inPos[fromModel].read();
142+
OutDataVecCoord* out = outPos[to].write();
143+
const InDataVecCoord* in = inPos[from].read();
144144
if(out && in)
145145
{
146146
this->apply(mparams, *out, *in);
@@ -151,12 +151,12 @@ void Mapping<In,Out>::apply(const MechanicalParams* mparams, MultiVecCoordId out
151151
template <class In, class Out>
152152
void Mapping<In,Out>::applyJ(const MechanicalParams* mparams, MultiVecDerivId outVel, ConstMultiVecDerivId inVel)
153153
{
154-
State<In>* fromModel = this->fromModel.get();
155-
State<Out>* toModel = this->toModel.get();
156-
if(fromModel && toModel)
154+
State<In>* from = this->fromModel.get();
155+
State<Out>* to = this->toModel.get();
156+
if(from && to)
157157
{
158-
OutDataVecDeriv* out = outVel[toModel].write();
159-
const InDataVecDeriv* in = inVel[fromModel].read();
158+
OutDataVecDeriv* out = outVel[to].write();
159+
const InDataVecDeriv* in = inVel[from].read();
160160
if(out && in)
161161
{
162162
this->applyJ(mparams, *out, *in);
@@ -167,12 +167,12 @@ void Mapping<In,Out>::applyJ(const MechanicalParams* mparams, MultiVecDerivId ou
167167
template <class In, class Out>
168168
void Mapping<In,Out>::applyJT(const MechanicalParams *mparams, MultiVecDerivId inForce, ConstMultiVecDerivId outForce)
169169
{
170-
State<In>* fromModel = this->fromModel.get();
171-
State<Out>* toModel = this->toModel.get();
172-
if(fromModel && toModel)
170+
State<In>* from = this->fromModel.get();
171+
State<Out>* to = this->toModel.get();
172+
if(from && to)
173173
{
174-
InDataVecDeriv* out = inForce[fromModel].write();
175-
const OutDataVecDeriv* in = outForce[toModel].read();
174+
InDataVecDeriv* out = inForce[from].write();
175+
const OutDataVecDeriv* in = outForce[to].read();
176176
if(out && in)
177177
{
178178
this->applyJT(mparams, *out, *in);
@@ -184,12 +184,12 @@ void Mapping<In,Out>::applyJT(const MechanicalParams *mparams, MultiVecDerivId i
184184
template <class In, class Out>
185185
void Mapping<In,Out>::applyJT(const ConstraintParams* cparams, MultiMatrixDerivId inConst, ConstMultiMatrixDerivId outConst )
186186
{
187-
State<In>* fromModel = this->fromModel.get();
188-
State<Out>* toModel = this->toModel.get();
189-
if(fromModel && toModel)
187+
State<In>* from = this->fromModel.get();
188+
State<Out>* to = this->toModel.get();
189+
if(from && to)
190190
{
191-
InDataMatrixDeriv* out = inConst[fromModel].write();
192-
const OutDataMatrixDeriv* in = outConst[toModel].read();
191+
InDataMatrixDeriv* out = inConst[from].write();
192+
const OutDataMatrixDeriv* in = outConst[to].read();
193193
if(out && in)
194194
{
195195
this->applyJT(cparams, *out, *in);
@@ -208,13 +208,13 @@ void Mapping<In,Out>::applyDJT(const MechanicalParams* /*mparams */ , MultiVecDe
208208
template <class In, class Out>
209209
void Mapping<In,Out>::computeAccFromMapping(const MechanicalParams* mparams, MultiVecDerivId outAcc, ConstMultiVecDerivId inVel, ConstMultiVecDerivId inAcc )
210210
{
211-
State<In>* fromModel = this->fromModel.get();
212-
State<Out>* toModel = this->toModel.get();
213-
if(fromModel && toModel)
211+
State<In>* from = this->fromModel.get();
212+
State<Out>* to = this->toModel.get();
213+
if(from && to)
214214
{
215-
OutDataVecDeriv* out = outAcc[toModel].write();
216-
const InDataVecDeriv* inV = inVel[fromModel].read();
217-
const InDataVecDeriv* inA = inAcc[fromModel].read();
215+
OutDataVecDeriv* out = outAcc[to].write();
216+
const InDataVecDeriv* inV = inVel[from].read();
217+
const InDataVecDeriv* inA = inAcc[from].read();
218218
if(out && inV && inA)
219219
this->computeAccFromMapping(mparams, *out, *inV, *inA);
220220
}

Sofa/framework/Core/src/sofa/core/ObjectFactory.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ void ObjectFactory::dump(std::ostream& out)
529529
if (!entry->aliases.empty())
530530
{
531531
out << " aliases :";
532-
for (std::set<std::string>::iterator myit = entry->aliases.begin(), itend = entry->aliases.end(); myit != itend; ++myit)
532+
for (std::set<std::string>::iterator myit = entry->aliases.begin(), aliasesEnd = entry->aliases.end(); myit != aliasesEnd; ++myit)
533533
out << " " << *myit;
534534
out << "\n";
535535
}
@@ -573,7 +573,7 @@ void ObjectFactory::dumpXML(std::ostream& out)
573573
const ClassEntry::SPtr entry = it->second;
574574
if (entry->className != it->first) continue;
575575
out << "<class name=\"" << xmlencode(entry->className) <<"\">\n";
576-
for (std::set<std::string>::iterator myit = entry->aliases.begin(), itend = entry->aliases.end(); myit != itend; ++myit)
576+
for (std::set<std::string>::iterator myit = entry->aliases.begin(), aliasesEnd = entry->aliases.end(); myit != aliasesEnd; ++myit)
577577
out << "<alias>" << xmlencode(*myit) << "</alias>\n";
578578
if (!entry->description.empty())
579579
out << "<description>"<<entry->description<<"</description>\n";
@@ -607,7 +607,7 @@ void ObjectFactory::dumpHTML(std::ostream& out)
607607
if (!entry->aliases.empty())
608608
{
609609
out << "<li>Aliases:<i>";
610-
for (std::set<std::string>::iterator myit = entry->aliases.begin(), itend = entry->aliases.end(); myit != itend; ++myit)
610+
for (std::set<std::string>::iterator myit = entry->aliases.begin(), aliasesEnd = entry->aliases.end(); myit != aliasesEnd; ++myit)
611611
out << " " << xmlencode(*myit);
612612
out << "</i></li>\n";
613613
}

Sofa/framework/Core/src/sofa/core/SofaLibrary.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ void SofaLibrary::build( const std::vector< std::string >& examples)
4848
if (creatorEntry != entries[i]->creatorMap.end())
4949
{
5050
const objectmodel::BaseClass* baseClass = creatorEntry->second->getClass();
51-
std::vector<std::string> categories;
52-
CategoryLibrary::getCategories(baseClass, categories);
53-
for (std::vector<std::string>::iterator it = categories.begin(); it != categories.end(); ++it)
51+
std::vector<std::string> categoriesVec;
52+
CategoryLibrary::getCategories(baseClass, categoriesVec);
53+
for (std::vector<std::string>::iterator it = categoriesVec.begin(); it != categoriesVec.end(); ++it)
5454
{
5555
mainCategories.insert((*it));
5656
inventory.insert(std::make_pair((*it), entries[i]));

Sofa/framework/Core/src/sofa/core/behavior/DefaultMultiMatrixAccessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void DefaultMultiMatrixAccessor::clear()
5252
{
5353
globalDim = 0;
5454
for (auto it = realStateOffsets.begin(), itend = realStateOffsets.end(); it != itend; ++it)
55-
it->second = -1;
55+
it->second = static_cast<decltype(it->second)>(-1);
5656

5757
for (std::map< const sofa::core::behavior::BaseMechanicalState*, linearalgebra::BaseMatrix* >::iterator it = mappedMatrices.begin(), itend = mappedMatrices.end(); it != itend; ++it)
5858
if (it->second != nullptr) delete it->second;

Sofa/framework/Core/src/sofa/core/collision/Intersection.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ helper::TypeInfo IntersectorMap::getType(core::CollisionModel* model)
4242
if (it == castMap.end())
4343
{
4444
helper::TypeInfo t2 = t;
45-
for (std::set<const objectmodel::ClassInfo* >::iterator it = classes.begin(); it != classes.end(); ++it)
45+
for (std::set<const objectmodel::ClassInfo* >::iterator ci = classes.begin(); ci != classes.end(); ++ci)
4646
{
47-
if ((*it)->isInstance(model))
47+
if ((*ci)->isInstance(model))
4848
{
49-
t2 = (*it)->type();
49+
t2 = (*ci)->type();
5050
break;
5151
}
5252
}
@@ -76,14 +76,14 @@ ElementIntersector* IntersectorMap::get(core::CollisionModel* model1, core::Coll
7676

7777

7878
std::stringstream tmp;
79-
for(InternalMap::const_iterator it = intersectorsMap.begin(), itEnd = intersectorsMap.end(); it != itEnd; ++it)
79+
for(InternalMap::const_iterator it2 = intersectorsMap.begin(), itEnd = intersectorsMap.end(); it2 != itEnd; ++it2)
8080
{
81-
helper::TypeInfo t1 = it->first.first;
82-
helper::TypeInfo t2 = it->first.second;
81+
helper::TypeInfo t1_tmp = it2->first.first;
82+
helper::TypeInfo t2_tmp = it2->first.second;
8383
tmp << " "
84-
<< gettypename(t1) << "-"
85-
<< gettypename(t2);
86-
const ElementIntersector* i = it->second;
84+
<< gettypename(t1_tmp) << "-"
85+
<< gettypename(t2_tmp);
86+
const ElementIntersector* i = it2->second;
8787
if (!i)
8888
tmp << " nullptr";
8989
else

0 commit comments

Comments
 (0)