[llvm-bugs] [Bug 43598] New: -Wunneeded-internal-declaration warned on needed function

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Oct 7 16:56:55 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=43598

            Bug ID: 43598
           Summary: -Wunneeded-internal-declaration warned on needed
                    function
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: leonardchan at google.com
                CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
                    richard-llvm at metafoo.co.uk

For this code:

```
  1 #include <type_traits>
  2 
  3 namespace {
  4 
  5 // Check if Op is convertible to bool.
  6 template <typename Op>
  7 using enable_relop_t = std::enable_if_t<(std::is_convertible<Op,
bool>::value), bool>;
  8 
  9 // Chek if can do == with T and U.
 10 template <typename T, typename U,
 11          enable_relop_t<decltype(std::declval<T>() == std::declval<U>())> =
true>
 12 constexpr bool is_comparable(T&&, U&&) {
 13   return true;
 14 }
 15 
 16 struct comparable_a {};
 17 
 18 constexpr bool operator==(const comparable_a&, const comparable_a&) {
return true; }
 19 
 20 static_assert(is_comparable(comparable_a{}, comparable_a{}));
 21 
 22 }
```

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)).

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20191007/d856f064/attachment.html>


More information about the llvm-bugs mailing list