DiscussionsIssue archiveOCCT:Foundation Classes

Archived issue #0028355

Stating wrong parent class in DEFINE_STANDARD_RTTIEXT is not recognized during compilation

CommunityOCCT:Foundation Classesclosed31 public notes

Search issues

Description

It is necessary to give always the direct parent class as second argument of the macro. If this is not done correctly, the code compiles, but there are runtime problems with RTTI (like wrong behaviour of IsKind() method).

At least with g++ from version 4.3 on there seems to be a possibility to do a static assert to check the correct base class during compile time.

Steps to reproduce

Not required

Public activity

31 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: Benjamin Bihler
Date: Fri Jan 13 17:40:33 2017 +0100

    0028355: Stating wrong parent class in DEFINE_STANDARD_RTTIEXT is not recognized during compilation
    
    Fixed dubious RTTI definitions.

Author: Benjamin Bihler
Date: Fri Jan 13 17:24:18 2017 +0100

    0028355: Stating wrong parent class in DEFINE_STANDARD_RTTIEXT is not recognized during compilation
    
    Added static_assert for GCC compiler from version 4.3 on.
02Commenter 2
Branch [archived branch] has been updated by Author.

[revision removed]


Detailed log of new commits:

Author: Benjamin Bihler
Date: Mon Jan 16 09:44:25 2017 +0100

    0028355: Stating wrong parent class in DEFINE_STANDARD_RTTIEXT is not recognized during compilation
    
    Improved error message (classes can have more than one direct parent class).

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

[revision removed]


Detailed log of new commits:

Author: Benjamin Bihler
Date: Mon Jan 16 09:49:13 2017 +0100

    0028355: Stating wrong parent class in DEFINE_STANDARD_RTTIEXT is not recognized during compilation
    
    Fixed macro definition for non-GNU-compilers.

04Commenter 2
Branch [archived branch] has been created by Participant.

[revision removed]


Detailed log of new commits:

Author: Benjamin Bihler
Date: Fri Jan 13 19:24:18 2017 +0300

    0028355: Stating wrong parent class in DEFINE_STANDARD_RTTIEXT is not recognized during compilation
    
    Added compile-time check (static_assert) to ensure that classes used in DEFINE_STANDARD_RTTI* macros are actually derived and base class.
    For GCC compiler version 4.3 and later on, check ensures that base is direct.
    
    Fixed dubious RTTI definitions.
05Author
The duplicate is invisible for me. :-(
06Commenter 6
Hello Benjamin,

You do not see the duplicate because it is created inside customer project; this does not make any difference though because the matter is exactly the same, and nothing has been done for that before your fix.

Please have a look at reworked fix in branch CR28355_2: I have added similar check for non-GCC compilers, and revised a bit implementation (moved auxiliar types to namespace "opencascade", added details in error message etc.).

I am now checking that it works under MS VC compilers, and will submit for certification testing as soon as the check is done. If you could check that version in your environment, it would be great.

07Author
G++ compilation fails with "error: a template declaration cannot appear at block scope". Since static assertions are done at compile time there is no reason to put OCC_CHECK_BASE_CLASS inside the get_type_name implementation, is there? Therefore it should be moved outside, then compilation with g++ will succeed.
08Commenter 2
Branch [archived branch] has been updated by Author.

[revision removed]


Detailed log of new commits:

Author: Benjamin Bihler
Date: Mon Jan 16 13:59:42 2017 +0100

    0028355: Stating wrong parent class in DEFINE_STANDARD_RTTIEXT is not recognized during compilation
    
    Fixed compilation with g++.

09Commenter 9
Sorry for delay.. Unfortunately, std::is_base_of<> (used in OCC_CHECK_BASE_CLASS macro for non-GCC) cannot be used inside the class definition (error "class is not completely defined"). This is a reason why I put it inside the function. I see the problem with GCC, will try to fix it in compatible way.
10Author
I see. In one of my first tries I had the same problem. There I put the check into IMPLEMENT_STANDARD_RTTIEXT. Is this an option? (Unfortunately the error message appears not exactly at the position of the problem then, but anyway it's easy to find it.)
11Commenter 2
Branch [archived branch] has been updated by Participant.

[revision removed]


Detailed log of new commits:

Author: abv
Date: Mon Jan 16 20:43:09 2017 +0300

    // correction for non-GCC compilers

12Commenter 2
Branch [archived branch] has been updated by Participant.

[revision removed]


Detailed log of new commits:

Author: abv
Date: Mon Jan 16 22:41:37 2017 +0300

    Added static assert to ensure that first argument of macro DEFINE_STANDARD_RTTI* actually corresponds to current class being defined.

13Commenter 13
Benjamin, putting the check to IMPLEMENT_STANDARD_RTTIEXT is not an option, since we have also fully inlined macro DEFINE_STANDARD_RTTI_INLINE which shall be protected as well for the fix to be completed. The issue with GCC is just that "using" statement for declaring template cannot be used inside function; this can be easily avoided. See the updated branch.

Note that I have added one more assert, to check that the class being defined actually corresponds to the name given as the first argument of the macro.
14Commenter 14
Reviewed with corrections, please test. First, please check compilation on all supported compilers.
15Author
Well done, works nicely here. :-)
16Commenter 16
Dear BugMaster,

Branch CR28355_2 from occt git-repository (and master from products git-repository) was compiled on Linux, MacOS and Windows platforms and tested.
[revision removed]

Number of compiler warnings:
occt component:
   Linux: 0 (0 on master)
   Windows: 0 (0 on master)
   MasOS: 0 (0 on master)
products component:
   Linux: 63
   Windows: 0
   MacOS: 1146

Compilation error has been detected during building of Qt-based OCCT samples on Linux:
http://jenkins-test-07.nnov.opencascade.com/view/CR28355_2-master/job/CR28355_2-master-OCCT-Debian70-64-qt-samples-linux/1/parsed_console/

Regressions/Differences:
Not detected

Testing cases:
Not needed

Testing on Linux:
Total MEMORY difference: 93556163 / 92911266 [+0.69%]
Total CPU difference: 21356.60000000021 / 21506.1200000003 [-0.70%]

Testing on Windows:
Total MEMORY difference: 58650792 / 58649007 [+0.00%]
Total CPU difference: 19417.444469998558 / 19749.742200098677 [-1.68%]
17Commenter 17
Dear Andrey,

Branch [archived branch] has been rejected due to:
- compilation errors
18Commenter 2
Branch [archived branch] has been updated by Participant.

[revision removed]


Detailed log of new commits:

Author: abv
Date: Wed Jan 18 15:19:05 2017 +0300

    RTTI definition is corrected in samples/qt/FuncDemo/src/CircleDriver.h

19Commenter 19
Qt sample is corrected, please check its building (only)
20Commenter 1
21Commenter 2
Branch [archived branch] has been updated by Participant.

[revision removed]


Detailed log of new commits:

Author: abv
Date: Wed Jan 18 18:34:43 2017 +0300

    // use std::tr2::diract_bases only for GCC 4.7+

22Commenter 22
I have corrected version of GCC (std::tr2 namespaces seems to be available only since GCC 4.7, at least it is not present in documentation on GCC 4.6.4, see https://gcc.gnu.org/onlinedocs/gcc-4.6.4/libstdc++/api/namespaces.html).
Please check compilation again.
23Commenter 1
The same platforms:
http://jenkins-test-08.nnov.opencascade.com/view/CR28355_2/view/OCCT%20compile/job/CR28355_2_master-OCCT-CentOS64-64-opt-compile/2/parsed_console/
http://jenkins-test-08.nnov.opencascade.com/view/CR28355_2/view/OCCT%20compile/job/CR28355_2_master-OCCT-Debian60-64-opt-compile/2/parsed_console/

/OCCT/src/SelectMgr/SelectMgr_TriangularFrustum.hxx:95: error: invalid use of template-name 'SelectMgr_Frustum' without an argument list
/OCCT/src/SelectMgr/SelectMgr_TriangularFrustum.hxx:95: error: type/value mismatch at argument 1 in template parameter list for 'template<class T1, class T2, class Dummy> struct opencascade::is_base_but_not_same'
/OCCT/src/SelectMgr/SelectMgr_TriangularFrustum.hxx:95: error: expected a type, got 'SelectMgr_Frustum'
24Commenter 2
Branch [archived branch] has been updated by Participant.

[revision removed]


Detailed log of new commits:

Author: abv
Date: Wed Jan 18 21:26:48 2017 +0300

    // minor correction for GCC 4.4

25Commenter 25
I have pushed the change which I hope will fix the issue. Alas, I cannot check with GCC older than 4.7 (Ubuntu seems not supporting it), but it builds OK with GCC 5.1, CLang 3.6, VS 2010 and 2015. Please re-try.
26Commenter 26
Dear BugMaster,

Branch CR28355_2 from occt git-repository (and master from products git-repository) was compiled on Linux, MacOS and Windows platforms and tested.
[revision removed]

Number of compiler warnings:
occt component:
   Linux: 0 (0 on master)
   Windows: 0 (0 on master)
   MasOS: 0 (0 on master)
products component:
   Linux: 63
   Windows: 0
   MacOS: 1160

Compilation error has been detected during building of Qt-based OCCT samples on Linux:
http://jenkins-test-07.nnov.opencascade.com/view/CR28355_2-master/job/CR28355_2-master-OCCT-Debian70-64-qt-samples-linux/3/parsed_console/
27Commenter 27
Dear Andrey,

Branch [archived branch] has been rejected due to:
- compilation errors
28Commenter 2
Branch [archived branch] has been updated by Participant.

[revision removed]


Detailed log of new commits:

Author: abv
Date: Thu Jan 19 11:38:01 2017 +0300

    // RTTI definitions are corrected in Qt sample FuncDemo

29Commenter 29
Sample building should be corrected now, please check
30Commenter 2
Branch [archived branch] has been deleted by Participant.

[revision removed]
31Commenter 2
Branch [archived branch] has been deleted by Participant.

[revision removed]