Skip to content

Commit 0c03935

Browse files
committed
C++: Support __is_aggregate builtin
Fix some whitespace issues while here.
1 parent c4283dd commit 0c03935

File tree

4 files changed

+34
-11
lines changed

4 files changed

+34
-11
lines changed

cpp/ql/lib/semmle/code/cpp/exprs/BuiltInOperations.qll

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class BuiltInOperationHasAssign extends BuiltInOperation, @hasassignexpr {
173173
*
174174
* Returns `true` if the type has a copy constructor.
175175
* ```
176-
* std::integral_constant< bool, __has_copy(_Tp)> hc;
176+
* std::integral_constant<bool, __has_copy(_Tp)> hc;
177177
* ```
178178
*/
179179
class BuiltInOperationHasCopy extends BuiltInOperation, @hascopyexpr {
@@ -189,7 +189,7 @@ class BuiltInOperationHasCopy extends BuiltInOperation, @hascopyexpr {
189189
* Returns `true` if a copy assignment operator has an empty exception
190190
* specification.
191191
* ```
192-
* std::integral_constant< bool, __has_nothrow_assign(_Tp)> hnta;
192+
* std::integral_constant<bool, __has_nothrow_assign(_Tp)> hnta;
193193
* ```
194194
*/
195195
class BuiltInOperationHasNoThrowAssign extends BuiltInOperation, @hasnothrowassign {
@@ -220,7 +220,7 @@ class BuiltInOperationHasNoThrowConstructor extends BuiltInOperation, @hasnothro
220220
*
221221
* Returns `true` if the copy constructor has an empty exception specification.
222222
* ```
223-
* std::integral_constant< bool, __has_nothrow_copy(MyType) >;
223+
* std::integral_constant<bool, __has_nothrow_copy(MyType) >;
224224
* ```
225225
*/
226226
class BuiltInOperationHasNoThrowCopy extends BuiltInOperation, @hasnothrowcopy {
@@ -266,7 +266,7 @@ class BuiltInOperationHasTrivialConstructor extends BuiltInOperation, @hastrivia
266266
*
267267
* Returns true if the type has a trivial copy constructor.
268268
* ```
269-
* std::integral_constant< bool, __has_trivial_copy(MyType) > htc;
269+
* std::integral_constant<bool, __has_trivial_copy(MyType)> htc;
270270
* ```
271271
*/
272272
class BuiltInOperationHasTrivialCopy extends BuiltInOperation, @hastrivialcopy {
@@ -468,7 +468,7 @@ class BuiltInOperationIsUnion extends BuiltInOperation, @isunionexpr {
468468
* ```
469469
* template<typename _Tp1, typename _Tp2>
470470
* struct types_compatible
471-
* : public integral_constant<bool, __builtin_types_compatible_p(_Tp1, _Tp2) >
471+
* : public integral_constant<bool, __builtin_types_compatible_p(_Tp1, _Tp2)>
472472
* { };
473473
* ```
474474
*/
@@ -547,7 +547,7 @@ class BuiltInOperationBuiltInAddressOf extends UnaryOperation, BuiltInOperation,
547547
* ```
548548
* template<typename T, typename... Args>
549549
* struct is_trivially_constructible
550-
* : public integral_constant<bool, __is_trivially_constructible(T, Args...) >
550+
* : public integral_constant<bool, __is_trivially_constructible(T, Args...)>
551551
* { };
552552
* ```
553553
*/
@@ -701,7 +701,7 @@ class BuiltInOperationIsTriviallyCopyable extends BuiltInOperation, @istrivially
701701
*
702702
* ```
703703
* template <typename _Tp>
704-
* std::integral_constant< bool, __is_literal_type(_Tp)> ilt;
704+
* std::integral_constant<bool, __is_literal_type(_Tp)> ilt;
705705
* ```
706706
*/
707707
class BuiltInOperationIsLiteralType extends BuiltInOperation, @isliteraltypeexpr {
@@ -718,7 +718,7 @@ class BuiltInOperationIsLiteralType extends BuiltInOperation, @isliteraltypeexpr
718718
* compiler, with semantics of the `memcpy` operation.
719719
* ```
720720
* template <typename _Tp>
721-
* std::integral_constant< bool, __has_trivial_move_constructor(_Tp)> htmc;
721+
* std::integral_constant<bool, __has_trivial_move_constructor(_Tp)> htmc;
722722
* ```
723723
*/
724724
class BuiltInOperationHasTrivialMoveConstructor extends BuiltInOperation,
@@ -736,7 +736,7 @@ class BuiltInOperationHasTrivialMoveConstructor extends BuiltInOperation,
736736
* ```
737737
* template<typename T>
738738
* struct has_trivial_move_assign
739-
* : public integral_constant<bool, __has_trivial_move_assign(T) >
739+
* : public integral_constant<bool, __has_trivial_move_assign(T)>
740740
* { };
741741
* ```
742742
*/
@@ -771,7 +771,7 @@ class BuiltInOperationHasNothrowMoveAssign extends BuiltInOperation, @hasnothrow
771771
* ```
772772
* template<typename T, typename... Args>
773773
* struct is_constructible
774-
* : public integral_constant<bool, __is_constructible(T, Args...) >
774+
* : public integral_constant<bool, __is_constructible(T, Args...)>
775775
* { };
776776
* ```
777777
*/
@@ -935,7 +935,7 @@ class BuiltInOperationIsValueClass extends BuiltInOperation, @isvalueclassexpr {
935935
* ```
936936
* template<typename T>
937937
* struct is_final
938-
* : public integral_constant<bool, __is_final(T) >
938+
* : public integral_constant<bool, __is_final(T)>
939939
* { };
940940
* ```
941941
*/
@@ -991,3 +991,17 @@ class BuiltInComplexOperation extends BuiltInOperation, @builtincomplex {
991991
/** Gets the operand corresponding to the imaginary part of the complex number. */
992992
Expr getImaginaryOperand() { this.hasChild(result, 1) }
993993
}
994+
995+
/**
996+
* A C++ `__is_aggregate` built-in operation (used by some implementations of the
997+
* `<type_traits>` header).
998+
*
999+
* Returns `true` if the type has is an aggregate type.
1000+
* ```
1001+
* std::integral_constant<bool, __is_aggregate(_Tp)> ia;
1002+
* ``` */
1003+
class BuiltInOperationIsAggregate extends BuiltInOperation, @isaggregate {
1004+
override string toString() { result = "__is_aggregate" }
1005+
1006+
override string getAPrimaryQlClass() { result = "BuiltInOperationIsAggregate" }
1007+
}

cpp/ql/lib/semmlecode.cpp.dbscheme

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,6 +1651,7 @@ case @expr.kind of
16511651
| 328 = @co_yield
16521652
| 329 = @temp_init
16531653
| 330 = @isassignable
1654+
| 331 = @isaggregate
16541655
;
16551656

16561657
@var_args_expr = @vastartexpr
@@ -1713,6 +1714,7 @@ case @expr.kind of
17131714
| @builtinchooseexpr
17141715
| @builtincomplex
17151716
| @isassignable
1717+
| @isaggregate
17161718
;
17171719

17181720
new_allocated_type(

cpp/ql/test/library-tests/builtins/type_traits/expr.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,7 @@
305305
| ms.cpp:260:29:260:57 | __is_assignable | a_struct,int | 0 |
306306
| ms.cpp:260:29:260:57 | a_struct | | <none> |
307307
| ms.cpp:260:29:260:57 | int | | <none> |
308+
| ms.cpp:262:28:262:51 | __is_aggregate | a_struct | 1 |
309+
| ms.cpp:262:28:262:51 | a_struct | | <none> |
310+
| ms.cpp:263:28:263:46 | __is_aggregate | int | 0 |
311+
| ms.cpp:263:28:263:46 | int | | <none> |

cpp/ql/test/library-tests/builtins/type_traits/ms.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,7 @@ void f(void) {
258258
bool b_is_assignable1 = __is_assignable(a_struct,a_struct);
259259
bool b_is_assignable2 = __is_assignable(a_struct,empty);
260260
bool b_is_assignable3 = __is_assignable(a_struct,int);
261+
262+
bool b_is_aggregate1 = __is_aggregate(a_struct);
263+
bool b_is_aggregate2 = __is_aggregate(int);
261264
}

0 commit comments

Comments
 (0)