Skip to content

Commit b20961a

Browse files
committed
C++: Expose constant expressions as attribute arguments
1 parent 553f1c4 commit b20961a

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

cpp/ql/lib/semmle/code/cpp/Specifier.qll

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,11 @@ class AttributeArgument extends Element, @attribute_arg {
258258
* Gets the text for the value of this argument, if its value is
259259
* a constant or token.
260260
*/
261-
string getValueText() { attribute_arg_value(underlyingElement(this), result) }
261+
string getValueText() {
262+
if underlyingElement(this) instanceof @attribute_arg_constant_expr
263+
then result = this.getValueConstant().getValue()
264+
else attribute_arg_value(underlyingElement(this), result)
265+
}
262266

263267
/**
264268
* Gets the value of this argument, if its value is integral.
@@ -270,6 +274,13 @@ class AttributeArgument extends Element, @attribute_arg {
270274
*/
271275
Type getValueType() { attribute_arg_type(underlyingElement(this), unresolveElement(result)) }
272276

277+
/**
278+
* Gets the value of this argument, if its value is a constant.
279+
*/
280+
Expr getValueConstant() {
281+
attribute_arg_constant(underlyingElement(this), unresolveElement(result))
282+
}
283+
273284
/**
274285
* Gets the attribute to which this is an argument.
275286
*/
@@ -294,7 +305,10 @@ class AttributeArgument extends Element, @attribute_arg {
294305
(
295306
if underlyingElement(this) instanceof @attribute_arg_type
296307
then tail = this.getValueType().getName()
297-
else tail = this.getValueText()
308+
else
309+
if underlyingElement(this) instanceof @attribute_arg_constant_expr
310+
then tail = this.getValueConstant().toString()
311+
else tail = this.getValueText()
298312
) and
299313
result = prefix + tail
300314
)

0 commit comments

Comments
 (0)