Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e647dc3

Browse files
zlaski-semmlegeoffw0
authored andcommitted
[CPP-418] Fill in examples for ErroneousType, UnknownType, and
assorted complex/imaginary arithmetic operations.
1 parent 09f538a commit e647dc3

2 files changed

Lines changed: 64 additions & 7 deletions

File tree

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,13 @@ class BuiltInType extends Type, @builtintype {
311311

312312
/**
313313
* An erroneous type. This type has no corresponding C/C++ syntax.
314+
*
315+
* ErroneousType is the type of ErrorExpr, which it turn refers to an illegal
316+
* language construct. In the example below, a temporary (`0`) cannot be bound
317+
* to an lvalue reference (`int &`):
318+
* ```
319+
* int &intref = 0;
320+
* ```
314321
*/
315322
class ErroneousType extends BuiltInType {
316323
ErroneousType() { builtintypes(underlyingElement(this), _, 1, _, _, _) }
@@ -320,6 +327,16 @@ class ErroneousType extends BuiltInType {
320327

321328
/**
322329
* The unknown type. This type has no corresponding C/C++ syntax.
330+
*
331+
* Unknown types usually occur inside _uninstantiated_ template functions.
332+
* In the example below, the type of the ternary `?:` expression cannot
333+
* be determined:
334+
* ```
335+
* template <typename T>
336+
* T min(T x, T y) {
337+
* return (x < y) ? x : y;
338+
* }
339+
* ```
323340
*/
324341
class UnknownType extends BuiltInType {
325342
UnknownType() { builtintypes(underlyingElement(this), _, 2, _, _, _) }

cpp/ql/src/semmle/code/cpp/exprs/ArithmeticOperation.qll

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class UnaryPlusExpr extends UnaryArithmeticOperation, @unaryplusexpr {
4141
* functions.
4242
* ```
4343
* _Complex double a = ( 1.0, 2.0 );
44-
* b = ~ a; // ( 1,0, - 2.0 )
44+
* _Complex double b = ~ a; // ( 1,0, - 2.0 )
4545
* ```
4646
*/
4747
class ConjugationExpr extends UnaryArithmeticOperation, @conjugation {
@@ -273,7 +273,13 @@ class RemExpr extends BinaryArithmeticOperation, @remexpr {
273273
}
274274

275275
/**
276-
* A C/C++ multiply expression with an imaginary number.
276+
* A C/C++ multiply expression with an imaginary number. This is specific to
277+
* C99 and later.
278+
* ```
279+
* double z;
280+
* _Imaginary double x, y;
281+
* z = x * y;
282+
* ```
277283
*/
278284
class ImaginaryMulExpr extends BinaryArithmeticOperation, @jmulexpr {
279285
override string getOperator() { result = "*" }
@@ -286,7 +292,13 @@ class ImaginaryMulExpr extends BinaryArithmeticOperation, @jmulexpr {
286292
}
287293

288294
/**
289-
* A C/C++ divide expression with an imaginary number.
295+
* A C/C++ divide expression with an imaginary number. This is specific to
296+
* C99 and later.
297+
* ```
298+
* double z;
299+
* _Imaginary double y;
300+
* z = z / y;
301+
* ```
290302
*/
291303
class ImaginaryDivExpr extends BinaryArithmeticOperation, @jdivexpr {
292304
override string getOperator() { result = "/" }
@@ -299,7 +311,14 @@ class ImaginaryDivExpr extends BinaryArithmeticOperation, @jdivexpr {
299311
}
300312

301313
/**
302-
* A C/C++ add expression with a real term and an imaginary term.
314+
* A C/C++ add expression with a real term and an imaginary term. This is
315+
* specific to C99 and later.
316+
* ```
317+
* double z;
318+
* _Imaginary double x;
319+
* _Complex double w;
320+
* w = z + x;
321+
* ```
303322
*/
304323
class RealImaginaryAddExpr extends BinaryArithmeticOperation, @fjaddexpr {
305324
override string getOperator() { result = "+" }
@@ -312,7 +331,14 @@ class RealImaginaryAddExpr extends BinaryArithmeticOperation, @fjaddexpr {
312331
}
313332

314333
/**
315-
* A C/C++ add expression with an imaginary term and a real term.
334+
* A C/C++ add expression with an imaginary term and a real term. This is
335+
* specific to C99 and later.
336+
* ```
337+
* double z;
338+
* _Imaginary double x;
339+
* _Complex double w;
340+
* w = x + z;
341+
* ```
316342
*/
317343
class ImaginaryRealAddExpr extends BinaryArithmeticOperation, @jfaddexpr {
318344
override string getOperator() { result = "+" }
@@ -325,7 +351,14 @@ class ImaginaryRealAddExpr extends BinaryArithmeticOperation, @jfaddexpr {
325351
}
326352

327353
/**
328-
* A C/C++ subtract expression with a real term and an imaginary term.
354+
* A C/C++ subtract expression with a real term and an imaginary term. This is
355+
* specific to C99 and later.
356+
* ```
357+
* double z;
358+
* _Imaginary double x;
359+
* _Complex double w;
360+
* w = z - x;
361+
* ```
329362
*/
330363
class RealImaginarySubExpr extends BinaryArithmeticOperation, @fjsubexpr {
331364
override string getOperator() { result = "-" }
@@ -338,7 +371,14 @@ class RealImaginarySubExpr extends BinaryArithmeticOperation, @fjsubexpr {
338371
}
339372

340373
/**
341-
* A C/C++ subtract expression with an imaginary term and a real term.
374+
* A C/C++ subtract expression with an imaginary term and a real term. This is
375+
* specific to C99 and later.
376+
* ```
377+
* double z;
378+
* _Imaginary double x;
379+
* _Complex double w;
380+
* w = x - z;
381+
* ```
342382
*/
343383
class ImaginaryRealSubExpr extends BinaryArithmeticOperation, @jfsubexpr {
344384
override string getOperator() { result = "-" }

0 commit comments

Comments
 (0)