Skip to content

[clang-tidy] false positive for misc-redundant-expression with fold-expression #110089

@schenker

Description

@schenker

In some cases, clang-tidy reports a false-positive misc-redundant-expression for fold expressions that contain the same value more than once (https://godbolt.org/z/YfThnE9Wh):

#include <type_traits>

template<typename... Args>
constexpr bool all_true = (... && Args::value);
constexpr bool result = all_true<std::true_type, std::true_type, std::true_type>;

Output:

<source>:4:28: warning: both sides of operator are equivalent [misc-redundant-expression]
    4 | constexpr bool all_true = (... && Args::value);
      |           

Strictly speaking the warning is correct, but I would not expect clang-tidy to complain here.

When all_true is implemented as a function, clang-tidy does not report anything:

#include <type_traits>

template<typename... Args>
constexpr bool all_true() {
    return (... && Args::value);
}

constexpr bool result = all_true<std::true_type, std::true_type, std::true_type>();

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions