Skip to content

-Wunneeded-internal-declaration warned on needed function #42943

@PiJoules

Description

@PiJoules
Bugzilla Link 43598
Version trunk
OS Linux
CC @kamleshbhalui,@zygoloid

Extended Description

For this code:

#include <type_traits>

namespace {

// Check if Op is convertible to bool.
template <typename Op>
using enable_relop_t = std::enable_if_t<(std::is_convertible<Op, bool>::value), bool>;

// Chek if can do == with T and U.
template <typename T, typename U,
         enable_relop_t<decltype(std::declval<T>() == std::declval<U>())> = true>
constexpr bool is_comparable(T&&, U&&) {
  return true;
}

struct comparable_a {};

constexpr bool operator==(const comparable_a&, const comparable_a&) { return true; }

static_assert(is_comparable(comparable_a{}, comparable_a{}));

}

We get this warning on line 18: warning: function 'operator==' is not needed and will not be emitted [-Wunneeded-internal-declaration]. If the function were truly unneeded, I would assume I should just be able to comment out line 18 and everything should still compile, but I would get an error no matching function for call to 'is_comparable' meaning it was used.

Compiled with bin/clang++ ~/misc/test.cpp -c -std=c++17 -Wall from ToT clang.

I'm noticing that this compiles without warnings also if I don't wrap everything in an unnamed namespace or mark operator== with __attrubute__((used)).

Metadata

Metadata

Assignees

Labels

bugzillaIssues migrated from bugzillaclang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerconfirmedVerified by a second partyfalse-positiveWarning fires when it should not

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions