CodeQL library for C/C++
Search

Module Cast

Provides classes for modeling C/C++ casts and conversions, as well as some type-related operators such as sizeof and alignof.

Import path

import semmle.code.cpp.exprs.Cast

Imports

Expr

Provides classes modeling C/C++ expressions.

Predicates

qlCast

A node representing the Cast sub-class of entity cast.

qlConversion

A node representing the Conversion sub-class of entity cast.

Classes

AlignofExprOperator

A C++11 alignof expression whose operand is an expression. int addrMask = ~(alignof(expr) - 1);

AlignofOperator

A C++11 alignof expression.

AlignofTypeOperator

A C++11 alignof expression whose operand is a type name. bool proper_alignment = (alingof(T) == alignof(T[0]);

ArithmeticConversion

A conversion from one arithmetic or enum type to another.

ArrayToPointerConversion

A C/C++ array to pointer conversion.

BaseClassConversion

A conversion from a pointer or glvalue of a derived class to a pointer or glvalue of a direct or virtual base class.

BoolConversion

A conversion to bool. Returns false if the source value is zero, false, or nullptr. Returns true otherwise.

CStyleCast

A cast expression in C, or a C-style cast expression in C++. float f = 3.0f; int i = (int)f;

Cast

A C/C++ cast expression.

ConstCast

A C++ const_cast expression.

Conversion

A C/C++ cast expression or similar unary expression that doesn’t affect the logical value of its operand.

DerivedClassConversion

A conversion from a pointer or glvalue to a base class to a pointer or glvalue to a direct derived class.

DynamicCast

A C++ dynamic_cast expression.

FloatingPointConversion

A conversion from one floating point type.

FloatingPointToIntegralConversion

A conversion from a floating point type to an integral or enum type.

GlvalueConversion

A conversion of a glvalue from one type to another. The conversion does not modify the address of the glvalue. For glvalue conversions involving base and derived classes, see BaseClassConversion and DerivedClassConversion.

InheritanceConversion

A conversion between two pointers or _glvalue_s related by inheritance.

IntegralConversion

A conversion from one integral or enum type to another.

IntegralToFloatingPointConversion

A conversion from an integral or enum type to a floating point type.

IntegralToPointerConversion

A conversion from an integral or enum type to a pointer type.

PointerConversion

A conversion from one pointer type to another.

PointerToIntegralConversion

A conversion from a pointer type to an integral or enum type.

PointerToMemberBaseClassConversion

A conversion from a pointer-to-member of a derived class to a pointer-to-member of an immediate base class.

PointerToMemberConversion

A conversion from one pointer-to-member type to another.

PointerToMemberDerivedClassConversion

A conversion from a pointer-to-member of a base class to a pointer-to-member of an immediate derived class.

PrvalueAdjustmentConversion

The adjustment of the type of a class prvalue. Most commonly seen in code similar to: class String { ... }; String func(); void caller() { const String& r = func(); } In the above example, the result of the call to func is a prvalue of type String, which will be adjusted to type const String before being bound to the reference.

ReinterpretCast

A C++ reinterpret_cast expression.

SizeofExprOperator

A C/C++ sizeof expression whose operand is an expression. if (sizeof(a) == sizeof(b)) { c = (b)a; }

SizeofOperator

A C/C++ sizeof expression.

SizeofPackOperator

A C++11 sizeof... expression which determines the size of a template parameter pack.

SizeofTypeOperator

A C/C++ sizeof expression whose operand is a type name. int szlong = sizeof(int) == sizeof(long)? 4 : 8;

StaticCast

A C++ static_cast expression.

TemporaryObjectExpr

A node representing a temporary object created as part of an expression.

TypeidOperator

A C++ typeid expression which provides run-time type information (RTTI) about its argument.

UuidofOperator

A Microsoft C/C++ __uuidof expression that returns the UUID of a type, as specified by the __declspec(uuid) attribute. struct UUID { char a[16]; }; struct __declspec(uuid("{01234567-89ab-cdef-0123-456789ABCDEF}")) S {}; UUID uuid = __uuidof(S);

VoidConversion

A conversion to void.

Modules

CastConsistency

INTERNAL: Do not use. Query predicates used to check invariants that should hold for all Cast nodes. To run all consistency queries for the ASTs, including the ones below, run “semmle/code/cpp/ASTConsistency.ql”.