Skip to content

Commit af90e7c

Browse files
authored
[Clang] Fix an assertion in expression recovery (llvm#112888)
Explicit object member function calls are not modelled as member calls Fixes llvm#112559
1 parent b7bc1d0 commit af90e7c

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ Improvements to Clang's diagnostics
419419
- The warning for an unsupported type for a named register variable is now phrased ``unsupported type for named register variable``,
420420
instead of ``bad type for named register variable``. This makes it clear that the type is not supported at all, rather than being
421421
suboptimal in some way the error fails to mention (#GH111550).
422-
422+
423423
- Clang now emits a ``-Wdepredcated-literal-operator`` diagnostic, even if the
424424
name was a reserved name, which we improperly allowed to suppress the
425425
diagnostic.
@@ -538,6 +538,7 @@ Bug Fixes to C++ Support
538538
certain situations. (#GH47400), (#GH90896)
539539
- Fix erroneous templated array size calculation leading to crashes in generated code. (#GH41441)
540540
- During the lookup for a base class name, non-type names are ignored. (#GH16855)
541+
- Fix a crash when recovering an invalid expression involving an explicit object member conversion operator. (#GH112559)
541542

542543
Bug Fixes to AST Handling
543544
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/AST/Expr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1989,7 +1989,7 @@ Expr *CastExpr::getSubExprAsWritten() {
19891989
SubExpr = IgnoreExprNodes(cast<CXXConstructExpr>(SubExpr)->getArg(0),
19901990
ignoreImplicitSemaNodes);
19911991
} else if (E->getCastKind() == CK_UserDefinedConversion) {
1992-
assert((isa<CXXMemberCallExpr>(SubExpr) || isa<BlockExpr>(SubExpr)) &&
1992+
assert((isa<CallExpr, BlockExpr>(SubExpr)) &&
19931993
"Unexpected SubExpr for CK_UserDefinedConversion.");
19941994
if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SubExpr))
19951995
SubExpr = MCE->getImplicitObjectArgument();

clang/test/SemaCXX/cxx2b-deducing-this.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,3 +1097,20 @@ struct C4 {
10971097
// expected-warning {{volatile-qualified parameter type 'const volatile C4' is deprecated}}
10981098
};
10991099
}
1100+
1101+
1102+
namespace GH112559 {
1103+
struct Wrap {};
1104+
struct S {
1105+
constexpr operator Wrap (this const S& self) {
1106+
return Wrap{};
1107+
};
1108+
constexpr int operator <<(this Wrap self, int i) {
1109+
return 0;
1110+
}
1111+
};
1112+
// Purposefully invalid expression to check an assertion in the
1113+
// expression recovery machinery.
1114+
static_assert((S{} << 11) == a);
1115+
// expected-error@-1 {{use of undeclared identifier 'a'}}
1116+
}

0 commit comments

Comments
 (0)