[cfe-dev] parse C++ throw

Chris Lattner clattner at apple.com
Sun Feb 24 20:24:12 PST 2008

On Feb 24, 2008, at 4:20 PM, Mike Stump wrote:

> Here is a patch to add parsing support for C++ throw expressions.

Wow, very nice.  You did a great job, I just have some minor nit-picky  
comments below.

> I tested to ensure this would be safe for C, it is, as throw isn't  
> only recognized when doing C++.


> Did I do the type of the throw expression correctly?  I copied the  
> way true and false were done.

I'm surprised that throw is an expression, you learn something new  
every day.  Your code looks great.

+/// PraseThrowExpression - THis handles the C++ throw expression.

Minor typos here: prase -> parse, THis -> This


+  virtual ExprResult ActOnCXXThrow(SourceLocation OpLoc,
+				   ExprTy *Op = 0) {

+  ///  CXXThrowExpr - [C++ 15] C++ Throw Expression.
+  ///
+  class CXXThrowExpr : public Expr {
+    Expr *Op;
+    SourceLocation Loc;

I'd suggest renaming Loc -> ThrowLoc to be more explicit about what it  
is the location of.  In the comment, please say explicitly that this  
handles two cases "throw;" in which case the operand is null, and  
"throw x;" in which case x is the operand.

This method:
+    Expr *getSubExpr() const { return Op; }

Should be replaced with these two:
+    const Expr *getSubExpr() const { return Op; }
+    Expr *getSubExpr() { return Op; }

Please resubmit the tweaked patch and I'll apply, thanks Mike!


More information about the cfe-dev mailing list