I recently tried to build a project with clang and clang++. Up to now it has only been built with GCC.
One of the problems that I saw was with code that is of the following form
if (expression)
{
var = var;
}
I assume that this was done to give a place in the code to put breakpoints in debug builds. In optimized builds the code should all be optimized away.
We build with -Werror and this fails to build with
error: explicitly assigning value of variable of type 'int' to itself [-Werror,-Wself-assign]
I can get rid of the warning/error with -Wno-self-assign or -Wno-error=self-assign or locally with
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wself-assign"
var = var;
#pragma clang diagnostic pop
(possibly in a MACRO).
Does anyone have any other suggestions for code without side effects that could be used for breakpoints?