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/include/variant b/libcxx/include/variant --- a/libcxx/include/variant +++ b/libcxx/include/variant @@ -1663,8 +1663,8 @@ using argument_type = monostate; using result_type = size_t; - inline _LIBCPP_INLINE_VISIBILITY - result_type operator()(const argument_type&) const _NOEXCEPT { + inline _LIBCPP_INLINE_VISIBILITY result_type + operator()(const argument_type&) const _NOEXCEPT { return 66740831; // return a fundamentally attractive random value. } }; diff --git a/libcxx/include/vector b/libcxx/include/vector --- a/libcxx/include/vector +++ b/libcxx/include/vector @@ -3403,7 +3403,7 @@ erase_if(vector<_Tp, _Allocator>& __c, _Predicate __pred) { auto __old_size = __c.size(); __c.erase(_VSTD::remove_if(__c.begin(), __c.end(), __pred), __c.end()); - return __old_size - __c.size(); + return __old_size - __c.size(); } #endif diff --git a/libcxx/utils/ci/buildkite-pipeline.yml b/libcxx/utils/ci/buildkite-pipeline.yml --- a/libcxx/utils/ci/buildkite-pipeline.yml +++ b/libcxx/utils/ci/buildkite-pipeline.yml @@ -15,6 +15,19 @@ # steps: + - label: "Format" + command: "libcxx/utils/ci/run-buildbot check-format" + artifact_paths: + - "**/clang-format.patch" + agents: + queue: "libcxx-builders" + retry: + automatic: + - exit_status: -1 # Agent was lost + limit: 2 + + - wait + - label: "C++03" command: "libcxx/utils/ci/run-buildbot generic-cxx03" artifact_paths: diff --git a/libcxx/utils/ci/run-buildbot b/libcxx/utils/ci/run-buildbot --- a/libcxx/utils/ci/run-buildbot +++ b/libcxx/utils/ci/run-buildbot @@ -8,6 +8,7 @@ #===----------------------------------------------------------------------===## set -ex +set -o pipefail PROGNAME="$(basename "${0}")" @@ -105,6 +106,21 @@ } case "${BUILDER}" in +check-format) + clean + echo "+++ Checking formatting" + # We need to set --extensions so that clang-format checks extensionless files. + mkdir -p ${BUILD_DIR} + git-clang-format \ + --binary /usr/bin/clang-format-11 --diff \ + --extensions ',h,hh,hpp,hxx,c,cc,cxx,cpp' HEAD~1 \ + -- \ + libcxx/{benchmarks,include,src,test} \ + libcxxabi/{fuzz,include,src,test} \ + | tee ${BUILD_DIR}/clang-format.patch + # Check if the diff is empty, fail otherwise. + ! grep -q '^--- a' ${BUILD_DIR}/clang-format.patch +;; generic-cxx03) export CC=clang export CXX=clang++ 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 @@ -564,14 +564,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] @@ -580,7 +580,7 @@ result += line result += "\n" if 'depends' in tc.keys(): - result += "# endif\n" + result += "# endif\n" return result def chunks(l, n): @@ -645,9 +645,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 @@ -660,6 +662,8 @@ {cxx2a_macros} #endif +// clang-format on + #endif // _LIBCPP_VERSIONH """ @@ -680,48 +684,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 """ } @@ -787,6 +791,8 @@ #include <{header}> #include "test_macros.h" +// clang-format off + #if TEST_STD_VER < 14 {cxx11_tests} @@ -805,6 +811,8 @@ #endif // TEST_STD_VER > 17 +// clang-format on + int main(int, char**) {{ return 0; }} """.format(script_name=script_name, header=h,