[clang] [clang][AST] Fix crash on labeled break/continue within switch condition statement expression (PR #228655)

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 6 04:52:02 PDT 2026


================
@@ -1532,10 +1532,11 @@ const Stmt *LabelStmt::getInnermostLabeledStmt() const {
   return S;
 }
 
-const Stmt *LoopControlStmt::getNamedLoopOrSwitch() const {
-  if (!hasLabelTarget())
-    return nullptr;
-  return getLabelDecl()->getStmt()->getInnermostLabeledStmt();
+const std::optional<Stmt *> LoopControlStmt::getNamedLoopOrSwitch() const {
----------------
tbaederr wrote:

The problem with `std::optional<ptr>` is that you now have _two_ invalid states. We had problems in the past where we returned a non-std::nullopt optional that still wrapped a null pointer.

https://github.com/llvm/llvm-project/pull/228655


More information about the cfe-commits mailing list