Mantis Bug Tracker Workflow

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0030448Community[OCCT] OCCT:Foundation Classespublic2019-01-18 16:432019-01-18 16:44
Assigned Toabv 
PlatformAOSLOS VersionL
Product Version[OCCT] 7.3.0 
Target Version[OCCT] 7.4.0*Fixed in Version 
Summary0030448: Add Typo Detection to Derivation Creation Methods
DescriptionThere are a lot of methods for modifying an object OR creating a derivation of an already existing object (especially in gp) and they all have the same naming pattern.

For example gp_Vec has method Reversed(). Since this method is pure (it is const and has no side-effects), its return value should never be discarded.

Because of the naming pattern the modification method's name is VERY similar to the derivation creation method's name (Reverse() and Reversed()). If someone wants to revert a vector and mistakenly calls vector.Reversed() instead of vector.Reverse(), he has introduced a subtle bug. A reverted vector is returned, but then discarded and the original vector remains unaltered.

From C++ 17 on there is the possibility to add a [[nodiscard]] attribute to a return value to flag that it should be used. If the Reversed() method would have been flagged like that, the error could easily be detected.

I have suffered from such an error, therefore I want to ask whether this change is welcome? It has a disadvantage: for preventing compilation errors and warnings from older compilers, the attribute needs to be surrounded by lengthy code. It would look like this:

  //! Reverses the direction of a vector
#ifdef __has_cpp_attribute
#if __has_cpp_attribute(nodiscard)
    gp_Vec Reversed() const;
  gp_Vec operator -() const
  return Reversed();

What is your opinion?
TagsNo tags attached.
Test case number
Attached Files

- Relationships

-  Notes
There are no notes attached to this issue.

- Issue History
Date Modified Username Field Change
2019-01-18 16:43 BenjaminBihler New Issue
2019-01-18 16:43 BenjaminBihler Assigned To => abv
2019-01-18 16:44 BenjaminBihler Status new => feedback

Copyright © 2000 - 2019 MantisBT Team
Powered by Mantis Bugtracker