[llvm-bugs] [Bug 36644] New: -Woverloaded-virtual shouldn't warn for final functions

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Mar 8 01:35:17 PST 2018


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

            Bug ID: 36644
           Summary: -Woverloaded-virtual shouldn't warn for final
                    functions
           Product: clang
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: benni.buch at gmail.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

struct A{
    virtual void f(int){}
};

struct B: A{
    virtual void f(double){}

    void f(int v)final{
        f(static_cast< double >(v));
    }
};

struct C: B{
    virtual void f(char){}

    void f(double v)final{
        f(static_cast< char >(v));
    }
};


The intent of the warning is to catch errors where you intended to override a
virtual function but made an error in the function type. final virtual
functions can't be overridden, so it shouldn't warn about it, but:


$ clang++ -c -Woverloaded-virtual -c main.cpp
main.cpp:14:18: warning: 'C::f' hides overloaded virtual function
[-Woverloaded-virtual]
    virtual void f(char){}
                 ^
main.cpp:8:10: note: hidden overloaded virtual function 'B::f' declared here:
type mismatch at 1st parameter ('int' vs 'char')
    void f(int v)final{
         ^
1 warning generated.

$ clang++ --version
clang version 6.0.0 (http://llvm.org/git/clang.git
4a005620928c39874a0177ec97d84e636ab8dbfc) (http://llvm.org/git/llvm.git
e9667680470d3c40c51ff887fd33c2a91a07d62f)                                       
Target: x86_64-unknown-linux-gnu                                                
Thread model: posix                                                             
InstalledDir: /home/bebuch/media/programme/llvm/bin


The intent in the structure above it to convert a parameter of a virtual
function to another type and call a new virtual function with same name but new
type which can be overridden in a derived class. final makes clear that the
original virtual functions should not be overridden in derived classes anymore.

-- 
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/20180308/14d36b42/attachment.html>


More information about the llvm-bugs mailing list