Skip to content

Commit 754ea60

Browse files
authored
Merge branch 'main' into GH88866
2 parents 88beac3 + d3eb65f commit 754ea60

File tree

616 files changed

+15961
-6541
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

616 files changed

+15961
-6541
lines changed

clang-tools-extra/clang-tidy/ClangTidyCheck.cpp

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "ClangTidyCheck.h"
10-
#include "llvm/ADT/SmallString.h"
1110
#include "llvm/ADT/StringRef.h"
12-
#include "llvm/Support/Error.h"
11+
#include "llvm/ADT/StringSet.h"
1312
#include "llvm/Support/YAMLParser.h"
1413
#include <optional>
14+
#include <string>
1515

1616
namespace clang::tidy {
1717

@@ -62,16 +62,29 @@ ClangTidyCheck::OptionsView::get(StringRef LocalName) const {
6262
return std::nullopt;
6363
}
6464

65+
static const llvm::StringSet<> DeprecatedGlobalOptions{
66+
"StrictMode",
67+
"IgnoreMacros",
68+
};
69+
6570
static ClangTidyOptions::OptionMap::const_iterator
6671
findPriorityOption(const ClangTidyOptions::OptionMap &Options,
6772
StringRef NamePrefix, StringRef LocalName,
68-
llvm::StringSet<> *Collector) {
73+
ClangTidyContext *Context) {
74+
llvm::StringSet<> *Collector = Context->getOptionsCollector();
6975
if (Collector) {
7076
Collector->insert((NamePrefix + LocalName).str());
7177
Collector->insert(LocalName);
7278
}
7379
auto IterLocal = Options.find((NamePrefix + LocalName).str());
7480
auto IterGlobal = Options.find(LocalName);
81+
// FIXME: temporary solution for deprecation warnings, should be removed
82+
// after 22.x. Warn configuration deps on deprecation global options.
83+
if (IterLocal == Options.end() && IterGlobal != Options.end() &&
84+
DeprecatedGlobalOptions.contains(LocalName))
85+
Context->configurationDiag(
86+
"global option '%0' is deprecated, please use '%1%0' instead.")
87+
<< LocalName << NamePrefix;
7588
if (IterLocal == Options.end())
7689
return IterGlobal;
7790
if (IterGlobal == Options.end())
@@ -83,8 +96,7 @@ findPriorityOption(const ClangTidyOptions::OptionMap &Options,
8396

8497
std::optional<StringRef>
8598
ClangTidyCheck::OptionsView::getLocalOrGlobal(StringRef LocalName) const {
86-
auto Iter = findPriorityOption(CheckOptions, NamePrefix, LocalName,
87-
Context->getOptionsCollector());
99+
auto Iter = findPriorityOption(CheckOptions, NamePrefix, LocalName, Context);
88100
if (Iter != CheckOptions.end())
89101
return StringRef(Iter->getValue().Value);
90102
return std::nullopt;
@@ -117,8 +129,7 @@ ClangTidyCheck::OptionsView::get<bool>(StringRef LocalName) const {
117129
template <>
118130
std::optional<bool>
119131
ClangTidyCheck::OptionsView::getLocalOrGlobal<bool>(StringRef LocalName) const {
120-
auto Iter = findPriorityOption(CheckOptions, NamePrefix, LocalName,
121-
Context->getOptionsCollector());
132+
auto Iter = findPriorityOption(CheckOptions, NamePrefix, LocalName, Context);
122133
if (Iter != CheckOptions.end()) {
123134
if (auto Result = getAsBool(Iter->getValue().Value, Iter->getKey()))
124135
return Result;
@@ -157,10 +168,9 @@ std::optional<int64_t> ClangTidyCheck::OptionsView::getEnumInt(
157168
bool IgnoreCase) const {
158169
if (!CheckGlobal && Context->getOptionsCollector())
159170
Context->getOptionsCollector()->insert((NamePrefix + LocalName).str());
160-
auto Iter = CheckGlobal
161-
? findPriorityOption(CheckOptions, NamePrefix, LocalName,
162-
Context->getOptionsCollector())
163-
: CheckOptions.find((NamePrefix + LocalName).str());
171+
auto Iter = CheckGlobal ? findPriorityOption(CheckOptions, NamePrefix,
172+
LocalName, Context)
173+
: CheckOptions.find((NamePrefix + LocalName).str());
164174
if (Iter == CheckOptions.end())
165175
return std::nullopt;
166176

clang-tools-extra/clangd/tool/ClangdMain.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,13 @@ opt<std::string> FallbackStyle{
242242
init(clang::format::DefaultFallbackStyle),
243243
};
244244

245-
opt<int> EnableFunctionArgSnippets{
245+
opt<std::string> EnableFunctionArgSnippets{
246246
"function-arg-placeholders",
247247
cat(Features),
248248
desc("When disabled (0), completions contain only parentheses for "
249249
"function calls. When enabled (1), completions also contain "
250250
"placeholders for method parameters"),
251-
init(-1),
251+
init("-1"),
252252
};
253253

254254
opt<CodeCompleteOptions::IncludeInsertion> HeaderInsertion{
@@ -636,6 +636,22 @@ loadExternalIndex(const Config::ExternalIndexSpec &External,
636636
llvm_unreachable("Invalid ExternalIndexKind.");
637637
}
638638

639+
std::optional<bool> shouldEnableFunctionArgSnippets() {
640+
std::string Val = EnableFunctionArgSnippets;
641+
// Accept the same values that a bool option parser would, but also accept
642+
// -1 to indicate "unspecified", in which case the ArgumentListsPolicy
643+
// config option will be respected.
644+
if (Val == "1" || Val == "true" || Val == "True" || Val == "TRUE")
645+
return true;
646+
if (Val == "0" || Val == "false" || Val == "False" || Val == "FALSE")
647+
return false;
648+
if (Val != "-1")
649+
elog("Value specified by --function-arg-placeholders is invalid. Provide a "
650+
"boolean value or leave unspecified to use ArgumentListsPolicy from "
651+
"config instead.");
652+
return std::nullopt;
653+
}
654+
639655
class FlagsConfigProvider : public config::Provider {
640656
private:
641657
config::CompiledFragment Frag;
@@ -696,10 +712,9 @@ class FlagsConfigProvider : public config::Provider {
696712
BGPolicy = Config::BackgroundPolicy::Skip;
697713
}
698714

699-
if (EnableFunctionArgSnippets >= 0) {
700-
ArgumentLists = EnableFunctionArgSnippets
701-
? Config::ArgumentListsPolicy::FullPlaceholders
702-
: Config::ArgumentListsPolicy::Delimiters;
715+
if (std::optional<bool> Enable = shouldEnableFunctionArgSnippets()) {
716+
ArgumentLists = *Enable ? Config::ArgumentListsPolicy::FullPlaceholders
717+
: Config::ArgumentListsPolicy::Delimiters;
703718
}
704719

705720
Frag = [=](const config::Params &, Config &C) {

clang-tools-extra/clangd/unittests/Matchers.h

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -127,74 +127,6 @@ PolySubsequenceMatcher<Args...> HasSubsequence(Args &&... M) {
127127
llvm::consumeError(ComputedValue.takeError()); \
128128
} while (false)
129129

130-
// Implements the HasValue(m) matcher for matching an Optional whose
131-
// value matches matcher m.
132-
template <typename InnerMatcher> class OptionalMatcher {
133-
public:
134-
explicit OptionalMatcher(const InnerMatcher &matcher) : matcher_(matcher) {}
135-
OptionalMatcher(const OptionalMatcher&) = default;
136-
OptionalMatcher &operator=(const OptionalMatcher&) = delete;
137-
138-
// This type conversion operator template allows Optional(m) to be
139-
// used as a matcher for any Optional type whose value type is
140-
// compatible with the inner matcher.
141-
//
142-
// The reason we do this instead of relying on
143-
// MakePolymorphicMatcher() is that the latter is not flexible
144-
// enough for implementing the DescribeTo() method of Optional().
145-
template <typename Optional> operator Matcher<Optional>() const {
146-
return MakeMatcher(new Impl<Optional>(matcher_));
147-
}
148-
149-
private:
150-
// The monomorphic implementation that works for a particular optional type.
151-
template <typename Optional>
152-
class Impl : public ::testing::MatcherInterface<Optional> {
153-
public:
154-
using Value = typename std::remove_const<
155-
typename std::remove_reference<Optional>::type>::type::value_type;
156-
157-
explicit Impl(const InnerMatcher &matcher)
158-
: matcher_(::testing::MatcherCast<const Value &>(matcher)) {}
159-
160-
Impl(const Impl&) = default;
161-
Impl &operator=(const Impl&) = delete;
162-
163-
virtual void DescribeTo(::std::ostream *os) const {
164-
*os << "has a value that ";
165-
matcher_.DescribeTo(os);
166-
}
167-
168-
virtual void DescribeNegationTo(::std::ostream *os) const {
169-
*os << "does not have a value that ";
170-
matcher_.DescribeTo(os);
171-
}
172-
173-
virtual bool
174-
MatchAndExplain(Optional optional,
175-
::testing::MatchResultListener *listener) const {
176-
if (!optional)
177-
return false;
178-
179-
*listener << "which has a value ";
180-
return MatchPrintAndExplain(*optional, matcher_, listener);
181-
}
182-
183-
private:
184-
const Matcher<const Value &> matcher_;
185-
};
186-
187-
const InnerMatcher matcher_;
188-
};
189-
190-
// Creates a matcher that matches an Optional that has a value
191-
// that matches inner_matcher.
192-
template <typename InnerMatcher>
193-
inline OptionalMatcher<InnerMatcher>
194-
HasValue(const InnerMatcher &inner_matcher) {
195-
return OptionalMatcher<InnerMatcher>(inner_matcher);
196-
}
197-
198130
} // namespace clangd
199131
} // namespace clang
200132
#endif

clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ using ::testing::ElementsAre;
2828
using ::testing::Field;
2929
using ::testing::IsEmpty;
3030
using ::testing::Matcher;
31+
using ::testing::Optional;
3132
using ::testing::SizeIs;
3233
using ::testing::UnorderedElementsAre;
3334

@@ -38,12 +39,12 @@ MATCHER_P(selectionRangeIs, R, "") { return arg.selectionRange == R; }
3839
template <class... ParentMatchers>
3940
::testing::Matcher<TypeHierarchyItem> parents(ParentMatchers... ParentsM) {
4041
return Field(&TypeHierarchyItem::parents,
41-
HasValue(UnorderedElementsAre(ParentsM...)));
42+
Optional(UnorderedElementsAre(ParentsM...)));
4243
}
4344
template <class... ChildMatchers>
4445
::testing::Matcher<TypeHierarchyItem> children(ChildMatchers... ChildrenM) {
4546
return Field(&TypeHierarchyItem::children,
46-
HasValue(UnorderedElementsAre(ChildrenM...)));
47+
Optional(UnorderedElementsAre(ChildrenM...)));
4748
}
4849
// Note: "not resolved" is different from "resolved but empty"!
4950
MATCHER(parentsNotResolved, "") { return !arg.parents; }
@@ -790,7 +791,7 @@ struct Child : Parent1, Parent2 {};
790791
Children,
791792
UnorderedElementsAre(
792793
AllOf(withName("Child"),
793-
withResolveParents(HasValue(UnorderedElementsAre(withResolveID(
794+
withResolveParents(Optional(UnorderedElementsAre(withResolveID(
794795
getSymbolID(&findDecl(AST, "Parent1")).str())))))));
795796
}
796797

@@ -810,9 +811,9 @@ struct Chil^d : Parent {};
810811
ASSERT_THAT(Result, SizeIs(1));
811812
auto Parents = superTypes(Result.front(), Index.get());
812813

813-
EXPECT_THAT(Parents, HasValue(UnorderedElementsAre(
814+
EXPECT_THAT(Parents, Optional(UnorderedElementsAre(
814815
AllOf(withName("Parent"),
815-
withResolveParents(HasValue(IsEmpty()))))));
816+
withResolveParents(Optional(IsEmpty()))))));
816817
}
817818
} // namespace
818819
} // namespace clangd

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ Improvements to clang-tidy
119119

120120
- Removed :program:`clang-tidy`'s global options for most of checks. All options
121121
are changed to local options except `IncludeStyle`, `StrictMode` and
122-
`IgnoreMacros`.
122+
`IgnoreMacros`. Global scoped `StrictMode` and `IgnoreMacros` are deprecated
123+
and will be removed in further releases.
123124

124125
.. csv-table::
125126
:header: "Check", "Options removed from global option"

clang-tools-extra/docs/clang-tidy/checks/bugprone/unhandled-self-assignment.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,7 @@ temporary object into ``this`` (needs a move assignment operator):
120120
121121
.. option:: WarnOnlyIfThisHasSuspiciousField
122122

123-
When `true`, the check will warn only if the container class of the copy assignment operator
124-
has any suspicious fields (pointer or C array). This option is set to `true` by default.
123+
When `true`, the check will warn only if the container class of the copy
124+
assignment operator has any suspicious fields (pointer, C array and C++ smart
125+
pointer).
126+
This option is set to `true` by default.

clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-fmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %check_clang_tidy %s modernize-use-std-format %t -- \
22
// RUN: -config="{CheckOptions: { \
3-
// RUN: StrictMode: true, \
3+
// RUN: modernize-use-std-format.StrictMode: true, \
44
// RUN: modernize-use-std-format.StrFormatLikeFunctions: 'fmt::sprintf', \
55
// RUN: modernize-use-std-format.ReplacementFormatFunction: 'fmt::format', \
66
// RUN: modernize-use-std-format.FormatHeader: '<fmt/core.h>' \
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// RUN: clang-tidy %s --config="{CheckOptions:{StrictMode: true}}" -checks="-*,modernize-use-std-format" | FileCheck %s
2+
3+
// CHECK: warning: global option 'StrictMode' is deprecated, please use 'modernize-use-std-format.StrictMode' instead. [clang-tidy-config]

clang/docs/ClangFormat.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ names. It has the following format:
150150
* Patterns follow the rules specified in `POSIX 2.13.1, 2.13.2, and Rule 1 of
151151
2.13.3 <https://pubs.opengroup.org/onlinepubs/9699919799/utilities/
152152
V3_chap02.html#tag_18_13>`_.
153+
* Bash globstar (``**``) is supported.
153154
* A pattern is negated if it starts with a bang (``!``).
154155

155156
To match all files in a directory, use e.g. ``foo/bar/*``. To match all files in

clang/docs/ClangFormatStyleOptions.rst

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2088,6 +2088,11 @@ the configuration (without a prefix: ``Auto``).
20882088
If ``true``, ``while (true) continue;`` can be put on a single
20892089
line.
20902090

2091+
.. _AllowShortNamespacesOnASingleLine:
2092+
2093+
**AllowShortNamespacesOnASingleLine** (``Boolean``) :versionbadge:`clang-format 20` :ref:`<AllowShortNamespacesOnASingleLine>`
2094+
If ``true``, ``namespace a { class b; }`` can be put on a single line.
2095+
20912096
.. _AlwaysBreakAfterDefinitionReturnType:
20922097

20932098
**AlwaysBreakAfterDefinitionReturnType** (``DefinitionReturnTypeBreakingStyle``) :versionbadge:`clang-format 3.7` :ref:`<AlwaysBreakAfterDefinitionReturnType>`
@@ -6793,6 +6798,15 @@ the configuration (without a prefix: ``Auto``).
67936798

67946799

67956800

6801+
.. _VariableTemplates:
6802+
6803+
**VariableTemplates** (``List of Strings``) :versionbadge:`clang-format 20` :ref:`<VariableTemplates>`
6804+
A vector of non-keyword identifiers that should be interpreted as variable
6805+
template names.
6806+
6807+
A ``)`` after a variable template instantiation is **not** annotated as
6808+
the closing parenthesis of C-style cast operator.
6809+
67966810
.. _VerilogBreakBetweenInstancePorts:
67976811

67986812
**VerilogBreakBetweenInstancePorts** (``Boolean``) :versionbadge:`clang-format 17` :ref:`<VerilogBreakBetweenInstancePorts>`
@@ -6829,6 +6843,45 @@ the configuration (without a prefix: ``Auto``).
68296843
68306844
For example: BOOST_PP_STRINGIZE
68316845

6846+
.. _WrapNamespaceBodyWithEmptyLines:
6847+
6848+
**WrapNamespaceBodyWithEmptyLines** (``WrapNamespaceBodyWithEmptyLinesStyle``) :versionbadge:`clang-format 20` :ref:`<WrapNamespaceBodyWithEmptyLines>`
6849+
Wrap namespace body with empty lines.
6850+
6851+
Possible values:
6852+
6853+
* ``WNBWELS_Never`` (in configuration: ``Never``)
6854+
Remove all empty lines at the beginning and the end of namespace body.
6855+
6856+
.. code-block:: c++
6857+
6858+
namespace N1 {
6859+
namespace N2
6860+
function();
6861+
}
6862+
}
6863+
6864+
* ``WNBWELS_Always`` (in configuration: ``Always``)
6865+
Always have at least one empty line at the beginning and the end of
6866+
namespace body except that the number of empty lines between consecutive
6867+
nested namespace definitions is not increased.
6868+
6869+
.. code-block:: c++
6870+
6871+
namespace N1 {
6872+
namespace N2 {
6873+
6874+
function();
6875+
6876+
}
6877+
}
6878+
6879+
* ``WNBWELS_Leave`` (in configuration: ``Leave``)
6880+
Keep existing newlines at the beginning and the end of namespace body.
6881+
``MaxEmptyLinesToKeep`` still applies.
6882+
6883+
6884+
68326885
.. END_FORMAT_STYLE_OPTIONS
68336886
68346887
Adding additional style options

0 commit comments

Comments
 (0)