|Anonymous | Login||2019-02-19 19:52 MSK|
|My View | View Issues | Change Log | Roadmap|
|View Issue Details|
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0030448||Community||[OCCT] OCCT:Foundation Classes||public||2019-01-18 16:43||2019-01-18 16:44|
|Product Version||[OCCT] 7.3.0|
|Target Version||[OCCT] 7.4.0*||Fixed in Version|
|Summary||0030448: Add Typo Detection to Derivation Creation Methods|
|Description||There 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
gp_Vec Reversed() const;
gp_Vec operator -() const
What is your opinion?
|Tags||No tags attached.|
|Test case number|
|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|