LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 23519 - Add clang tidy warning for move constructors and assignments without noexcept
Summary: Add clang tidy warning for move constructors and assignments without noexcept
Status: RESOLVED FIXED
Alias: None
Product: clang-tools-extra
Classification: Unclassified
Component: clang-tidy (show other bugs)
Version: unspecified
Hardware: PC Windows NT
: P enhancement
Assignee: Alexander Kornienko
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-05-13 18:21 PDT by Niall Douglas
Modified: 2017-05-23 11:56 PDT (History)
6 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Niall Douglas 2015-05-13 18:21:02 PDT
Chandler told me to file a feature request adding a clang tidy check giving warnings for when move constructors or assignment operators are not marked noexcept.

I sometimes forget the noexcept. I am sure so do others.

Niall
Comment 1 Alexander Kornienko 2015-05-18 08:03:19 PDT
Looks like an easy one for a new contributor. Patches are welcome! ;)
Comment 2 Chandler Carruth 2015-05-20 23:23:29 PDT
(In reply to comment #1)
> Looks like an easy one for a new contributor. Patches are welcome! ;)

I'd like to ask that this is prioritized. I would very strongly like to have this. If no where else, LLVM could benefit heavily from this when using custom types in data structures.
Comment 3 Alexander Kornienko 2015-05-21 10:09:04 PDT
Should we complain about move constructors declared with noexcept(false), or should this be considered a way to silence the warning?
Comment 4 Niall Douglas 2015-05-21 10:22:05 PDT
(In reply to comment #3)
> Should we complain about move constructors declared with noexcept(false), or
> should this be considered a way to silence the warning?

If it's noexcept(expr) where expr is evaluated to be false then the warning should be issued.

If it's noexcept(false) with a literal false then the warning should not be issued. I would hope there is still a way of suppressing clang tidy warnings in general.

Ideally only types ever used inside STL containers or other places where noexcept move semantics are crucially important should generate these warnings, but I'd prefer a false positive here than no warning at all.

There is also the matter of throw capable code being in a destructor. Under C++ 11 destructors are all default noexcept, and therefore a throw must never reach a destructor edge. A ton of people converting code from C++ 03 fail to adjust their destructors. I'll add another feature request.

Niall
Comment 5 Alexander Kornienko 2015-05-22 05:03:58 PDT
Sent http://reviews.llvm.org/D9933 for review.
Comment 6 Alexander Kornienko 2015-05-27 09:52:15 PDT
The check is there, but no fix-it hints for now.
Comment 7 Anthony Leedom 2016-12-14 22:12:35 PST
Error in the current implementation of this check. The check warns when move constructor/assignment operator is marked noexcept and is explicitly defaulted.
Comment 8 Anthony Leedom 2016-12-14 22:13:49 PST
Error in the current implementation of this check. The check warns when move constructor/assignment operator is marked noexcept and is explicitly defaulted.
Comment 9 Alexander Kornienko 2017-05-16 16:14:44 PDT
Anthony, please file a separate bug with an example and an explanation of why you think this is a wrong behavior.
Comment 10 Anthony Leedom 2017-05-23 11:56:54 PDT
Looks like Bug 24712 fixes this behavior.