Details
-
Suggestion
-
Resolution: Invalid
-
Not Evaluated
-
None
-
None
-
None
Description
Suppose I have code like this:
class A { public: void setI(int newI) {i = newI;} private: int i; } class B { private: A exampleMember; }
If I then right click on exampleMember and select "generate getter and setter member functions" the signature of the getter will look like this:
A getExampleMember() const;
I think it should look like this:
A const getExampleMember() const;
There's no reason I can think of that you'd want the returned value to be mutable in this case and occasionally people(especially people coming from languages like java and ruby where everything is a pointer) will accidentally do something like this:
B badIdea; badIdea.getExampleMember().setI(10);
This wouldn't apply to getters that return primitives/pointers/references of course since that will have no effect on the generated code and result in compiler warnings.
Attachments
For Gerrit Dashboard: QTCREATORBUG-9413 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
57722,2 | CppEditor: GenerateGetterSetter return objects as const | 2.8 | qt-creator/qt-creator | Status: ABANDONED | -2 | 0 |