Bug 148415 - More detailed, better explained loplugin errors
Summary: More detailed, better explained loplugin errors
Status: ASSIGNED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: framework (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All All
: medium normal
Assignee: Devansh Varshney
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Dev-related
  Show dependency treegraph
 
Reported: 2022-04-06 08:26 UTC by Gabor Kelemen (allotropia)
Modified: 2025-05-07 18:21 UTC (History)
6 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 Gabor Kelemen (allotropia) 2022-04-06 08:26:34 UTC
This is not about LO, but about the clang plugins used by Jenkins.

In many cases the plugins end up giving error messages on a patch, which may be difficult to understand for beginner programmers - or even more experienced ones who do not follow new developments in the clang plugins area.

It came up that it would be better/more educative if ALL these error messages[1] were all uniformly a bit more explanatory:
- Why is some practice considered "wrong"? This may be dug out of git logs, but that's  super inconvenient.
- What should I change to do it correctly, possibly with an example.

Adding experienced devs and TDF mentors to CC. It would be beneficial to review all the plugins and change their error messages to be very descriptive if they are currently not.

[1] Just for examples from builds on top of the list:
https://gerrit.libreoffice.org/c/core/+/132571 writes:
clang plugin redundantcast did trigger. redundant static_cast from "SwParaPortion *" to "SwLinePortion *"
- tells why is this bad, but no explanation on what to do (might be seen as trivial... but that's just an assumption of experienced devs, better to make sure ;) )

https://gerrit.libreoffice.org/c/core/+/130692 writes:
clang plugin fakebool did trigger. use "true" instead of "sal_True" 
- no explanation why is this bad, but tells what to change

https://gerrit.libreoffice.org/c/core/+/132505 writes:
clang plugin stringviewparam did trigger. replace function parameter of type "const rtl::OUString &" with "std::u16string_view"
- no explanation why is this bad, but tells what to change

clang plugin simplifyconstruct did trigger. no need to explicitly init an instance of "::std::unique_ptr<FileChangedChecker>" with nullptr, just use default constructor
- explains why is this bad and what to do instead - excellent!
Comment 1 Aron Budea 2022-06-04 06:32:17 UTC
Seems reasonable, setting to NEW.
Comment 2 QA Administrators 2024-06-04 03:14:31 UTC Comment hidden (obsolete)
Comment 3 Devansh Varshney 2025-05-07 12:51:27 UTC
(In reply to Gabor Kelemen (allotropia) from comment #0)

> clang plugin simplifyconstruct did trigger. no need to explicitly init an
> instance of "::std::unique_ptr<FileChangedChecker>" with nullptr, just use
> default constructor
> - explains why is this bad and what to do instead - excellent!

This is what I got when I was working on https://gerrit.libreoffice.org/c/core/+/163924/24 (tdf#132007)

hence for the aDoc URL I have to follow loplugin:stringviewparam, which recommend replacing const rtl::OUString& parameters with std::u16string_view to promote non-owning views and avoid unnecessary copies at the call site. 


PasswordDialog::PasswordDialog(weld::Window* pParent,
    task::PasswordRequestMode nDialogMode, const std::locale& rResLocale,
    const std::u16string_view aDocURL, bool bIsSimplePasswordRequest)


And this bug makes sense as at that time I thought that document URL is not going to change hence I made the change, but now Michael in the comments while reviewing raised question that the subsequent internal conversion from `std::u16string_view` back to a local `rtl::OUString`.

If the `stringviewparam` message had briefly mentioned the benefits of `string_view` (e.g., "to avoid potential copies at call site and promote non-owning views for API parameters"), it would have been immediately clearer.

It also made me wonder if this check is consistently applied or if its enforcement has become more stringent recently, as I noticed other recent changes to the same file (`passworddlg.cxx`) didn't seem to trigger similar discussions, though perhaps their parameters were different or didn't meet the plugin's trigger conditions?

This seems like a valid enhancement and since I faced this, now feel the need of improving these messages. I would like to work on this :)
Comment 4 Devansh Varshney 2025-05-07 18:21:09 UTC
https://cgit.freedesktop.org/libreoffice/core/tree/compilerplugins/clang

Goal: Enhance the diagnostic messages emitted by loplugin.

Current State: As the bug notes, many messages tell you what to change (e.g., "replace const rtl::OUString & with std::u16string_view") but not why it's better or the rationale behind the rule. Some are better (like simplifyconstruct).

Desired State: Messages should ideally include:

- The specific issue detected (e.g., "loplugin:stringviewparam did trigger").

- A clear instruction on what code change is needed (e.g., "replace function parameter of type 'const rtl::OUString &' with 'std::u16string_view'").

- A concise explanation of why this change is recommended (e.g., "...to avoid potential copies at call site and promote non-owning views for API parameters.").

- (Optional but helpful): A minimal "Before -> After" code snippet example if the change isn't trivial.