<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Oct 1, 2014 at 3:11 AM, Douglas Gregor <span dir="ltr"><<a href="mailto:dgregor@apple.com" target="_blank">dgregor@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span><br>
> On Sep 30, 2014, at 2:58 PM, Reid Kleckner <<a href="mailto:rnk@google.com" target="_blank">rnk@google.com</a>> wrote:<br>
><br>
> +cc clang-tidy people, since they rolled this kind of stuff out already.<br>
><br>
> Index: test/Parser/cxx0x-in-cxx98.cpp<br>
> ===================================================================<br>
> --- test/Parser/cxx0x-in-cxx98.cpp    (revision 218519)<br>
> +++ test/Parser/cxx0x-in-cxx98.cpp    (working copy)<br>
> @@ -10,11 +10,12 @@<br>
><br>
>  struct B {<br>
>    virtual void f();<br>
> -  virtual void g();<br>
> +  virtual void g(); // expected-note {{overridden virtual function is here}}<br>
>  };<br>
>  struct D final : B { // expected-warning {{'final' keyword is a C++11 extension}}<br>
>    virtual void f() override; // expected-warning {{'override' keyword is a C++11 extension}}<br>
> -  virtual void g() final; // expected-warning {{'final' keyword is a C++11 extension}}<br>
> +  virtual void g() final; // expected-warning {{'final' keyword is a C++11 extension}} \<br>
> +                       // expected-warning {{'g' overrides a member function but is not marked 'override'}}<br>
>  };<br>
><br>
>  void NewBracedInitList() {<br>
><br>
> Should we really be suggesting that users add C++11 features like override when -Wcxx98-compat is on? That seems undesirable.<br>
<br>
</span>To get this warning, the user will already have written ‘override’, demonstrating that they don’t care about -Wcxx98-compat warnings at all. I suspect there isn’t a real use case here.<br>
<span><br>
><br>
> Index: test/Parser/cxx0x-decl.cpp<br>
> ===================================================================<br>
> --- test/Parser/cxx0x-decl.cpp        (revision 218519)<br>
> +++ test/Parser/cxx0x-decl.cpp        (working copy)<br>
> @@ -83,13 +83,13 @@<br>
><br>
>  namespace FinalOverride {<br>
>    struct Base {<br>
> -    virtual void *f();<br>
> +    virtual void *f(); // expected-note {{overridden virtual function is here}}<br>
>      virtual void *g();<br>
>      virtual void *h();<br>
>      virtual void *i();<br>
>    };<br>
>    struct Derived : Base {<br>
> -    virtual auto f() -> void *final;<br>
> +    virtual auto f() -> void *final; // expected-warning {{'f' overrides a member function but is not marked 'override'}}<br>
>      virtual auto g() -> void *override;<br>
>      virtual auto h() -> void *final override;<br>
>      virtual auto i() -> void *override final;<br>
><br>
> Why make this suggestion? 'override' is redundant in the presence of 'final’,<br>
<br>
</span>That’s not true. “override” says that you’re overriding something from the base class, potentially changing the behavior from what your base class would have provided. “final” says that your own derived classes can’t change the behavior further. Those are separate concerns.<br></blockquote><div><br></div><div>I think we should not warn when a method is declared "final" but not "override". There's not much value in this warning, and it conflicts at least with the <a href="http://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Inheritance">Google C++ Style Guide</a>:</div></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_extra"><div class="gmail_quote"><div><i><span style="font-size:13px;color:rgb(51,51,51);font-family:sans-serif">For clarity, use exactly one of </span><code style="font-size:13px;white-space:nowrap;color:rgb(51,51,51);background-color:rgb(250,250,250)">override</code><span style="font-size:13px;color:rgb(51,51,51);font-family:sans-serif">, </span><code style="font-size:13px;white-space:nowrap;color:rgb(51,51,51);background-color:rgb(250,250,250)">final</code><span style="font-size:13px;color:rgb(51,51,51);font-family:sans-serif">, or </span><code style="font-size:13px;white-space:nowrap;color:rgb(51,51,51);background-color:rgb(250,250,250)">virtual</code><span style="font-size:13px;color:rgb(51,51,51);font-family:sans-serif"> when declaring an override.</span></i> </div></div></div></blockquote><div class="gmail_extra"><div class="gmail_quote"><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<span><br>
> assuming that we warn on final virtual methods that don't override anything, which we probably should.<br>
<br>
</span>Sure, that warning would make sense.<br></blockquote><div><br></div><div>This warning would make sense. And it would make it completely useless to warn on "final" methods not marked with "override", as "final" would either imply "override" or it would get a warning.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
        - Doug<br>
<br>
<br>
</blockquote></div><div><br></div><div>-- Alex</div>
</div></div>