diff --git a/libcxx/.clang-format b/libcxx/.clang-format --- a/libcxx/.clang-format +++ b/libcxx/.clang-format @@ -4,10 +4,24 @@ Language: Cpp Standard: Cpp03 +# Lots of code uses indent of 4, but that's not consistent. +# AccessModifierOffset: -4 +# IndentWidth: 4 +AlignConsecutiveAssignments: true +AlignTrailingComments: true +# BreakBeforeBraces: Allman # Usage is not consistent. +# AlwaysBreakAfterReturnType: All # Do we want it only in templates? We could request and addition of AlwaysBreakBeforeReturnType as well. + AlwaysBreakTemplateDeclarations: true PointerAlignment: Left +IndentPPDirectives: AfterHash +# SpacesBeforeTrailingComments: 2 # Already inconsistent # Disable formatting options which may break tests. SortIncludes: false ReflowComments: false +# Alternative solution: we can have a different .clang-format in test/. E.g. with: +# CommentPragmas: '^ expected-' # Alternative to disabling ReflowComments. + +# Caveat currently released versions of clang-format mishandle concepts and consider boolean operators as rvalue references, hence using PointerAlignment. --- diff --git a/libcxx/utils/generate_feature_test_macro_components.py b/libcxx/utils/generate_feature_test_macro_components.py --- a/libcxx/utils/generate_feature_test_macro_components.py +++ b/libcxx/utils/generate_feature_test_macro_components.py @@ -561,14 +561,14 @@ for tc in feature_test_macros: if std not in tc["values"]: continue - inner_indent = 1 + inner_indent = 2 if 'depends' in tc.keys(): assert 'internal_depends' in tc.keys() - result += "# if %s\n" % tc["internal_depends"] + result += "# if %s\n" % tc["internal_depends"] inner_indent += 2 if get_value_before(tc["values"], std) is not None: assert 'depends' not in tc.keys() - result += "# undef %s\n" % tc["name"] + result += "# undef %s\n" % tc["name"] line = "#%sdefine %s" % ((" " * inner_indent), tc["name"]) line += " " * (indent - len(line)) line += "%sL" % tc["values"][std] @@ -577,7 +577,7 @@ result += line result += "\n" if 'depends' in tc.keys(): - result += "# endif\n" + result += "# endif\n" return result def chunks(l, n): @@ -642,9 +642,11 @@ #include <__config> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -#pragma GCC system_header +# pragma GCC system_header #endif +// clang-format off + #if _LIBCPP_STD_VER > 11 {cxx14_macros} #endif @@ -657,6 +659,8 @@ {cxx2a_macros} #endif +// clang-format on + #endif // _LIBCPP_VERSIONH """ @@ -677,48 +681,48 @@ test_types = { "undefined": """ -# ifdef {name} -# error "{name} should not be defined before {std_first}" -# endif +# ifdef {name} +# error "{name} should not be defined before {std_first}" +# endif """, "depends": """ -# if {depends} -# ifndef {name} -# error "{name} should be defined in {std}" -# endif -# if {name} != {value} -# error "{name} should have the value {value} in {std}" -# endif -# else -# ifdef {name} -# error "{name} should not be defined when {depends} is not defined!" -# endif -# endif +# if {depends} +# ifndef {name} +# error "{name} should be defined in {std}" +# endif +# if {name} != {value} +# error "{name} should have the value {value} in {std}" +# endif +# else +# ifdef {name} +# error "{name} should not be defined when {depends} is not defined!" +# endif +# endif """, "unimplemented": """ -# if !defined(_LIBCPP_VERSION) -# ifndef {name} -# error "{name} should be defined in {std}" -# endif -# if {name} != {value} -# error "{name} should have the value {value} in {std}" -# endif -# else // _LIBCPP_VERSION -# ifdef {name} -# error "{name} should not be defined because it is unimplemented in libc++!" -# endif -# endif +# if !defined(_LIBCPP_VERSION) +# ifndef {name} +# error "{name} should be defined in {std}" +# endif +# if {name} != {value} +# error "{name} should have the value {value} in {std}" +# endif +# else // _LIBCPP_VERSION +# ifdef {name} +# error "{name} should not be defined because it is unimplemented in libc++!" +# endif +# endif """, "defined":""" -# ifndef {name} -# error "{name} should be defined in {std}" -# endif -# if {name} != {value} -# error "{name} should have the value {value} in {std}" -# endif +# ifndef {name} +# error "{name} should be defined in {std}" +# endif +# if {name} != {value} +# error "{name} should have the value {value} in {std}" +# endif """ } @@ -784,6 +788,8 @@ #include <{header}> #include "test_macros.h" +// clang-format off + #if TEST_STD_VER < 14 {cxx11_tests} @@ -802,6 +808,8 @@ #endif // TEST_STD_VER > 17 +// clang-format on + int main(int, char**) {{ return 0; }} """.format(script_name=script_name, header=h,