Skip to content

Commit 582ab01

Browse files
authored
Merge branch 'main' into main
2 parents 77ad557 + b041a58 commit 582ab01

File tree

746 files changed

+35568
-11473
lines changed

Some content is hidden

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

746 files changed

+35568
-11473
lines changed

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ namespace clang::tidy {
5555

5656
namespace {
5757
#if CLANG_TIDY_ENABLE_STATIC_ANALYZER
58-
static const char *AnalyzerCheckNamePrefix = "clang-analyzer-";
58+
#define ANALYZER_CHECK_NAME_PREFIX "clang-analyzer-"
59+
static constexpr llvm::StringLiteral AnalyzerCheckNamePrefix =
60+
ANALYZER_CHECK_NAME_PREFIX;
5961

6062
class AnalyzerDiagnosticConsumer : public ento::PathDiagnosticConsumer {
6163
public:
@@ -351,10 +353,9 @@ ClangTidyASTConsumerFactory::ClangTidyASTConsumerFactory(
351353
static void
352354
setStaticAnalyzerCheckerOpts(const ClangTidyOptions &Opts,
353355
clang::AnalyzerOptions &AnalyzerOptions) {
354-
StringRef AnalyzerPrefix(AnalyzerCheckNamePrefix);
355356
for (const auto &Opt : Opts.CheckOptions) {
356357
StringRef OptName(Opt.getKey());
357-
if (!OptName.consume_front(AnalyzerPrefix))
358+
if (!OptName.consume_front(AnalyzerCheckNamePrefix))
358359
continue;
359360
// Analyzer options are always local options so we can ignore priority.
360361
AnalyzerOptions.Config[OptName] = Opt.getValue().Value;
@@ -476,7 +477,8 @@ std::vector<std::string> ClangTidyASTConsumerFactory::getCheckNames() {
476477
#if CLANG_TIDY_ENABLE_STATIC_ANALYZER
477478
for (const auto &AnalyzerCheck : getAnalyzerCheckersAndPackages(
478479
Context, Context.canEnableAnalyzerAlphaCheckers()))
479-
CheckNames.push_back(AnalyzerCheckNamePrefix + AnalyzerCheck.first);
480+
CheckNames.emplace_back(
481+
(AnalyzerCheckNamePrefix + AnalyzerCheck.first).str());
480482
#endif // CLANG_TIDY_ENABLE_STATIC_ANALYZER
481483

482484
llvm::sort(CheckNames);
@@ -668,18 +670,19 @@ getAllChecksAndOptions(bool AllowEnablingAnalyzerAlphaCheckers) {
668670
Buffer.append(AnalyzerCheck);
669671
Result.Checks.insert(Buffer);
670672
}
671-
for (std::string OptionName : {
673+
674+
static constexpr llvm::StringLiteral OptionNames[] = {
672675
#define GET_CHECKER_OPTIONS
673676
#define CHECKER_OPTION(TYPE, CHECKER, OPTION_NAME, DESCRIPTION, DEFAULT, \
674677
RELEASE, HIDDEN) \
675-
Twine(AnalyzerCheckNamePrefix).concat(CHECKER ":" OPTION_NAME).str(),
678+
ANALYZER_CHECK_NAME_PREFIX CHECKER ":" OPTION_NAME,
676679

677680
#include "clang/StaticAnalyzer/Checkers/Checkers.inc"
678681
#undef CHECKER_OPTION
679682
#undef GET_CHECKER_OPTIONS
680-
}) {
681-
Result.Options.insert(OptionName);
682-
}
683+
};
684+
685+
Result.Options.insert_range(OptionNames);
683686
#endif // CLANG_TIDY_ENABLE_STATIC_ANALYZER
684687

685688
Context.setOptionsCollector(&Result.Options);

clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ AST_POLYMORPHIC_MATCHER(
4646
if (PrefixPosition == StringRef::npos)
4747
return false;
4848
Path = Path.drop_front(PrefixPosition + AbslPrefix.size());
49-
static const char *AbseilLibraries[] = {
49+
static constexpr llvm::StringLiteral AbseilLibraries[] = {
5050
"algorithm", "base", "container", "debugging", "flags",
5151
"hash", "iterator", "memory", "meta", "numeric",
5252
"profiling", "random", "status", "strings", "synchronization",
5353
"time", "types", "utility"};
54-
return llvm::any_of(AbseilLibraries, [&](const char *Library) {
54+
return llvm::any_of(AbseilLibraries, [&](llvm::StringLiteral Library) {
5555
return Path.starts_with(Library);
5656
});
5757
}

clang-tools-extra/clang-tidy/bugprone/ComparePointerToMemberVirtualFunctionCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace {
2525

2626
AST_MATCHER(CXXMethodDecl, isVirtual) { return Node.isVirtual(); }
2727

28-
static const char *const ErrorMsg =
28+
static constexpr llvm::StringLiteral ErrorMsg =
2929
"comparing a pointer to member virtual function with other pointer is "
3030
"unspecified behavior, only compare it with a null-pointer constant for "
3131
"equality.";

clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,8 @@ static bool isEmpty(ASTContext &Context, const QualType &Type) {
373373
return isIncompleteOrZeroLengthArrayType(Context, Type);
374374
}
375375

376-
static const char *getInitializer(QualType QT, bool UseAssignment) {
377-
const char *DefaultInitializer = "{}";
376+
static llvm::StringLiteral getInitializer(QualType QT, bool UseAssignment) {
377+
static constexpr llvm::StringLiteral DefaultInitializer = "{}";
378378
if (!UseAssignment)
379379
return DefaultInitializer;
380380

clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ using namespace clang::ast_matchers;
1515

1616
namespace clang::tidy::modernize {
1717

18+
// FIXME: Add chrono::treat_as_floating_point_v and chrono::is_clock_v.
19+
// This will require restructuring the code to handle type traits not
20+
// defined directly in std.
1821
static const llvm::StringSet<> ValueTraits = {
1922
"alignment_of",
2023
"conjunction",
@@ -28,6 +31,7 @@ static const llvm::StringSet<> ValueTraits = {
2831
"is_array",
2932
"is_assignable",
3033
"is_base_of",
34+
"is_bind_expression",
3135
"is_bounded_array",
3236
"is_class",
3337
"is_compound",
@@ -40,10 +44,14 @@ static const llvm::StringSet<> ValueTraits = {
4044
"is_destructible",
4145
"is_empty",
4246
"is_enum",
47+
"is_error_code_enum",
48+
"is_error_condition_enum",
49+
"is_execution_policy",
4350
"is_final",
4451
"is_floating_point",
4552
"is_function",
4653
"is_fundamental",
54+
"is_implicit_lifetime",
4755
"is_integral",
4856
"is_invocable",
4957
"is_invocable_r",
@@ -65,14 +73,17 @@ static const llvm::StringSet<> ValueTraits = {
6573
"is_nothrow_invocable_r",
6674
"is_nothrow_move_assignable",
6775
"is_nothrow_move_constructible",
76+
"is_nothrow_relocatable",
6877
"is_nothrow_swappable",
6978
"is_nothrow_swappable_with",
7079
"is_null_pointer",
7180
"is_object",
81+
"is_placeholder",
7282
"is_pointer",
7383
"is_pointer_interconvertible_base_of",
7484
"is_polymorphic",
7585
"is_reference",
86+
"is_replaceable",
7687
"is_rvalue_reference",
7788
"is_same",
7889
"is_scalar",
@@ -91,15 +102,26 @@ static const llvm::StringSet<> ValueTraits = {
91102
"is_trivially_destructible",
92103
"is_trivially_move_assignable",
93104
"is_trivially_move_constructible",
105+
"is_trivially_relocatable",
94106
"is_unbounded_array",
95107
"is_union",
96108
"is_unsigned",
109+
"is_virtual_base_of",
97110
"is_void",
98111
"is_volatile",
99112
"negation",
100113
"rank",
114+
"ratio_equal",
115+
"ratio_greater_equal",
116+
"ratio_greater",
117+
"ratio_less_equal",
118+
"ratio_less",
119+
"ratio_not_equal",
101120
"reference_constructs_from_temporary",
102121
"reference_converts_from_temporary",
122+
"tuple_size",
123+
"uses_allocator",
124+
"variant_size",
103125
};
104126

105127
static const llvm::StringSet<> TypeTraits = {
@@ -130,6 +152,12 @@ static const llvm::StringSet<> TypeTraits = {
130152
"result_of",
131153
"invoke_result",
132154
"type_identity",
155+
"compare_three_way_result",
156+
"common_comparison_category",
157+
"unwrap_ref_decay",
158+
"unwrap_reference",
159+
"tuple_element",
160+
"variant_alternative",
133161
};
134162

135163
static DeclarationName getName(const DependentScopeDeclRefExpr &D) {

clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ void UseUsingCheck::check(const MatchFinder::MatchResult &Result) {
119119
if (StartLoc.isMacroID() && IgnoreMacros)
120120
return;
121121

122-
static const char *UseUsingWarning = "use 'using' instead of 'typedef'";
122+
static constexpr llvm::StringLiteral UseUsingWarning =
123+
"use 'using' instead of 'typedef'";
123124

124125
// Warn at StartLoc but do not fix if there is macro or array.
125126
if (MatchedDecl->getUnderlyingType()->isArrayType() || StartLoc.isMacroID()) {

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,9 @@ Changes in existing checks
281281
excluding variables with ``thread_local`` storage class specifier from being
282282
matched.
283283

284+
- Improved :doc:`modernize-type-traits
285+
<clang-tidy/checks/modernize/type-traits>` check by detecting more type traits.
286+
284287
- Improved :doc:`modernize-use-default-member-init
285288
<clang-tidy/checks/modernize/use-default-member-init>` check by matching
286289
arithmetic operations, ``constexpr`` and ``static`` values, and detecting

clang-tools-extra/docs/clang-tidy/checks/modernize/type-traits.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,10 @@ Options
3838
#define IS_SIGNED(T) std::is_signed<T>::value
3939

4040
Defaults to `false`.
41+
42+
Limitations
43+
-----------
44+
45+
Does not currently diagnose uses of type traits with nested name
46+
specifiers (e.g. ``std::chrono::is_clock``,
47+
``std::chrono::treat_as_floating_point``).

clang-tools-extra/test/clang-tidy/checkers/modernize/type-traits.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %check_clang_tidy -std=c++14 %s modernize-type-traits %t -check-suffixes=',MACRO'
22
// RUN: %check_clang_tidy -std=c++14 %s modernize-type-traits %t -- \
33
// RUN: -config='{CheckOptions: {modernize-type-traits.IgnoreMacros: true}}'
4-
// RUN: %check_clang_tidy -std=c++17 %s modernize-type-traits %t -check-suffixes=',CXX17,MACRO,CXX17MACRO'
4+
// RUN: %check_clang_tidy -std=c++17-or-later %s modernize-type-traits %t -check-suffixes=',CXX17,MACRO,CXX17MACRO'
55

66
namespace std {
77
template <typename>
@@ -19,6 +19,11 @@ namespace std {
1919
using type = T;
2020
};
2121

22+
template <typename...>
23+
struct common_type {
24+
using type = int;
25+
};
26+
2227
inline namespace __std_lib_version1 {
2328
template<typename T>
2429
struct add_const {
@@ -66,6 +71,10 @@ using UsingNoTypename = std::enable_if<true>::type;
6671
// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: use c++14 style type templates
6772
// CHECK-FIXES: using UsingNoTypename = std::enable_if_t<true>;
6873

74+
using VariadicTrait = std::common_type<int, long, bool>::type;
75+
// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: use c++14 style type templates
76+
// CHECK-FIXES: using VariadicTrait = std::common_type_t<int, long, bool>;
77+
6978
using UsingSpace = std::enable_if <true>::type;
7079
// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: use c++14 style type templates
7180
// CHECK-FIXES: using UsingSpace = std::enable_if_t <true>;

clang/docs/ReleaseNotes.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,12 @@ Improvements to Clang's diagnostics
678678
- Clang now accepts ``@tparam`` comments on variable template partial
679679
specializations. (#GH144775)
680680

681+
- Fixed a bug that caused diagnostic line wrapping to not function correctly on
682+
some systems. (#GH139499)
683+
684+
- Clang now tries to avoid printing file paths that contain ``..``, instead preferring
685+
the canonical file path if it ends up being shorter.
686+
681687
Improvements to Clang's time-trace
682688
----------------------------------
683689

@@ -761,6 +767,11 @@ Bug Fixes in This Version
761767
flag and diagnostic because the macro injection was used to emit this warning.
762768
Unfortunately there is no other good way to diagnose usage of ``static_assert``
763769
macro without inclusion of ``<assert.h>``.
770+
- In C23, something like ``[[/*possible attributes*/]];`` is an attribute
771+
declaration, not a statement. So it is not allowed by the syntax in places
772+
where a statement is required, specifically as the secondary block of a
773+
selection or iteration statement. This differs from C++, since C++ allows
774+
declaration statements. Clang now emits a warning for these patterns. (#GH141659)
764775

765776
Bug Fixes to Compiler Builtins
766777
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -914,6 +925,9 @@ Bug Fixes to C++ Support
914925
- Correctly handle allocations in the condition of a ``if constexpr``.(#GH120197) (#GH134820)
915926
- Fixed a crash when handling invalid member using-declaration in C++20+ mode. (#GH63254)
916927
- Fix a crash when trying to instantiate an ambiguous specialization. (#GH51866)
928+
- Improved handling of variables with ``consteval`` constructors, to
929+
consistently treat the initializer as manifestly constant-evaluated.
930+
(#GH135281)
917931

918932
Bug Fixes to AST Handling
919933
^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)