Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Corrected an NCCE and a CS that had no new lines.

...

Code Block
bgColor#FFcccc
langcpp
class S { 
  int v; 
 
public: 
  S() : v(12) {} // Non-trivial constructor 
 
  void f(); 
};   
 
void f() { 
 
// ...   
 
goto bad_idea;   
 
// ... 
 
S s; // Control passes over the declaration, so initialization does not take place.   
 
bad_idea: s.f(); 
}

Compliant Solution

This compliant solution ensures that s is properly initialized prior to performing the local jump.

Code Block
bgColor#ccccff
langcpp
class S { 
  int v; 
 
public: 
  S() : v(12) {} // Non-trivial constructor 
  
  void f(); 
};   
 
void f() { 
S s; 
 
// ... 
 
goto bad_idea; 
 
// ... 
 
bad_idea: s.f(); 
}

Noncompliant Code Example

...