Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Support transforming C-style casts #675

Open
Ukilele opened this issue Nov 28, 2024 · 0 comments
Open

[feature] Support transforming C-style casts #675

Ukilele opened this issue Nov 28, 2024 · 0 comments

Comments

@Ukilele
Copy link

Ukilele commented Nov 28, 2024

Hey Andres,
a (probably not so) small feature request 🙂

The C-style cast is a pretty complex thing in C++: https://en.cppreference.com/w/cpp/language/explicit_cast . It follows a bunch of logical steps to find out what to actually do in the end. It would be convenient if cppsinsights would show which steps and which casts the compiler eventually executes.

Given following code:

struct Base {};
struct Derived : private Base {};

Derived d;
Base& b = (Base&)d;

const Derived d2;
Base& b2 = (Base&)d2;

It would be nice if cppinsights would show something like this:

struct Base
{
  // inline constexpr Base() noexcept = default;
};

struct Derived : private Base
{
  // inline constexpr Derived() noexcept = default;
};


Derived d;
Base & b = /*extended_*/static_cast<Base&>(d);

const Derived d2;
Base & b2 = const_cast<Base&>(/*extended_*/static_cast<const Base&>(d2));

It seems that this feature is already partly implemented. In the following code, the C-style cast gets correctly transformed into a reinterpret_cast:
Code:

struct A { };
struct B { };

int main()
{
    A a;
    ((B*)&a);
}

Tranformation:

struct A
{
  // inline constexpr A() noexcept = default;
};

struct B
{
};


int main()
{
  A a;
  (reinterpret_cast<B *>(&a));
  return 0;
}

Maybe the feature is already partly implemented but only a few bits are missing?

Thanks and best regards,
Kilian

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant