Skip to content

Commit 4904988

Browse files
committed
C++: Expose trailing return type presence.
1 parent d658ef1 commit 4904988

File tree

6 files changed

+20
-0
lines changed

6 files changed

+20
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lgtm,codescanning
2+
* Added `Function.hasTrailingReturnType` predicate to check whether a function was declared with a trailing return type.

cpp/ql/src/semmle/code/cpp/Function.qll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,20 @@ class Function extends Declaration, ControlFlowNode, AccessHolder, @function {
151151
*/
152152
predicate isNaked() { getAnAttribute().hasName("naked") }
153153

154+
/**
155+
* Holds if this function has a trailing return type.
156+
*
157+
* Note that this is true whether or not deduction took place. For example,
158+
* this holds for both `e` and `f`, but not `g` or `h`:
159+
* ```
160+
* auto e() -> int { return 0; }
161+
* auto f() -> auto { return 0; }
162+
* auto g() { return 0; }
163+
* int h() { return 0; }
164+
* ```
165+
*/
166+
predicate hasTrailingReturnType() { this.hasSpecifier("has_trailing_return_type") }
167+
154168
/** Gets the return type of this function. */
155169
Type getType() { function_return_type(underlyingElement(this), unresolveElement(result)) }
156170

cpp/ql/test/library-tests/clang_ms/element.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
| file://:0:0:0:0 | forceinline |
9898
| file://:0:0:0:0 | fp_offset |
9999
| file://:0:0:0:0 | gp_offset |
100+
| file://:0:0:0:0 | has_trailing_return_type |
100101
| file://:0:0:0:0 | implicit_int |
101102
| file://:0:0:0:0 | inline |
102103
| file://:0:0:0:0 | int |

cpp/ql/test/library-tests/conditions/elements.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
| file://:0:0:0:0 | forceinline |
6969
| file://:0:0:0:0 | fp_offset |
7070
| file://:0:0:0:0 | gp_offset |
71+
| file://:0:0:0:0 | has_trailing_return_type |
7172
| file://:0:0:0:0 | implicit_int |
7273
| file://:0:0:0:0 | initializer for <error> |
7374
| file://:0:0:0:0 | inline |

cpp/ql/test/library-tests/templates/instantiations_functions/elements.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
| file://:0:0:0:0 | gp_offset |
130130
| file://:0:0:0:0 | grammar_helper_base & |
131131
| file://:0:0:0:0 | grammar_helper_base && |
132+
| file://:0:0:0:0 | has_trailing_return_type |
132133
| file://:0:0:0:0 | implicit_int |
133134
| file://:0:0:0:0 | inline |
134135
| file://:0:0:0:0 | int |

cpp/ql/test/library-tests/unnamed/elements.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
| file://:0:0:0:0 | forceinline | Other |
6060
| file://:0:0:0:0 | fp_offset | Other |
6161
| file://:0:0:0:0 | gp_offset | Other |
62+
| file://:0:0:0:0 | has_trailing_return_type | Other |
6263
| file://:0:0:0:0 | implicit_int | Other |
6364
| file://:0:0:0:0 | inline | Other |
6465
| file://:0:0:0:0 | int | Other |

0 commit comments

Comments
 (0)