Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Flags C-style and function-style casts that reinterpret an object's bits
# (clang's BitCast / LValueBitCast cast kinds); spell these as reinterpret_cast
# (plus const_cast when constness is also discarded) so the intent is explicit.
# Template instantiations are traversed so that dependent casts are reported
# once they resolve to a bit cast.
set traversal AsIs
match explicitCastExpr(
isExpansionInMainFile(),
anyOf(cStyleCastExpr(), cxxFunctionalCastExpr()),
anyOf(
hasCastKind("CK_BitCast"),
hasCastKind("CK_LValueBitCast"),
has(implicitCastExpr(anyOf(hasCastKind("CK_BitCast"), hasCastKind("CK_LValueBitCast"))))))
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[[nodiscard]] char *mutable_bytes(const int *value)
{
return (char *)value;// expect-finding
}

[[nodiscard]] void *mutable_address(const int &value)
{
return (void *)&value;// expect-finding
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
template<typename To, typename From> [[nodiscard]] To convert(const From value)
{
return (To)value;// expect-finding
}

[[nodiscard]] const char *as_chars(const int *value) { return convert<const char *>(value); }
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[[nodiscard]] const unsigned char *object_bytes(const int &value)
{
return (const unsigned char *)&value;// expect-finding
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[[nodiscard]] float &reinterpret_bits(int &value)
{
return (float &)value;// expect-finding
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using byte_pointer = const unsigned char *;

[[nodiscard]] byte_pointer object_bytes(const int &value)
{
return byte_pointer(&value);// expect-finding
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[[nodiscard]] const unsigned char *object_bytes(const int &value)
{
return reinterpret_cast<const unsigned char *>(&value);
}

[[nodiscard]] float &reinterpret_bits(int &value) { return reinterpret_cast<float &>(value); }
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
template<typename To, typename From> [[nodiscard]] constexpr To convert(const From value)
{
return (To)value;
}

[[nodiscard]] constexpr int truncate(const double value) { return convert<int>(value); }
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
struct Base
{
int base_value;
};

struct Derived : Base
{
int derived_value;
};

using integer = int;

[[nodiscard]] constexpr int truncate(const double value) { return (int)value; }

[[nodiscard]] constexpr int truncate_functional(const double value) { return integer(value); }

[[nodiscard]] const Derived *as_derived(const Base *base) { return (const Derived *)base; }

[[nodiscard]] const Base *as_base(const Derived *derived) { return (const Base *)derived; }

[[nodiscard]] float to_float(const int &value) { return (const float &)value; }
Loading