================
@@ -3109,8 +3109,11 @@ class LoopControlStmt : public Stmt {
   void setLabelDecl(LabelDecl *S) { TargetLabel = S; }
 
   /// If this is a named break/continue, get the loop or switch statement
-  /// that this targets.
-  const Stmt *getNamedLoopOrSwitch() const;
+  /// that this targets. May return std::nullopt if the loop has a label
+  /// but its LabelStmt has not yet been created. Otherwise, Stmt * will
+  /// be a non-null pointer to the loop or switch statement under the label.
+  /// \pre `isNamed()`
+  const std::optional<Stmt *> getNamedLoopOrSwitch() const;
----------------
Expertcoderz wrote:

> Ok, if this now asserts `isNamed()`, then I don’t think we need the 
> `std::optional` anymore. Just have it return a null `Stmt*` when appropriate

Alright, I've reverted the change. Basically, we now only support calling 
`getNamedLoopOrSwitch()` for named break/continue statements (and even then it 
may still return null, which is the responsibility of callers to check). The 
comment on the function should be clear enough about that behavior, but if it's 
not then let me know and I will improve it.

https://github.com/llvm/llvm-project/pull/228655
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to