C++: Expose trailing return type presence.

This commit is contained in:
Alexandre Boulgakov
2021-08-10 17:54:56 +01:00
parent d658ef1dcd
commit 490498899b
6 changed files with 20 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
lgtm,codescanning
* Added `Function.hasTrailingReturnType` predicate to check whether a function was declared with a trailing return type.

View File

@@ -151,6 +151,20 @@ class Function extends Declaration, ControlFlowNode, AccessHolder, @function {
*/
predicate isNaked() { getAnAttribute().hasName("naked") }
/**
* Holds if this function has a trailing return type.
*
* Note that this is true whether or not deduction took place. For example,
* this holds for both `e` and `f`, but not `g` or `h`:
* ```
* auto e() -> int { return 0; }
* auto f() -> auto { return 0; }
* auto g() { return 0; }
* int h() { return 0; }
* ```
*/
predicate hasTrailingReturnType() { this.hasSpecifier("has_trailing_return_type") }
/** Gets the return type of this function. */
Type getType() { function_return_type(underlyingElement(this), unresolveElement(result)) }

View File

@@ -97,6 +97,7 @@
| file://:0:0:0:0 | forceinline |
| file://:0:0:0:0 | fp_offset |
| file://:0:0:0:0 | gp_offset |
| file://:0:0:0:0 | has_trailing_return_type |
| file://:0:0:0:0 | implicit_int |
| file://:0:0:0:0 | inline |
| file://:0:0:0:0 | int |

View File

@@ -68,6 +68,7 @@
| file://:0:0:0:0 | forceinline |
| file://:0:0:0:0 | fp_offset |
| file://:0:0:0:0 | gp_offset |
| file://:0:0:0:0 | has_trailing_return_type |
| file://:0:0:0:0 | implicit_int |
| file://:0:0:0:0 | initializer for <error> |
| file://:0:0:0:0 | inline |

View File

@@ -129,6 +129,7 @@
| file://:0:0:0:0 | gp_offset |
| file://:0:0:0:0 | grammar_helper_base & |
| file://:0:0:0:0 | grammar_helper_base && |
| file://:0:0:0:0 | has_trailing_return_type |
| file://:0:0:0:0 | implicit_int |
| file://:0:0:0:0 | inline |
| file://:0:0:0:0 | int |

View File

@@ -59,6 +59,7 @@
| file://:0:0:0:0 | forceinline | Other |
| file://:0:0:0:0 | fp_offset | Other |
| file://:0:0:0:0 | gp_offset | Other |
| file://:0:0:0:0 | has_trailing_return_type | Other |
| file://:0:0:0:0 | implicit_int | Other |
| file://:0:0:0:0 | inline | Other |
| file://:0:0:0:0 | int | Other |