s/method/function/g since function is the correct name in C++.

llvm-svn: 354704
This commit is contained in:
Rui Ueyama 2019-02-22 23:59:51 +00:00
parent c94dad9d97
commit 81c0880c99
1 changed files with 12 additions and 12 deletions

View File

@ -7,20 +7,20 @@ If your build failed with a linker error something like this::
the vtable symbol may be undefined because the class is missing its key function (see https://lld.llvm.org/missingkeyfunction) the vtable symbol may be undefined because the class is missing its key function (see https://lld.llvm.org/missingkeyfunction)
it's likely that your class C has a key function (defined by the ABI as the first it's likely that your class C has a key function (defined by the ABI as the first
non-pure, non-inline, virtual method), but you haven't actually defined it. non-pure, non-inline, virtual function), but you haven't actually defined it.
When a class has a key function, the compiler emits the vtable (and some other When a class has a key function, the compiler emits the vtable (and some other
things as well) only in the translation unit that defines that key function. Thus, things as well) only in the translation unit that defines that key function. Thus,
if you're missing the key function, you'll also be missing the vtable. If no other if you're missing the key function, you'll also be missing the vtable. If no other
function calls your missing method, you won't see any undefined reference errors function calls your missing function, you won't see any undefined reference errors
for it, but you will see undefined references to the vtable symbol. for it, but you will see undefined references to the vtable symbol.
When a class has no non-pure, non-inline, virtual methods, there is no key When a class has no non-pure, non-inline, virtual functions, there is no key
method, and the compiler is forced to emit the vtable in every translation unit function, and the compiler is forced to emit the vtable in every translation unit
that references the class. In this case, it is emitted in a COMDAT section, that references the class. In this case, it is emitted in a COMDAT section,
which allows the linker to eliminate all duplicate copies. This is still which allows the linker to eliminate all duplicate copies. This is still
wasteful in terms of object file size and link time, so it's always advisable to wasteful in terms of object file size and link time, so it's always advisable to
ensure there is at least one eligible method that can serve as the key function. ensure there is at least one eligible function that can serve as the key function.
Here are the most common mistakes that lead to this error: Here are the most common mistakes that lead to this error:
@ -36,8 +36,8 @@ Say you have a base class declared in a header file::
... ...
}; };
Here, ``~B`` is the first non-pure, non-inline, virtual method, so it is the key Here, ``~B`` is the first non-pure, non-inline, virtual function, so it is the key
method. If you forget to define ``B::~B`` in your source file, the compiler will function. If you forget to define ``B::~B`` in your source file, the compiler will
not emit the vtable for ``B``, and you'll get an undefined reference to "vtable not emit the vtable for ``B``, and you'll get an undefined reference to "vtable
for B". for B".
@ -47,9 +47,9 @@ the first eligible key function and it's easy to forget to implement them. It's
also more likely that you won't have any direct references to the destructor, so also more likely that you won't have any direct references to the destructor, so
you won't see any undefined reference errors that point directly to the problem. you won't see any undefined reference errors that point directly to the problem.
The solution in this case is to implement the missing method. The solution in this case is to implement the missing function.
Forgetting to declare a virtual method in an abstract class as pure Forgetting to declare a virtual function in an abstract class as pure
------------------------------------------------------------------- -------------------------------------------------------------------
Say you have an abstract base class declared in a header file:: Say you have an abstract base class declared in a header file::
@ -65,18 +65,18 @@ Say you have an abstract base class declared in a header file::
}; };
This base class is intended to be abstract, but you forgot to mark one of the This base class is intended to be abstract, but you forgot to mark one of the
methods pure. Here, ``A::bar``, being non-pure, is nominated as the key function, functions pure. Here, ``A::bar``, being non-pure, is nominated as the key function,
and as a result, the vtable for ``A`` is not emitted, because the compiler is and as a result, the vtable for ``A`` is not emitted, because the compiler is
waiting for a translation unit that defines ``A::bar``. waiting for a translation unit that defines ``A::bar``.
The solution in this case is to add the missing ``= 0`` to the declaration of The solution in this case is to add the missing ``= 0`` to the declaration of
``A::bar``. ``A::bar``.
Key method is defined, but the linker doesn't see it Key function is defined, but the linker doesn't see it
---------------------------------------------------- ----------------------------------------------------
It's also possible that you have defined the key function somewhere, but the It's also possible that you have defined the key function somewhere, but the
object file containing the definition of that method isn't being linked into object file containing the definition of that function isn't being linked into
your application. your application.
The solution in this case is to check your dependencies to make sure that The solution in this case is to check your dependencies to make sure that