Skip to content

Commit 12cafc3

Browse files
authored
Merge branch 'main' into add_test_for_p2788r0
2 parents e29aaaf + 892513e commit 12cafc3

File tree

12 files changed

+66
-50
lines changed

12 files changed

+66
-50
lines changed

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -702,17 +702,16 @@ void NotNullTerminatedResultCheck::registerMatchers(MatchFinder *Finder) {
702702
return hasArgument(
703703
CC.LengthPos,
704704
allOf(
705-
anyOf(
706-
ignoringImpCasts(integerLiteral().bind(WrongLengthExprName)),
707-
allOf(unless(hasDefinition(SizeOfCharExpr)),
708-
allOf(CC.WithIncrease
709-
? ignoringImpCasts(hasDefinition(HasIncOp))
710-
: ignoringImpCasts(allOf(
711-
unless(hasDefinition(HasIncOp)),
712-
anyOf(hasDefinition(binaryOperator().bind(
713-
UnknownLengthName)),
714-
hasDefinition(anything())))),
715-
AnyOfWrongLengthInit))),
705+
anyOf(ignoringImpCasts(integerLiteral().bind(WrongLengthExprName)),
706+
allOf(unless(hasDefinition(SizeOfCharExpr)),
707+
allOf(CC.WithIncrease
708+
? ignoringImpCasts(hasDefinition(HasIncOp))
709+
: ignoringImpCasts(
710+
allOf(unless(hasDefinition(HasIncOp)),
711+
hasDefinition(optionally(
712+
binaryOperator().bind(
713+
UnknownLengthName))))),
714+
AnyOfWrongLengthInit))),
716715
expr().bind(LengthExprName)));
717716
};
718717

clang-tools-extra/clang-tidy/hicpp/ExceptionBaseclassCheck.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@ void ExceptionBaseclassCheck::registerMatchers(MatchFinder *Finder) {
2424
isSameOrDerivedFrom(hasName("::std::exception")))))))))),
2525
// This condition is always true, but will bind to the
2626
// template value if the thrown type is templated.
27-
anyOf(has(expr(
28-
hasType(substTemplateTypeParmType().bind("templ_type")))),
29-
anything()),
27+
optionally(has(
28+
expr(hasType(substTemplateTypeParmType().bind("templ_type"))))),
3029
// Bind to the declaration of the type of the value that
31-
// is thrown. 'anything()' is necessary to always succeed
32-
// in the 'eachOf' because builtin types are not
33-
// 'namedDecl'.
34-
eachOf(has(expr(hasType(namedDecl().bind("decl")))), anything()))
30+
// is thrown. 'optionally' is necessary because builtin types
31+
// are not 'namedDecl'.
32+
optionally(has(expr(hasType(namedDecl().bind("decl"))))))
3533
.bind("bad_throw"),
3634
this);
3735
}

clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ void StaticAssertCheck::registerMatchers(MatchFinder *Finder) {
3838
binaryOperator(
3939
hasAnyOperatorName("&&", "=="),
4040
hasEitherOperand(ignoringImpCasts(stringLiteral().bind("assertMSG"))),
41-
anyOf(binaryOperator(hasEitherOperand(IsAlwaysFalseWithCast)),
42-
anything()))
41+
optionally(binaryOperator(hasEitherOperand(IsAlwaysFalseWithCast))))
4342
.bind("assertExprRoot"),
4443
IsAlwaysFalse);
4544
auto NonConstexprFunctionCall =
@@ -52,12 +51,10 @@ void StaticAssertCheck::registerMatchers(MatchFinder *Finder) {
5251
auto NonConstexprCode =
5352
expr(anyOf(NonConstexprFunctionCall, NonConstexprVariableReference));
5453
auto AssertCondition =
55-
expr(
56-
anyOf(expr(ignoringParenCasts(anyOf(
57-
AssertExprRoot, unaryOperator(hasUnaryOperand(
58-
ignoringParenCasts(AssertExprRoot)))))),
59-
anything()),
60-
unless(NonConstexprCode), unless(hasDescendant(NonConstexprCode)))
54+
expr(optionally(expr(ignoringParenCasts(anyOf(
55+
AssertExprRoot, unaryOperator(hasUnaryOperand(
56+
ignoringParenCasts(AssertExprRoot))))))),
57+
unless(NonConstexprCode), unless(hasDescendant(NonConstexprCode)))
6158
.bind("condition");
6259
auto Condition =
6360
anyOf(ignoringParenImpCasts(callExpr(

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,12 @@ void UseBoolLiteralsCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
2626

2727
void UseBoolLiteralsCheck::registerMatchers(MatchFinder *Finder) {
2828
Finder->addMatcher(
29-
traverse(
30-
TK_AsIs,
31-
implicitCastExpr(
32-
has(ignoringParenImpCasts(integerLiteral().bind("literal"))),
33-
hasImplicitDestinationType(qualType(booleanType())),
34-
unless(isInTemplateInstantiation()),
35-
anyOf(hasParent(explicitCastExpr().bind("cast")), anything()))),
29+
traverse(TK_AsIs,
30+
implicitCastExpr(
31+
has(ignoringParenImpCasts(integerLiteral().bind("literal"))),
32+
hasImplicitDestinationType(qualType(booleanType())),
33+
unless(isInTemplateInstantiation()),
34+
optionally(hasParent(explicitCastExpr().bind("cast"))))),
3635
this);
3736

3837
Finder->addMatcher(

clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,8 @@ void ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
348348
implicitCastExpr().bind("implicitCastFromBool"),
349349
unless(hasParent(BitfieldConstruct)),
350350
// Check also for nested casts, for example: bool -> int -> float.
351-
anyOf(hasParent(implicitCastExpr().bind("furtherImplicitCast")),
352-
anything()),
351+
optionally(
352+
hasParent(implicitCastExpr().bind("furtherImplicitCast"))),
353353
unless(isInTemplateInstantiation()),
354354
unless(IsInCompilerGeneratedFunction))),
355355
this);

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,7 @@ Bug Fixes in This Version
703703
the second clause of a C-style ``for`` loop. (#GH139818)
704704
- Fixed a bug with constexpr evaluation for structs containing unions in case of C++ modules. (#GH143168)
705705
- Fixed incorrect token location when emitting diagnostics for tokens expanded from macros. (#GH143216)
706+
- Fixed an infinite recursion when checking constexpr destructors. (#GH141789)
706707

707708
Bug Fixes to Compiler Builtins
708709
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3978,7 +3978,7 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
39783978
for (auto *Tok = FirstNonComment && FirstNonComment->isNot(tok::kw_using)
39793979
? FirstNonComment->Next
39803980
: nullptr;
3981-
Tok; Tok = Tok->Next) {
3981+
Tok && Tok->isNot(BK_BracedInit); Tok = Tok->Next) {
39823982
if (Tok->is(TT_StartOfName))
39833983
SeenName = true;
39843984
if (Tok->Previous->EndsCppAttributeGroup)

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7159,7 +7159,10 @@ void Sema::CheckCompletedCXXClass(Scope *S, CXXRecordDecl *Record) {
71597159
// "effectively constexpr" for better compatibility.
71607160
// See https://github.com/llvm/llvm-project/issues/102293 for more info.
71617161
if (isa<CXXDestructorDecl>(M)) {
7162-
auto Check = [](QualType T, auto &&Check) -> bool {
7162+
llvm::SmallDenseSet<QualType> Visited;
7163+
auto Check = [&Visited](QualType T, auto &&Check) -> bool {
7164+
if (!Visited.insert(T->getCanonicalTypeUnqualified()).second)
7165+
return false;
71637166
const CXXRecordDecl *RD =
71647167
T->getBaseElementTypeUnsafe()->getAsCXXRecordDecl();
71657168
if (!RD || !RD->isCompleteDefinition())
@@ -7168,16 +7171,11 @@ void Sema::CheckCompletedCXXClass(Scope *S, CXXRecordDecl *Record) {
71687171
if (!RD->hasConstexprDestructor())
71697172
return false;
71707173

7171-
QualType CanUnqualT = T.getCanonicalType().getUnqualifiedType();
71727174
for (const CXXBaseSpecifier &B : RD->bases())
7173-
if (B.getType().getCanonicalType().getUnqualifiedType() !=
7174-
CanUnqualT &&
7175-
!Check(B.getType(), Check))
7175+
if (!Check(B.getType(), Check))
71767176
return false;
71777177
for (const FieldDecl *FD : RD->fields())
7178-
if (FD->getType().getCanonicalType().getUnqualifiedType() !=
7179-
CanUnqualT &&
7180-
!Check(FD->getType(), Check))
7178+
if (!Check(FD->getType(), Check))
71817179
return false;
71827180
return true;
71837181
};

clang/test/SemaCXX/gh102293.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,20 @@ class quux : quux { // expected-error {{base class has incomplete type}} \
4545
virtual int c();
4646
};
4747
}
48+
49+
// Ensure we don't get infinite recursion from the check, however. See GH141789
50+
namespace GH141789 {
51+
template <typename Ty>
52+
struct S {
53+
Ty t; // expected-error {{field has incomplete type 'GH141789::X'}}
54+
};
55+
56+
struct T {
57+
~T();
58+
};
59+
60+
struct X { // expected-note {{definition of 'GH141789::X' is not complete until the closing '}'}}
61+
S<X> next; // expected-note {{in instantiation of template class 'GH141789::S<GH141789::X>' requested here}}
62+
T m;
63+
};
64+
}

clang/unittests/Format/TokenAnnotatorTest.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3754,6 +3754,13 @@ TEST_F(TokenAnnotatorTest, BraceKind) {
37543754
ASSERT_EQ(Tokens.size(), 9u) << Tokens;
37553755
EXPECT_BRACE_KIND(Tokens[4], BK_BracedInit);
37563756
EXPECT_BRACE_KIND(Tokens[6], BK_BracedInit);
3757+
3758+
Tokens = annotate("auto f1{&T::operator()};");
3759+
ASSERT_EQ(Tokens.size(), 12u) << Tokens;
3760+
EXPECT_BRACE_KIND(Tokens[2], BK_BracedInit);
3761+
// Not TT_FunctionDeclarationName.
3762+
EXPECT_TOKEN(Tokens[6], tok::kw_operator, TT_Unknown);
3763+
EXPECT_BRACE_KIND(Tokens[9], BK_BracedInit);
37573764
}
37583765

37593766
TEST_F(TokenAnnotatorTest, UnderstandsElaboratedTypeSpecifier) {

0 commit comments

Comments
 (0)