Fix build warnings (found with gcc -Wall)

This commit is contained in:
Matthias Hochsteger 2024-12-03 13:05:33 +01:00
parent 0c1943c77b
commit 3bfa6c19fa
18 changed files with 68 additions and 65 deletions

View File

@ -842,6 +842,9 @@ namespace ngcore
NETGEN_INLINE void NothingToDelete ()
{
mem_to_delete = nullptr;
// this memory is not managed by the Array anymore, so set the memory usage to 0
mt.Free(sizeof(T)*allocsize);
}
/// Change logical size. If necessary, do reallocation. Keeps contents.

View File

@ -1211,7 +1211,7 @@ namespace netgen
PrintMessage (2, "Object ", i, " has ", tams->GetNT(), " triangles");
}
}
catch (exception)
catch (const std::exception &)
{
cerr << "*************************************************************" << endl
<< "**** out of memory problem in CSG visualization ****" << endl

View File

@ -109,7 +109,7 @@ namespace netgen
{
void * p = new char [(line.maxsize+5) * elsize];
if (line.maxsize*elsize)
if (line.maxsize && elsize)
memcpy (p, line.col, line.maxsize * elsize);
delete [] (char*)line.col;

View File

@ -1041,7 +1041,7 @@ namespace netgen
build_searchtree);
return ind - 1;
}
catch(NgException e) // quads not implemented curved yet
catch(const NgException & e) // quads not implemented curved yet
{
for (SegmentIndex si = 0; si < mesh->GetNSeg(); si++)
{

View File

@ -301,7 +301,7 @@ namespace netgen
in >> name;
cout << IM(3) << len << " element are in group " << name << endl;
int hi, index;
int fdnr, ednr;
int fdnr=-1, ednr=-1;
in >> hi >> index >> hi >> hi;
int codim = get<1>(element_map[index]);
@ -712,7 +712,7 @@ namespace netgen
if(!UserFormatRegister::HaveFormat(format))
throw Exception("Unknown format: " + format);
const auto & entry = UserFormatRegister::Get(format);
const auto entry = UserFormatRegister::Get(format);
if(!entry.read)
throw Exception("Reading format " + format + " is not implemented");

View File

@ -53,8 +53,8 @@ void ReadMeditFormat (Mesh & mesh, const filesystem::path & filename, map<tuple<
for([[maybe_unused]] auto k : Range(nvert)) {
for(auto i : Range(dim))
fin >> p[i];
fin >> index;
mesh.AddPoint(p);
fin >> index;
mesh.AddPoint(p);
}
}
else if(token == "Edges") {
@ -64,10 +64,10 @@ void ReadMeditFormat (Mesh & mesh, const filesystem::path & filename, map<tuple<
for([[maybe_unused]] auto k : Range(nedge)) {
for(auto i : Range(2))
fin >> seg[i];
fin >> seg.edgenr;
seg.edgenr = getIndex(1, seg.edgenr);
seg.si = seg.edgenr;
mesh.AddSegment(seg);
fin >> seg.edgenr;
seg.edgenr = getIndex(1, seg.edgenr);
seg.si = seg.edgenr;
mesh.AddSegment(seg);
}
}
else if(token == "Triangles") {
@ -77,9 +77,9 @@ void ReadMeditFormat (Mesh & mesh, const filesystem::path & filename, map<tuple<
for([[maybe_unused]] auto k : Range(ntrig)) {
for(auto i : Range(3))
fin >> sel[i];
fin >> index;
sel.SetIndex(getIndex(2, index));
mesh.AddSurfaceElement(sel);
fin >> index;
sel.SetIndex(getIndex(2, index));
mesh.AddSurfaceElement(sel);
}
}
else if(token == "Tetrahedra") {
@ -89,10 +89,10 @@ void ReadMeditFormat (Mesh & mesh, const filesystem::path & filename, map<tuple<
for([[maybe_unused]] auto k : Range(ntet)) {
for(auto i : Range(4))
fin >> el[i];
fin >> index;
el.SetIndex(getIndex(3, index));
el.Invert();
mesh.AddVolumeElement(el);
fin >> index;
el.SetIndex(getIndex(3, index));
el.Invert();
mesh.AddVolumeElement(el);
}
}
else if(token == "Corners") {

View File

@ -39,7 +39,7 @@ bool WriteUserFormat (const string & format,
if(!UserFormatRegister::HaveFormat(format))
return true;
const auto & entry = UserFormatRegister::Get(format);
const auto entry = UserFormatRegister::Get(format);
if(!entry.write)
return true;

View File

@ -49,7 +49,7 @@ namespace netgen
{
data = NULL; height = width = 0;
SetSize (m2.Height(), m2.Width());
if (Height()*Width())
if (Height() && Width())
memcpy (data, m2.data, sizeof(double) * (Height() * Width()));
}
@ -70,7 +70,7 @@ namespace netgen
delete[] data;
if (h*w)
if (h && w)
data = new double[h*w];
else
data = NULL;

View File

@ -788,9 +788,9 @@ namespace netgen
if(fabs(mat.Det()) > 1e-6)
break;
}
int maxpos1;
int maxpos2;
double val = 0;
int maxpos1 = 0;
int maxpos2 = 1;
double val = ns[0] * ns[1];
for (auto i : Range(ns))
{
for (auto j : Range(i + 1, ns.Size()))

View File

@ -1066,7 +1066,8 @@ double MeshOptimize3d :: SwapImproveEdge (
bad3 += GetLegalPenalty();
}
bool swap2, swap3;
bool swap2=false;
bool swap3=false;
if (goal == OPT_CONFORM)
{
@ -2608,7 +2609,7 @@ double MeshOptimize3d :: SplitImprove2Element (
// search for very flat tets, with two disjoint edges nearly crossing, like a rectangle with diagonals
int minedge = -1;
double mindist = 1e99;
double minlam0, minlam1;
double minlam0=0, minlam1=0;
for (int i : Range(3))
{

View File

@ -196,8 +196,8 @@ namespace netgen
auto& el = mesh.SurfaceElement(velement);
if(el.GetType() == TRIG)
{
double seg_lam;
double lam;
double seg_lam=-1;
double lam=-1;
auto seg = mesh.LineSegment(segs[i]);
for(auto k : Range(3))
{

View File

@ -396,8 +396,8 @@ namespace netgen
for (int i = 1; i <= mesh.GetNOpenElements(); i++)
md.meshing->AddBoundaryElement (mesh.OpenElement(i));
if (mp.delaunay && mesh.GetNOpenElements())
{
if (mp.delaunay && mesh.GetNOpenElements())
{
int oldne = mesh.GetNE();
md.meshing->Delaunay (mesh, domain, mp);
@ -408,22 +408,22 @@ namespace netgen
PrintMessage (3, mesh.GetNP(), " points, ",
mesh.GetNE(), " elements");
mesh.FindOpenElements(domain);
}
}
Box<3> domain_bbox( Box<3>::EMPTY_BOX );
Box<3> domain_bbox( Box<3>::EMPTY_BOX );
for (auto & sel : mesh.SurfaceElements())
for (auto & sel : mesh.SurfaceElements())
{
if (sel.IsDeleted() ) continue;
for (auto pi : sel.PNums())
domain_bbox.Add (mesh[pi]);
}
domain_bbox.Increase (0.01 * domain_bbox.Diam());
domain_bbox.Increase (0.01 * domain_bbox.Diam());
int cntsteps = 0;
int meshed;
if (mesh.GetNOpenElements())
int cntsteps = 0;
int meshed;
if (mesh.GetNOpenElements())
do
{
if (multithread.terminate)
@ -515,24 +515,22 @@ namespace netgen
PrintMessage (1, "Success !");
}
}
while (!meshed);
while (!meshed);
{
PrintMessage (3, "Check subdomain ", domain, " / ", mesh.GetNDomains());
PrintMessage (3, "Check subdomain ", domain, " / ", mesh.GetNDomains());
mesh.FindOpenElements(domain);
mesh.FindOpenElements(domain);
bool res = (mesh.CheckConsistentBoundary() != 0);
if (res)
{
if(debugparam.write_mesh_on_error)
md.mesh->Save("inconsistent_surface_domain_"+ToString(md.domain)+".vol.gz");
PrintError ("Surface mesh not consistent");
throw NgException ("Stop meshing since surface mesh not consistent");
}
}
RemoveIllegalElements (mesh, domain);
ConformToFreeSegments (mesh, domain);
bool res = (mesh.CheckConsistentBoundary() != 0);
if (res)
{
if(debugparam.write_mesh_on_error)
md.mesh->Save("inconsistent_surface_domain_"+ToString(md.domain)+".vol.gz");
PrintError ("Surface mesh not consistent");
throw NgException ("Stop meshing since surface mesh not consistent");
}
RemoveIllegalElements (mesh, domain);
ConformToFreeSegments (mesh, domain);
}
void MergeMeshes( Mesh & mesh, Array<MeshingData> & md )

View File

@ -175,7 +175,8 @@ namespace netgen
}
constexpr PointIndex (t_invalid inv) : i(PointIndex::BASE-1) { ; }
// PointIndex & operator= (const PointIndex &ai) { i = ai.i; return *this; }
constexpr operator int () const { return i; }
constexpr operator const int& () const { return i; }
explicit constexpr operator int& () { return i; }
PointIndex operator++ (int) { PointIndex hi(*this); i++; return hi; }
PointIndex operator-- (int) { PointIndex hi(*this); i--; return hi; }
PointIndex & operator++ () { i++; return *this; }

View File

@ -267,7 +267,7 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
.def(py::init<int>())
.def("__repr__", &ToString<PointIndex>)
.def("__str__", &ToString<PointIndex>)
.def_property_readonly("nr", &PointIndex::operator int)
.def_property_readonly("nr", &PointIndex::operator const int&)
.def("__eq__" , FunctionPointer( [](PointIndex &self, PointIndex &other)
{ return static_cast<int>(self)==static_cast<int>(other); }) )
.def("__hash__" , FunctionPointer( [](PointIndex &self ) { return static_cast<int>(self); }) )

View File

@ -224,7 +224,7 @@ NGCORE_API_EXPORT void ExportSTL(py::module & m)
.def("GetVicinity", [] (shared_ptr<STLGeometry> self, int node, int size, string type) {
NgArray<int> vic;
int trig;
int trig=-1;
if(type == "trig")
trig = node;

View File

@ -266,7 +266,7 @@ namespace netgen
}
catch (bad_weak_ptr e)
catch (const bad_weak_ptr & e)
{
// cout << "don't have a mesh to visualize" << endl;
VisualScene::DrawScene();
@ -895,7 +895,7 @@ namespace netgen
vstimestamp = meshtimestamp;
}
catch (bad_weak_ptr e)
catch (const bad_weak_ptr & e)
{
PrintMessage (3, "vsmesh::buildscene: don't have a mesh to visualize");
VisualScene::BuildScene (zoomall);

View File

@ -641,7 +641,7 @@ namespace netgen
// delete lock;
// mem_lock.UnLock();
}
catch (bad_weak_ptr e)
catch (const bad_weak_ptr & e)
{
// cout << "don't have a mesh to visualize" << endl;
VisualScene::DrawScene();
@ -1120,7 +1120,7 @@ namespace netgen
clipplanetimestamp = max2 (vispar.clipping.timestamp, solutiontimestamp);
}
catch (bad_weak_ptr e)
catch (const bad_weak_ptr & e)
{
PrintMessage (3, "vssolution::buildscene: don't have a mesh to visualize");
VisualScene::BuildScene (zoomall);

View File

@ -194,7 +194,7 @@ namespace netgen
if(mesh->GetGeometry())
ng_geometry = mesh->GetGeometry();
}
catch (NgException e)
catch (const NgException & e)
{
PrintMessage (3, e.What());
return TCL_ERROR;
@ -269,7 +269,7 @@ namespace netgen
geometry -> LoadSurfaces(infile);
}
}
catch (NgException e)
catch (const NgException & e)
{
PrintMessage (3, e.What());
return TCL_ERROR;
@ -551,7 +551,7 @@ namespace netgen
}
}
catch (NgException e)
catch (const NgException & e)
{
Tcl_SetResult (interp, const_cast<char*> (e.What().c_str()), TCL_VOLATILE);
return TCL_ERROR;
@ -582,7 +582,7 @@ namespace netgen
{
ng_geometry -> Save (string (cfilename));
}
catch (NgException e)
catch (const NgException & e)
{
Tcl_SetResult (interp, const_cast<char*> (e.What().c_str()), TCL_VOLATILE);
return TCL_ERROR;
@ -1440,7 +1440,7 @@ namespace netgen
PrintMessage (1, "Meshing done, time = ", GetTime(), " sec");
}
catch (NgException e)
catch (const NgException & e)
{
cout << e.What() << endl;
}