[llvm-bugs] [Bug 45066] New: spurious insuppressible conversion warning

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Feb 29 15:13:05 PST 2020


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

            Bug ID: 45066
           Summary: spurious insuppressible conversion warning
           Product: clang
           Version: 9.0
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: stsp2 at yandex.ru
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

#include <iostream>

struct D;
struct B {
    virtual operator D() = 0;
};
struct D : B
{
    operator D() override { std::cout << "conv" << std::endl; return D(); }
};
.
int main()
{
    D obj;
    B& br = obj;
    (D)br; // calls D::operator D() through virtual dispatch
    return 0;
}

$ clang++ -Wall -o vconv vconv.cpp
vconv.cpp:9:5: warning: conversion function converting 'D' to itself will never
be used
    operator D() override { std::cout << "conv" << std::endl; return D(); }
    ^
1 warning generated.

$ ./vconv 
conv


The example above shows that the warning
is spurious. Converting to the same type
will indeed never use the conversion
operator. But the above case converts
from B to D, so the warning does not apply.
It may be quite difficult to check properly,
but in this particular example the "override"
keyword is a clear hint that it is going
to be used via the virtual dispatch.

Note that with gcc it is at least possible
to suppress that warning with -Wno-class-conversion.
But in clang it is persistent.

-- 
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/20200229/6411fd14/attachment.html>


More information about the llvm-bugs mailing list