File tree Expand file tree Collapse file tree 1 file changed +16
-16
lines changed Expand file tree Collapse file tree 1 file changed +16
-16
lines changed Original file line number Diff line number Diff line change 28
28
\begin {codeblock }
29
29
void f()
30
30
{
31
- void *p = malloc(sizeof(int) + sizeof(float)); // undefined behavior, cannot create
32
- // both int and float in same place
33
- int& i = *reinterpret_cast<int *>(p);
34
- float& f = *reinterpret_cast< float*>(p);
31
+ void *p = malloc(sizeof(int) + sizeof(float));
32
+ *reinterpret_cast< int*>(p) = 0;
33
+ *reinterpret_cast<float *>(p) = 0.0f; // undefined behavior, cannot create
34
+ // both int and float in same place
35
35
}
36
36
\end {codeblock }
37
37
\end {example }
126
126
~S() {}
127
127
};
128
128
129
- float f() {
129
+ void f() {
130
130
S* p = new S;
131
131
p->~S();
132
132
delete p; // undefined behavior, operand of delete, lifetime has ended and \tcode {S}
739
739
\pnum
740
740
\begin {example }
741
741
\begin {codeblock }
742
- int main() {
743
- __uint128_t x2 = -1;
744
- float f = x2; // undefined behavior on systems where the range of
745
- // representable values of float is [-max,+max] on system where
746
- // represetable values are [-inf,+inf] this would not be UB
747
- }
742
+ int main() {
743
+ __uint128_t x2 = -1;
744
+ float f = x2; // undefined behavior on systems where the range of
745
+ // representable values of float is [-max,+max] on system where
746
+ // represetable values are [-inf,+inf] this would not be UB
747
+ }
748
748
\end {codeblock }
749
749
\end {example }
750
750
857
857
\pnum
858
858
\begin {example }
859
859
\begin {codeblock }
860
- struct B { virtual ~B(); };
861
- void f() {
862
- B bs[1];
863
- B* dp = dynamic_cast<B*>(bs+1); // undefined behavior
864
- }
860
+ struct B { virtual ~B(); };
861
+ void f() {
862
+ B bs[1];
863
+ B* dp = dynamic_cast<B*>(bs+1); // undefined behavior
864
+ }
865
865
\end {codeblock }
866
866
\end {example }
867
867
You can’t perform that action at this time.
0 commit comments