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

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 13 02:34:14 PDT 2019


sammccall created this revision.
sammccall added reviewers: klimek, modocache.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D67541

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/unittests/Format/FormatTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67541.220061.patch
Type: text/x-patch
Size: 7890 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190913/513a617d/attachment.bin>


More information about the cfe-commits mailing list