Bug 90341 - Clean up excessive const_cast'ing
Summary: Clean up excessive const_cast'ing
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All All
: medium enhancement
Assignee: Not Assigned
URL:
Whiteboard: target:7.0.0 target:7.4.0 target:24.2...
Keywords: difficultyMedium, easyHack, skillCpp, topicCleanup
Depends on:
Blocks: Dev-related
  Show dependency treegraph
 
Reported: 2015-03-30 06:50 UTC by Stephan Bergmann
Modified: 2024-10-23 13:15 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stephan Bergmann 2015-03-30 06:50:04 UTC
Find C++ source files that need a suspiciously high amount of const_cast, then see if some of them are due to poor design that can be improved (by e.g. making relevant member functions const, making relevant member variables mutable, making relevant variables pointer to non-const).

(You can use something like

> git grep --word-regexp --count const_cast | sort --numeric-sort --key=2 --field-separator=:

to get the high-scorers of const_cast usage.)
Comment 1 Robinson Tryon (qubit) 2015-12-10 11:40:55 UTC Comment hidden (obsolete)
Comment 2 Commit Notification 2016-01-06 13:36:46 UTC
Takeshi Abe committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=4ae319ae462f3f094452046e392c8c15446736ae

tdf#90341 Clean up excessive const_cast'ing

It will be available in 5.2.0.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 3 Robinson Tryon (qubit) 2016-02-18 14:52:26 UTC Comment hidden (obsolete)
Comment 4 jani 2016-08-05 09:19:45 UTC
Please be aware, that this easyhack is considered an important but large scale cosmetic change as described in https://wiki.documentfoundation.org/Development/LargeScaleChanges

It was in decided by the ESC to close this kind of easyhacks, and send them directly as mail, to new contributors.
https://lists.freedesktop.org/archives/libreoffice/2016-August/074920.html

Please do not submit patches with many files !!

This easyhacks should/will be opened, when we have a window to do largescale changes.
Comment 5 Xisco Faulí 2016-09-27 10:36:09 UTC Comment hidden (obsolete)
Comment 6 mesutcfc 2020-05-05 14:53:23 UTC
Hi Stephan. I tried fix this issue but jenkins says something went wrong. 
This is my patch : https://gerrit.libreoffice.org/c/core/+/93472
And this is error:

"error "binding value of type "const DbGridControl" to reference to type "DbGridControl" drops "const" qualifier" triggered in included file /home/tdf/lode/jenkins/workspace/lo_gerrit/Config/linux_clang_dbgutil_64/svx/source/inc/gridcell.hxx:136:46"

1)I can remove this const keyword 
gridcell.hxx:136
DbGridControl& GetParent() const {return m_rParent;}

2)Or i can ignore changes that i made before and only I can change this function.

std::unique_ptr<DbGridColumn> DbGridControl::CreateColumn(sal_uInt16 nId) const
{
    return std::unique_ptr<DbGridColumn>(new DbGridColumn(nId, *const_cast<DbGridControl*>(this)));
}

with this

std::unique_ptr<DbGridColumn> DbGridControl::CreateColumn(sal_uInt16 nId)
{
    return std::unique_ptr<DbGridColumn>(new DbGridColumn(nId, *this));
}

But i'm confused. What the logic in here? One of these ways is right? İf right. Which and why? I am really curious? Can you help me?
Comment 7 Stephan Bergmann 2020-05-05 15:10:42 UTC
(In reply to mesutcfc from comment #6)
> This is my patch : https://gerrit.libreoffice.org/c/core/+/93472

lets continue the discussion at <https://gerrit.libreoffice.org/c/core/+/93472/1#message-2d85da9e66f43cbdd85e8fd4ff56a9645ce9c3f0>
Comment 8 Commit Notification 2020-05-05 20:15:02 UTC
Mesut Çifci committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/7b152167a4e4c3eaac95aee8f282873681c90092

tdf90341  Clean up excessive const_cast'ing

It will be available in 7.0.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 9 Commit Notification 2022-01-25 18:55:20 UTC
VaibhavMalik4187 committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/d1207a5f3a573dbe39a7874931ce373e5c88628d

tdf#90341 Clean Up Excessive const_cast'ing

It will be available in 7.4.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 10 Harshita Nag 2022-11-20 15:40:33 UTC
Hi, 
I have contributed to few easy hacks and after that I am working on this hack.
I have found a file source/font/font.cxx and there are const_casts done in a couple of functions, 
I also have a way to check my changes in the locally built version of libreoffice by running make, but I am confused how can I know whether these const_casts are important or not without having to build? 
Any help would be really appreciated. 
Thanks!
Comment 11 Stephan Bergmann 2022-11-21 08:04:35 UTC
(In reply to Harshita Nag from comment #10)
> I also have a way to check my changes in the locally built version of
> libreoffice by running make, but I am confused how can I know whether these
> const_casts are important or not without having to build? 

I don't understand the above.  The idea here is to come up with some working change (which thus succeeds `make`) that avoids some const_cast(s).  But anyway, probably easier to follow up on any questions you still have if you turn your work into a Gerrit change and add me as a reviewer there.
Comment 12 Siddharth Khattar 2023-01-15 23:18:23 UTC
Hello all,

This is my second easy hack that I'm doing for LibreOffice. I've tried to do a couple of code submissions for this easy hack but unfortunately, they're failing in the build test. You can view them at: https://gerrit.libreoffice.org/c/core/+/144374

Unfortunately, I'm not at all familiar with the OUString class in LibreOffice and am new to open-source development as a whole. Please tell me what the errors mean really that are coming up in the failed build tests and what can I do to solve them.
Also, is there any documentation for the code that is written for these code files so that beginners can figure out what they are supposed to do? Are there any mentors or someone who can help guide me to solve this easy hack?
Comment 13 Commit Notification 2023-09-13 04:31:48 UTC
sahil committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/bf81be2641e8c66d78374289497b117fe3dfb024

tdf#90341 Clean up excessive const_cast'ing

It will be available in 24.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 14 Commit Notification 2024-01-17 13:34:13 UTC
Adam Seskunas committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/07059f3336f0daea15c0574a67bd99986eccedd3

tdf#90341 Clean up excessive const_cast'ing

It will be available in 24.8.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 15 Commit Notification 2024-10-23 13:15:58 UTC
Usman Akinyemi committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/ad6f39b19c8853c1e8f71a32f88d4656029e4005

tdf#90341 Clean up excessive const_cast'ing

It will be available in 25.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.