Skip to content

[clang-tidy] performance-noexcept-move-constructor do not handle conditional noexcept properly #126702

@Nechda

Description

@Nechda

Hi!

It seems that this issue has been discussed in #68101 and partially resolved. The problem is now observed in clang version 19.1.0 and possibly in the trunk as well.

To summarize, I have an external class that does not have a noexcept move constructor. When I try to mark the move constructor for my class using type traits, the check fails.

Previously, a workaround solved the case where the class in question had a template parameter. This allowed the check to allow the use of type traits with noexcept. Maybe the check should only be triggered when the user explicitly specifies noexcept(false)?

#include <type_traits>

/* External class */
struct NotMarkedNoexcept {
    int x;
    NotMarkedNoexcept() = default;
    // NOLINTNEXTLINE(performance-noexcept-move-constructor)
    NotMarkedNoexcept(NotMarkedNoexcept&& rhs);
};

struct Complicated {
    static constexpr bool NOEXCEPT_MOVE = std::is_nothrow_move_constructible_v<NotMarkedNoexcept>;

    Complicated() = default;
    Complicated(Complicated&&) noexcept(NOEXCEPT_MOVE) = default; // Warning

    NotMarkedNoexcept inner;
};

int main() {}
[<source>:14:41: warning: noexcept specifier on the move constructor evaluates to 'false' [performance-noexcept-move-constructor]](javascript:;)
   14 |     Complicated(Complicated&&) noexcept(NOEXCEPT_MOVE) = default; // Warning
      |                                         ^
1 warning generated.
Suppressed 1 warnings (1 NOLINT).

https://godbolt.org/z/E4E65jdhh

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions