Skip to content

Commit 2f1fc4b

Browse files
authored
Merge branch 'main' into fix/147217
2 parents f923464 + deade03 commit 2f1fc4b

File tree

496 files changed

+12049
-5369
lines changed

Some content is hidden

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

496 files changed

+12049
-5369
lines changed

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/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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,11 @@ Bug Fixes in This Version
772772
flag and diagnostic because the macro injection was used to emit this warning.
773773
Unfortunately there is no other good way to diagnose usage of ``static_assert``
774774
macro without inclusion of ``<assert.h>``.
775+
- In C23, something like ``[[/*possible attributes*/]];`` is an attribute
776+
declaration, not a statement. So it is not allowed by the syntax in places
777+
where a statement is required, specifically as the secondary block of a
778+
selection or iteration statement. This differs from C++, since C++ allows
779+
declaration statements. Clang now emits a warning for these patterns. (#GH141659)
775780

776781
Bug Fixes to Compiler Builtins
777782
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -925,6 +930,9 @@ Bug Fixes to C++ Support
925930
- Correctly handle allocations in the condition of a ``if constexpr``.(#GH120197) (#GH134820)
926931
- Fixed a crash when handling invalid member using-declaration in C++20+ mode. (#GH63254)
927932
- Fix a crash when trying to instantiate an ambiguous specialization. (#GH51866)
933+
- Improved handling of variables with ``consteval`` constructors, to
934+
consistently treat the initializer as manifestly constant-evaluated.
935+
(#GH135281)
928936

929937
Bug Fixes to AST Handling
930938
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@ def err_expected_while : Error<"expected 'while' in do/while loop">;
276276

277277
def err_expected_semi_after_stmt : Error<"expected ';' after %0 statement">;
278278
def err_expected_semi_after_expr : Error<"expected ';' after expression">;
279+
def warn_attr_in_secondary_block : ExtWarn<
280+
"ISO C does not allow an attribute list to appear here">,
281+
InGroup<DiagGroup<"c-attribute-extension">>;
279282
def err_extraneous_token_before_semi : Error<"extraneous '%0' before ';'">;
280283

281284
def err_expected_semi_after_method_proto : Error<

clang/include/clang/Driver/CommonArgs.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,12 @@ StringRef parseMPreferVectorWidthOption(clang::DiagnosticsEngine &Diags,
283283
StringRef parseMRecipOption(clang::DiagnosticsEngine &Diags,
284284
const llvm::opt::ArgList &Args);
285285

286+
// Convert ComplexRangeKind to a string that can be passed as a frontend option.
287+
std::string complexRangeKindToStr(LangOptions::ComplexRangeKind Range);
288+
289+
// Render a frontend option corresponding to ComplexRangeKind.
290+
std::string renderComplexRangeOption(LangOptions::ComplexRangeKind Range);
291+
286292
} // end namespace tools
287293
} // end namespace driver
288294
} // end namespace clang

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,12 +1023,13 @@ defm offload_uniform_block : BoolFOption<"offload-uniform-block",
10231023
BothFlags<[], [ClangOption], " that kernels are launched with uniform block sizes (default true for CUDA/HIP and false otherwise)">>;
10241024

10251025
def fcomplex_arithmetic_EQ : Joined<["-"], "fcomplex-arithmetic=">, Group<f_Group>,
1026-
Visibility<[ClangOption, CC1Option]>,
1026+
Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
10271027
Values<"full,improved,promoted,basic">, NormalizedValuesScope<"LangOptions">,
1028-
NormalizedValues<["CX_Full", "CX_Improved", "CX_Promoted", "CX_Basic"]>;
1028+
NormalizedValues<["CX_Full", "CX_Improved", "CX_Promoted", "CX_Basic"]>,
1029+
HelpText<"Controls the calculation methods of complex number multiplication and division.">;
10291030

10301031
def complex_range_EQ : Joined<["-"], "complex-range=">, Group<f_Group>,
1031-
Visibility<[CC1Option]>,
1032+
Visibility<[CC1Option, FC1Option]>,
10321033
Values<"full,improved,promoted,basic">, NormalizedValuesScope<"LangOptions">,
10331034
NormalizedValues<["CX_Full", "CX_Improved", "CX_Promoted", "CX_Basic"]>,
10341035
MarshallingInfoEnum<LangOpts<"ComplexRange">, "CX_Full">;

clang/include/clang/Sema/Sema.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6761,6 +6761,7 @@ class Sema final : public SemaBase {
67616761
EK_Decltype,
67626762
EK_TemplateArgument,
67636763
EK_AttrArgument,
6764+
EK_VariableInit,
67646765
EK_Other
67656766
} ExprContext;
67666767

0 commit comments

Comments
 (0)