-
Couldn't load subscription status.
- Fork 15k
Open
Labels
compiler-rt:ubsanUndefined behavior sanitizerUndefined behavior sanitizerfalse-positiveWarning fires when it should notWarning fires when it should not
Description
In the program:
struct A {
constexpr A();
virtual void f() {}
};
struct B : A {};
constexpr A::A() {
(void)static_cast<B*>(this);
}
int main() {
B b;
}compiled with -fsanitize=undefined flag, Clang reports:
/app/example.cpp:9:11: runtime error: downcast of address 0x7ffca2ddc908 which does not point to an object of type 'B'
0x7ffca2ddc908: note: object is of type 'A'
fc 7f 00 00 a8 4c df bc 66 55 00 00 00 00 00 00 00 00 00 00 83 e0 7c 61 10 7f 00 00 b0 ca c9 61
^~~~~~~~~~~~~~~~~~~~~~~
vptr for 'A'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /app/example.cpp:9:11 in Online demo: https://godbolt.org/z/axEPzczs8
But it does not look right, since the pointer after the cast is not used, and it can be used after finishing of B constructor.
pitrou
Metadata
Metadata
Assignees
Labels
compiler-rt:ubsanUndefined behavior sanitizerUndefined behavior sanitizerfalse-positiveWarning fires when it should notWarning fires when it should not