Shortest undefined behavior sample in C++ What's the shortest, well-formed C++ code that exhibits undefined behavior?
int main(){main;}



  3.6.1 Main function [basic.start.main]
  
  3 - [...] The function main shall not be used within a program.


Edit: this is diagnosable, so not UB.



int main(){for(;;);}



  1.10 Multi-threaded executions and data races [intro.multithread]
  
  24 - The implementation may assume that any thread will eventually do one of the following:
  — terminate,
  — make a call to a library I/O function,
  — access or modify a volatile object, or
  — perform a synchronization operation or an atomic operation.




int main(){int i=i;}



  4.1 Lvalue-to-rvalue conversion [conv.lval]
  
  1 - [...] If the object to which the glvalue refers is [...] uninitialized, a program
  that necessitates this conversion has undeﬁned behavior.




//^L.


Here ^L is the form feed character, which is part of the basic character set.  4 characters (a newline is not required per 2.2:2).  Undefined behaviour is per


  2.8 Comments [lex.comment]
  
  1 - If there is a
  form-feed or a vertical-tab character in [a //-style] comment, only white-space characters shall appear between it
  and the new-line that terminates the comment; no diagnostic is required.