Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 3-4-1 and lifetimes, initialization, and side effects
#2
Your first code example is compliant. The intent of the rule was that declarations should be in the smallest existing scope that retains the meaning of the program, and not to imply that new scopes should be created.

You are also right that there are potential problems when an object has constructors/destructors with side-effects. Cases like 'merge_thread_lock' weren't considered when we drafted this rule. This is one of the reasons that this rule has been removed from MISRA C++::2023
Posted by and on behalf of
the MISRA C++ Working Group
Reply


Messages In This Thread
RE: Rule 3-4-1 and lifetimes, initialization, and side effects - by misra cpp - 14-02-2025, 01:02 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)