Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions cpp/ql/src/semmle/code/cpp/exprs/BuiltInOperations.qll
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,15 @@ class BuiltInOperationIsUnion extends BuiltInOperation, @isunionexpr {
}

/**
* A C++ `__builtin_types` expression (used by some implementations of the type_traits header).
* DEPRECATED: Use `BuiltInOperationBuiltInTypesCompatibleP` instead.
*/
class BuiltInOperationBuiltInTypes extends BuiltInOperation, @typescompexpr {
override string toString() { result = "__builtin_types" }
deprecated class BuiltInOperationBuiltInTypes = BuiltInOperationBuiltInTypesCompatibleP;

/**
* A C++ `__builtin_types_compatible_p` expression (used by some implementations of the type_traits header).
*/
class BuiltInOperationBuiltInTypesCompatibleP extends BuiltInOperation, @typescompexpr {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm probably being overly paranoid here, but since the name BuiltInOperationBuiltInTypes was part of the supported API, we shouldn't make that name go away without deprecating it for a few releases first. I recommend adding an alias from the old name to the new name, something like:

  /**
   * DEPRECATED: Use `BuiltInOperationBuiltInTypesCompatibleP instead.instead.
   */
  deprecated
  class BuiltInOperationBuiltInTypes = BuiltInOperationBuiltInTypesCompatibleP;this.getChild(0) }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, I'll add that.

override string toString() { result = "__builtin_types_compatible_p" }
}

/**
Expand Down
2 changes: 2 additions & 0 deletions cpp/ql/test/library-tests/builtins/builtins/builtins.expected
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
| choose_expr.c:3:13:3:42 | __builtin_choose_expr |
| types.c:4:9:4:57 | __builtin_types_compatible_p |
| types.c:6:16:6:65 | __builtin_types_compatible_p |
| varargs.c:7:5:7:32 | __builtin_va_start |
| varargs.c:9:13:9:37 | __builtin_va_arg |
| varargs.c:11:5:11:24 | __builtin_va_end |
11 changes: 11 additions & 0 deletions cpp/ql/test/library-tests/builtins/builtins/types.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

int main(int argc, char **argv) {
char *s;
if (__builtin_types_compatible_p(__typeof__(s), long)) {
puts("long");
} else if (__builtin_types_compatible_p(__typeof__(s), char*)) {
puts("str");
}
return (0);
};