12-02-2025, 07:06 PM
We have some interesting cases for Rule 3-4-1 which we aren't sure whether they are violations or not. Strictly adhering to the rule of reduced visibility could cause issues regarding lifetimes, initialization, and side effects of a constructor/destructor.
For instance, in the following example, is the intent to require changes to the code so that 'old_value' is not visible after the if body, or is `old_value` considered non-violating?
Similarly, in cases where an object's constructor or destructor contains side effects, such as with a mutex, is the current visibility of 'merge_thread_lock' intended to be a violation?
For instance, in the following example, is the intent to require changes to the code so that 'old_value' is not visible after the if body, or is `old_value` considered non-violating?
Code:
void fn(int a) {
int old_value = a;
a += 4;
if (a > 10) {
a = old_value;
}
// ...
}
Similarly, in cases where an object's constructor or destructor contains side effects, such as with a mutex, is the current visibility of 'merge_thread_lock' intended to be a violation?
Code:
void fn(int a) {
std::unique_lock<std::shared_mutex> merge_thread_lock(global_mutex);
if (global) {
global = a;
merge_thread_lock.unlock();
}
// ...
}