Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Can't understand this warning

50 views
Skip to first unread message

Ian Collins

unread,
Apr 27, 2017, 4:43:01 PM4/27/17
to
On 04/28/17 08:09 AM, Stefan Ram wrote:
> I tried to make all of my functions out-of-line, yet I still
> get the warning. Why? And what can I do to get rid of the
> warning?
>
> #include <initializer_list>
> #include <iostream>
> #include <memory>
> #include <ostream>
>
> struct B
> { void n() const;
> virtual void v() const ;
> virtual ~B(); };
>
> void ::B::n() const { ::std::cerr << "::B::n\n"; }
> void ::B::v() const { ::std::cerr << "::B::v\n"; }
> B::~B() = default;
>
> struct D : public B
> { void n() const;
> void v() const override;
> ~D() override; };
>
> void ::D::n() const { ::std::cerr << "::D::n\n"; }
> void ::D::v() const { ::std::cerr << "::D::v\n"; }
> D::~D() = default;
>
> int main()
> { ::D const d;
> ::B const * b = &d;
> b->n();
> b->v(); ::std::cerr << '\n';
> d.n();
> d.v(); ::std::cerr << '\n';
> b->::B::n();
> b->::B::v(); ::std::cerr << '\n';
> d.::D::n();
> d.::D::v(); ::std::cerr << '\n'; }
>
> main.cpp:6:8: warning: 'B' has no out-of-line virtual method definitions; its vtable will be emitted in every translation unit [clang-diagnostic-weak-vtables]
> struct B
> ^
>
> main.cpp:15:8: warning: 'D' has no out-of-line virtual method definitions; its vtable will be emitted in every translation unit [clang-diagnostic-weak-vtables]
> struct D : public B
> ^

Compiler bug?

--
Ian

Scott Lurndal

unread,
Apr 28, 2017, 8:42:01 AM4/28/17
to
r...@zedat.fu-berlin.de (Stefan Ram) writes:
> Distribution through any means other than regular usenet
>
> channels is forbidden. It is forbidden to publish this
>
> article in the world wide web. It is forbidden to change
>
> URIs of this article into links. It is forbidden to remove
>
> this notice or to transfer the body without this notice.
>X-No-Archive: Yes
>Archive: no
>X-No-Archive-Readme: "X-No-Archive" is only set, because this prevents some
>
> services to mirror the article via the web (HTTP). But Stefan Ram
>
> hereby allows to keep this article within a Usenet archive server
>
> with only NNTP access without any time limitation.
>X-No-Html: yes
>Content-Language: en
>X-Received-Body-CRC: 4167814981
>X-Received-Bytes: 2654
>
> I tried to make all of my functions out-of-line, yet I still
> get the warning. Why? And what can I do to get rid of the
> warning?

First hit on a google search explains the warning message and its
associated cause quite clearly.

Marcel Mueller

unread,
Apr 28, 2017, 1:15:46 PM4/28/17
to
On 27.04.17 22.09, Stefan Ram wrote:
> main.cpp:6:8: warning: 'B' has no out-of-line virtual method definitions; its vtable will be emitted in every translation unit [clang-diagnostic-weak-vtables]
> struct B

Some compilers have the quirk to create the vtable for a polymorphic
class only by the compilation unit which implements the first virtual
function rather than by every compilation unit with weak symbols. This
does not work if there is no such function.


Marcel
0 new messages