This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by sammccall on Sep 13 2019, 2:33 AM.

Details

Summary

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.

Diff Detail

Repository
rL LLVM

Event Timeline

sammccall created this revision.Sep 13 2019, 2:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 13 2019, 2:33 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
sammccall updated this revision to Diff 220066.Sep 13 2019, 3:13 AM

Add fairly contrived test that demonstrates the difference between c++17 and latest (20) parsing mode.

This revision is now accepted and ready to land.Sep 16 2019, 1:05 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptOct 2 2019, 2:50 AM
thakis added a subscriber: thakis.Oct 3 2019, 3:59 PM

This broke the sphinx bot: http://lab.llvm.org:8011/builders/clang-sphinx-docs/builds/48207

Warning, treated as error:
/home/buildbot/llvm-build-dir/clang-sphinx-docs/llvm/src/tools/clang/docs/ClangFormatStyleOptions.rst:2295: WARNING: Explicit markup ends without a blank line; unexpected unindent.

Thanks, rL373724 should fix.

ClangFormatStyleOptions.rst and Format.h are inconsistent which means when clang/doc/tools/dump_format_style.py is run the rst file being generated is in danger of overwriting your changes (which I think you might have made by hand).

I'm happy to try and fix this for you, but I need to know what you want to keep, whats in the rst or whats in the Format.h