[clang] af90e7c - [Clang] Fix an assertion in expression recovery (#112888)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 18 06:42:59 PDT 2024
Author: cor3ntin
Date: 2024-10-18T15:42:54+02:00
New Revision: af90e7c5161de9a36af768dd5c9d73464e0eed64
URL: https://github.com/llvm/llvm-project/commit/af90e7c5161de9a36af768dd5c9d73464e0eed64
DIFF: https://github.com/llvm/llvm-project/commit/af90e7c5161de9a36af768dd5c9d73464e0eed64.diff
LOG: [Clang] Fix an assertion in expression recovery (#112888)
Explicit object member function calls are not modelled as member calls
Fixes #112559
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/AST/Expr.cpp
clang/test/SemaCXX/cxx2b-deducing-this.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b34da2d755704a..b7a6ace8bb895d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -419,7 +419,7 @@ Improvements to Clang's diagnostics
- The warning for an unsupported type for a named register variable is now phrased ``unsupported type for named register variable``,
instead of ``bad type for named register variable``. This makes it clear that the type is not supported at all, rather than being
suboptimal in some way the error fails to mention (#GH111550).
-
+
- Clang now emits a ``-Wdepredcated-literal-operator`` diagnostic, even if the
name was a reserved name, which we improperly allowed to suppress the
diagnostic.
@@ -538,6 +538,7 @@ Bug Fixes to C++ Support
certain situations. (#GH47400), (#GH90896)
- Fix erroneous templated array size calculation leading to crashes in generated code. (#GH41441)
- During the lookup for a base class name, non-type names are ignored. (#GH16855)
+- Fix a crash when recovering an invalid expression involving an explicit object member conversion operator. (#GH112559)
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 9ecbf121e3fc0d..66db6263cb1bd2 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -1989,7 +1989,7 @@ Expr *CastExpr::getSubExprAsWritten() {
SubExpr = IgnoreExprNodes(cast<CXXConstructExpr>(SubExpr)->getArg(0),
ignoreImplicitSemaNodes);
} else if (E->getCastKind() == CK_UserDefinedConversion) {
- assert((isa<CXXMemberCallExpr>(SubExpr) || isa<BlockExpr>(SubExpr)) &&
+ assert((isa<CallExpr, BlockExpr>(SubExpr)) &&
"Unexpected SubExpr for CK_UserDefinedConversion.");
if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SubExpr))
SubExpr = MCE->getImplicitObjectArgument();
diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
index 2a984a75f37d21..520052a89d1840 100644
--- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp
+++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
@@ -1097,3 +1097,20 @@ struct C4 {
// expected-warning {{volatile-qualified parameter type 'const volatile C4' is deprecated}}
};
}
+
+
+namespace GH112559 {
+struct Wrap {};
+struct S {
+ constexpr operator Wrap (this const S& self) {
+ return Wrap{};
+ };
+ constexpr int operator <<(this Wrap self, int i) {
+ return 0;
+ }
+};
+// Purposefully invalid expression to check an assertion in the
+// expression recovery machinery.
+static_assert((S{} << 11) == a);
+// expected-error at -1 {{use of undeclared identifier 'a'}}
+}
More information about the cfe-commits
mailing list