[umbrello] [Bug 442134] "const" correctness in Umbrello sources

Robert Hairgrove bugzilla_noreply at kde.org
Thu Sep 9 10:36:27 BST 2021


https://bugs.kde.org/show_bug.cgi?id=442134

--- Comment #3 from Robert Hairgrove <code at roberthairgrove.com> ---
(In reply to Oliver Kellogg from comment #1)
> Thanks for making the attachment, it is helpful.
> 
> Minor point:
> > File: codedocument.h
> > virtual QString getUniqueTag(const QString& prefix = QString()); // const
> 
> This one can't be made const due to a side effect this the function body,
> 
> QString CodeDocument::getUniqueTag (const QString& prefix) const
> {
>     [...]
>     m_lastTagIndex = number;   
> 
> The compiler reports
> "assignment of member ‘CodeDocument::m_lastTagIndex’ in read-only object".

Thank you, Oliver!

As I replied in the umbrello-devel user group (but under another email address,
sorry about that), one could declare "CodeDocument::m_lastTagIndex"
mutable...this would be the easiest way to fix the compilation error.

However, from looking at the implementation code, it appears that this member
merely implements some kind of sequence number used to generate the new tag.
Shouldn't this rather be made a static member, or have a static
"generateSequence()" function? Unless there is only one singleton instance of
CodeDocument objects, the danger of having duplicate values seems very real
here, because each derived instance will have its own copy of the member.

Also, the function is declared virtual ... what if a derived class overrides it
and thus cannot update the private member of the base class?

I suppose this could be avoided if each class were required to have its own
unique prefix which is prepended to the number, but I'm not sure where this is
enforced.

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the umbrello-devel mailing list