[ClangFormat] Future-proof Standard option, allow floating or pinning to…

Authored by sammccall on Oct 2 2019, 2:50 AM.


[ClangFormat] Future-proof Standard option, allow floating or pinning to arbitrary lang version

The historical context:

  • clang-format was written when C++11 was current, and the main language-version concern was >> vs > > template-closers. An option was added to allow selection of the 03/11 behavior, or auto-detection.
  • there was no option to choose simply "latest standard" so anyone who didn't ever want 03 behavior or auto-detection specified Cpp11.
  • In r185149 this option started to affect lexer mode.
  • no options were added to cover c++14, as parsing/formatting didn't change that much. The usage of Cpp11 to mean "latest" became codified e.g. in r206263
  • c++17 added some new constructs. These were mostly backwards-compatible and so not used in old programs, so having no way to turn them off was OK.
  • c++20 added some new constructs and keywords (e.g. co_*) that changed the meaning of existing programs, and people started to complain that the c++20 parsing couldn't be turned off.

New plan:

  • Default ('Auto') behavior remains unchanged: parse as latest, format template-closers based on input.
  • Add new 'Latest' option that more clearly expresses the intent "use modern features" that many projects have chosen for their .clang-format files.
  • Allow pinning to *any* language version, using the same name as clang -std: c++03, c++11, c++14 etc. These set precise lexer options, and any clang-format code depending on these can use a >= check.
  • For backwards compatibility, Cpp11 is an alias for Latest, not c++11. This matches the historical documented semantics of this option. This spelling (and Cpp03) are deprecated.

Reviewers: klimek, modocache

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D67541

llvm-svn: 373439