Skip to content

Commit bbb39f2

Browse files
committed
[Clang] Fix an assertion in expression recovery
Explicit object member function calls are not modelled as member calls Fixes #112559
1 parent 5f7502b commit bbb39f2

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
@@ -418,7 +418,7 @@ Improvements to Clang's diagnostics
418418
- The warning for an unsupported type for a named register variable is now phrased ``unsupported type for named register variable``,
419419
instead of ``bad type for named register variable``. This makes it clear that the type is not supported at all, rather than being
420420
suboptimal in some way the error fails to mention (#GH111550).
421-
421+
422422
- Clang now emits a ``-Wdepredcated-literal-operator`` diagnostic, even if the
423423
name was a reserved name, which we improperly allowed to suppress the
424424
diagnostic.
@@ -537,6 +537,7 @@ Bug Fixes to C++ Support
537537
certain situations. (#GH47400), (#GH90896)
538538
- Fix erroneous templated array size calculation leading to crashes in generated code. (#GH41441)
539539
- During the lookup for a base class name, non-type names are ignored. (#GH16855)
540+
- Fix a crash when recovering an invalid expression involving an explicit object member conversion operator. (#GH112559)
540541

541542
Bug Fixes to AST Handling
542543
^^^^^^^^^^^^^^^^^^^^^^^^^

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)