Archived issue #0029164

GCC 7.1 compiler warnings -Wmaybe-uninitialized on gp_XYZ and siblings

Open CASCADEOCCT:Codingclosed8 public notes

Search issues

Description

When OCCT is built with GCC 7.1 compiler (MinGw-64) it reports several warnings -Wmaybe-uninitialized in gp_XYZ and sibling classes.

While location of the problem is not properly reported by compiler, the reason is recognized: this is due to usage of local variables of reference type pointing to field of temporray object, like this:

Handle(Geom_Line) aLine = ...;
const gp_Dir& aDir = aLine->Lin().Direction();

Here Geom_Line::Lin() returns temporary object, and Direction() returns reference to its field. The object gets destroyed immediately (compiler has no knowledge of the fact that the value returned by Direction() is reference to field of that object). Thus aDir points to memory where destroyed object was located and which can be easily corrupted.

Steps to reproduce

Build with GCC 7.1 (MinGW-64)

Public activity

8 archived notes

Participants are labeled by their role within this record.

01Commenter 2
Branch [archived branch] has been created by Author.

[revision removed]


Detailed log of new commits:

Author: Author
Date: Fri Sep 29 18:35:03 2017 +0300

    0029164: GCC 7.1 compiler warnings -Wmaybe-uninitialized in gp_XYZ and siblings
    
    Code is corrected to avoid local variables of reference type pointing to fields of temporary objects.

Author: Commenter 3
Date: Thu Sep 28 21:29:22 2017 +0300

    0029152: Coding Rules - eliminate GCC compiler warnings -Wmisleading-indentation when using MinGW
02Commenter 2
Branch [archived branch] has been updated forcibly by Author.

[revision removed]
03Commenter 2
Branch [archived branch] has been updated forcibly by Author.

[revision removed]
04Commenter 2
Branch [archived branch] has been updated forcibly by Author.

[revision removed]
05Commenter 5
Fix is pushed to CR29164, please review
06Commenter 3
Please test the patch.
07Commenter 1
Tested in framework of testing issue 29170
08Commenter 2
Branch [archived branch] has been deleted by Commenter 3.

[revision removed]