Skip to content

Commit 06accfe

Browse files
author
Matthew Gretton-Dann
committed
C++: Add support for the spaceship operator
1 parent c5b3df1 commit 06accfe

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,3 +1216,18 @@ private predicate constantTemplateLiteral(Expr e) {
12161216
or
12171217
constantTemplateLiteral(e.(Cast).getExpr())
12181218
}
1219+
1220+
/**
1221+
* A C++ three-way comparison operation, also known as the _spaceship
1222+
* operation_. This is specific to C++20 and later.
1223+
* ```
1224+
* auto c = (a <=> b);
1225+
* ```
1226+
*/
1227+
class SpaceshipExpr extends BinaryOperation, @spaceshipexpr {
1228+
override string getCanonicalQLClass() { result = "SpaceshipExpr" }
1229+
1230+
override int getPrecedence() { result = 11 }
1231+
1232+
override string getOperator() { result = "<=>" }
1233+
}

cpp/ql/src/semmlecode.cpp.dbscheme

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,7 @@ funbind(
12311231
| @ltexpr
12321232
| @geexpr
12331233
| @leexpr
1234+
| @spaceshipexpr
12341235
;
12351236

12361237
@bin_bitwise_op_expr = @lshiftexpr
@@ -1636,6 +1637,7 @@ case @expr.kind of
16361637
| 323 = @vec_fill
16371638
| 324 = @builtinconvertvector
16381639
| 325 = @builtincomplex
1640+
| 326 = @spaceshipexpr
16391641
;
16401642

16411643
new_allocated_type(

0 commit comments

Comments
 (0)