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

Oliver Hunt via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 6 22:05:35 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 {
----------------
ojhunt wrote:

I agree - I've used `optional<T*>` in a few places, but we really need {invalid, none, value} rather than `has_value()==false` implies error. 

I think such a type would be useful, but I think making that part of this PR is clearly overkill. The current query + check however seems particularly bad as well: simply null checking the return is easy but is incorrect, etc

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


More information about the cfe-commits mailing list