[PATCH] D65043: [Format] Add C++20 standard to style options

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 24 07:45:48 PDT 2019


sammccall added a comment.

In D65043#1599148 <https://reviews.llvm.org/D65043#1599148>, @Quuxplusone wrote:

> Peanut gallery says: A priori, I don't see any reason for clang-format's `LanguageStandard` options to diverge from Clang's own `-std=` options. It sounds like currently they're very different, and you're proposing to make them basically the same. I think that's a good thing.


+1. (It'd be nice to canonically spell these 'c++11' instead of 'Cpp11', but that's a different patch.)
Exception: 'Auto' is important for clang-format but doesn't/shouldn't exist in clang.

> GCC and Clang still treat "lack of any `-std=` option" as a synonym for "`-std=c++03`".

Clang actually defaults to c++14 since clang 6. (CompilerInvocation.cpp near `CLANG_DEFAULT_STD_CXX`)

> A priori this is an absolutely terrible default, but there would be some logic in making clang-format follow their lead. The only sensible alternative, IMHO, would be for you to treat "lack of any `-std=` option" as a synonym for MSVC's `-std:c++latest`, which means "`-std=c++2a` today and `-std=c++2b` tomorrow."

It's important that clang-format works sensibly with minimal configuration on as much code as possible.
This means both:

- when running on pre-11 code that uses `vector<vector<int> >` consistently, it should preserve that c++03-compatible syntax
- when running on post-11 code that uses `vector<vector<int>>` in some places, it should fix the formatting to use it everywhere

This behavior is an important default, and doesn't correspond to any one version of C++. So neither "latest" nor "c++14" is an acceptable default. (Though c++14 should certainly be an option, and latest should possibly be one too)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65043/new/

https://reviews.llvm.org/D65043





More information about the cfe-commits mailing list