Skip to content

Commit afeaa62

Browse files
author
Matthew Gretton-Dann
committed
C++: Improve Template Value docs.
1 parent 809d97d commit afeaa62

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

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

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,26 +193,53 @@ abstract class Declaration extends Locatable, @declaration {
193193

194194
/**
195195
* Gets a template argument used to instantiate this declaration from a template.
196-
* When called on a template, this will return a template parameter.
196+
* When called on a template, this will return a template parameter type for
197+
* both typed and non-typed parameters.
197198
*/
198199
final Type getATemplateArgument() { result = getTemplateArgument(_) }
199200

200201
/**
201202
* Gets a template argument used to instantiate this declaration from a template.
202-
* When called on a template, this will return a template parameter value.
203+
* When called on a template, this will return a non-typed template
204+
* parameter value.
203205
*/
204206
final Expr getATemplateArgumentValue() { result = getTemplateArgumentValue(_) }
205207

206208
/**
207209
* Gets the `i`th template argument used to instantiate this declaration from a
208-
* template. When called on a template, this will return the `i`th template parameter.
210+
* template. When called on a template, this will return the `i`th template
211+
* parameter's type.
212+
*
213+
* For example:
214+
*
215+
* `template<typename T, T X> class Foo;`
216+
*
217+
* Will have `getTemplateArgument(0)` return `T`, and
218+
* `getTemplateArgument(1)` return `T`.
219+
*
220+
* `Foo<int, 1> bar;
221+
*
222+
* Will have `getTemplateArgument())` return `int`, and
223+
* `getTemplateArgument(1)` return `int`.
209224
*/
210225
Type getTemplateArgument(int index) { none() }
211226

212227
/**
213228
* Gets the `i`th template argument value used to instantiate this declaration
214229
* from a template. When called on a template, this will return the `i`th template
215230
* parameter value if it exists.
231+
*
232+
* For example:
233+
*
234+
* `template<typename T, T X> class Foo;`
235+
*
236+
* Will have `getTemplateArgumentValue(1)` return `X`, and no result for
237+
* `getTemplateArgumentValue(0)`.
238+
*
239+
* `Foo<int, 10> bar;
240+
*
241+
* Will have `getTemplateArgumentValue(1)` return `10`, and no result for
242+
* `getTemplateArgumentValue(0)`.
216243
*/
217244
Expr getTemplateArgumentValue(int index) { none() }
218245

0 commit comments

Comments
 (0)