| Issue |
76335
|
| Summary |
cppcoreguidelines-slicing should honour static_cast<Base>
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
segoon
|
```cpp
class Base {
int i;
void f() {}
virtual void g() {}
};
class DerivedWithMemberVariables : public Base {
void f();
int j;
};
void negatives() {
// OK, simple copying from the same type.
Base a;
DerivedWithMemberVariables b;
// OK, explicit static_cast<> to the base class
a = static_cast<Base>(b);
}
```
Expected: no error as the derived class is explicitly cast to the base class.
Real:
`/home/segoon/projects/llvm-project/build/../clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/slicing.cpp:17:7: warning: slicing object from type 'DerivedWithMemberVariables' to 'Base' discards 4 bytes of state [cppcoreguidelines-slicing]
17 | a = static_cast<Base>(b);
| ^
`
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs