I have code similar to the following block of code (I am not allowed to publish the source code) inside the .cpp file, which I think compiled by clang++ ( Ubuntu clang version 3.5.2-3ubuntu1 (tags/RELEASE_352/final) (based on LLVM 3.5.2) ).
It looks like C code because we use GoogleTest to test our C code. Anyway:
size_t const SHIFT = 4; uint8_t var, var2; var2 = var; var = var << SHIFT >> SHIFT;
Now, why is comment [1] true? I assumed that the corresponding line would result in the nullification of the upper 4 bits. But I found out that this is not true; the program simply restores the original value.
Is this a language-specific behavior or is clang compiling a supposedly useless bit shift?
(I checked associativity (using this table on cppreference.com , assuming that the associativity / priority of the main operators will not differ between C++ versions and probably not between C++ and C , or at least not in the βcurrent versionsβ) , and it seems that the RHS expression in [1] should really give the same result as the following two statements)
c ++ c compiler-optimization compilation clang ++
polynomial_donut
source share