Please use GitHub pull requests for new patches. Phabricator shutdown timeline
Differential D80514 Diff 279625 clang-tools-extra/docs/clang-tidy/checks/modernize-use-trailing-return-type.rst
Changeset View
Changeset View
Standalone View
Standalone View
clang-tools-extra/docs/clang-tidy/checks/modernize-use-trailing-return-type.rst
Show All 20 Lines | |||||
.. code-block:: c++ | .. code-block:: c++ | ||||
auto f1() -> int; | auto f1() -> int; | ||||
inline auto f2(int arg) -> int noexcept; | inline auto f2(int arg) -> int noexcept; | ||||
virtual auto f3() const && -> float = delete; | virtual auto f3() const && -> float = delete; | ||||
Known Limitations | Known Limitations | ||||
----------------- | ----------------- | ||||
bernhardmgruber: I tried 2 online rst editors and they failed to format the code blocks inside the tables. Will… | |||||
In other documentation such examples are sequential. Same below. Eugene.Zelenko: In other documentation such examples are sequential. Same below. | |||||
Ok! I will separate the code blocks again. bernhardmgruber: Ok! I will separate the code blocks again. | |||||
The following categories of return types cannot be rewritten currently: | The following categories of return types cannot be rewritten currently: | ||||
* function pointers | * function pointers | ||||
* member function pointers | * member function pointers | ||||
* member pointers | * member pointers | ||||
* decltype, when it is the top level expression | |||||
Unqualified names in the return type might erroneously refer to different entities after the rewrite. | Unqualified names in the return type might erroneously refer to different entities after the rewrite. | ||||
Preventing such errors requires a full lookup of all unqualified names present in the return type in the scope of the trailing return type location. | Preventing such errors requires a full lookup of all unqualified names present in the return type in the scope of the trailing return type location. | ||||
This location includes e.g. function parameter names and members of the enclosing class (including all inherited classes). | This location includes e.g. function parameter names and members of the enclosing class (including all inherited classes). | ||||
Such a lookup is currently not implemented. | Such a lookup is currently not implemented. | ||||
Given the following piece of code | Given the following piece of code | ||||
.. code-block:: c++ | .. code-block:: c++ | ||||
struct Object { long long value; }; | struct S { long long value; }; | ||||
Object f(unsigned Object) { return {Object * 2}; } | S f(unsigned S) { return {S * 2}; } | ||||
class CC { | class CC { | ||||
int Object; | int S; | ||||
struct Object m(); | struct S m(); | ||||
}; | }; | ||||
Object CC::m() { return {0}; } | S CC::m() { return {0}; } | ||||
a careless rewrite would produce the following output: | a careless rewrite would produce the following output: | ||||
.. code-block:: c++ | .. code-block:: c++ | ||||
struct Object { long long value; }; | struct S { long long value; }; | ||||
auto f(unsigned Object) -> Object { return {Object * 2}; } // error | auto f(unsigned S) -> S { return {S * 2}; } // error | ||||
class CC { | class CC { | ||||
int Object; | int S; | ||||
auto m() -> struct Object; | auto m() -> struct S; | ||||
}; | }; | ||||
auto CC::m() -> Object { return {0}; } // error | auto CC::m() -> S { return {0}; } // error | ||||
This code fails to compile because the Object in the context of f refers to the equally named function parameter. | This code fails to compile because the S in the context of f refers to the equally named function parameter. | ||||
Similarly, the Object in the context of m refers to the equally named class member. | Similarly, the S in the context of m refers to the equally named class member. | ||||
The check can currently only detect a clash with a function parameter name. | The check can currently only detect and avoid a clash with a function parameter name. |
I tried 2 online rst editors and they failed to format the code blocks inside the tables. Will this work with the clang documentation?