Bug 403088 - function-args-by-value should ignore std::atomic
Summary: function-args-by-value should ignore std::atomic
Status: RESOLVED FIXED
Alias: None
Product: clazy
Classification: Developer tools
Component: general (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Sergio Martins
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-01-11 04:00 UTC by Matthew Woehlke
Modified: 2019-01-16 16:25 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matthew Woehlke 2019-01-11 04:00:03 UTC
SUMMARY
Although std::atomic is correctly considered a "small and trivially-copyable type", passing one by value makes no sense. The only plausible use case for passing a std::atomic is passing by reference. Accordingly, it is always a false positive for clazy to warn about passing std::atomic by reference.

STEPS TO REPRODUCE
1. Run clazy on a function that takes a std::atomic by const reference.

OBSERVED RESULT
Clazy complains that the parameter should be passed by value.

EXPECTED RESULT
Clazy should not complain. (Possibly it should complain about std::atomic that is *not* passed by reference.)

SOFTWARE/OS VERSIONS
clazy: master (75c097b118931e2d8f3a66cc12bf7045ee548e81)
clang: clang-6.0.1-2.fc28
llvm: llvm-6.0.1-8.fc28
Comment 1 Sergio Martins 2019-01-13 21:47:26 UTC
Git commit 1ac59a00dc6886ba6e1259daac8980c92230fc2a by Sergio Martins.
Committed on 13/01/2019 at 21:46.
Pushed by smartins into branch '1.4'.

Don't suggest to pass classes with deleted copy ctor by value

M  +2    -1    src/TypeUtils.cpp
M  +12   -0    tests/function-args-by-value/main.cpp
M  +12   -0    tests/function-args-by-value/main.cpp_fixed.cpp.expected

https://commits.kde.org/clazy/1ac59a00dc6886ba6e1259daac8980c92230fc2a
Comment 2 Matthew Woehlke 2019-01-16 16:25:28 UTC
Oh, wow... I hadn't even thought about std::atomic being non-copyable. Checking for that (since following clazy's advice in such cases will break your code) is indeed a much better fix; thanks!