[PATCH] Make noexcept check for constant expressions.

Eelis eelis at eelis.net
Sun Apr 26 05:07:37 PDT 2015


This fixes PR15481.

http://reviews.llvm.org/D9281

Files:
  include/clang/AST/ExprCXX.h
  lib/Sema/SemaExprCXX.cpp
  test/CXX/expr/expr.unary/expr.unary.noexcept/sema.cpp

Index: include/clang/AST/ExprCXX.h
===================================================================
--- include/clang/AST/ExprCXX.h
+++ include/clang/AST/ExprCXX.h
@@ -3340,13 +3340,15 @@
 
 public:
   CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val,
-                  SourceLocation Keyword, SourceLocation RParen)
+                  bool IsConstexpr, SourceLocation Keyword,
+                  SourceLocation RParen)
     : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary,
            /*TypeDependent*/false,
-           /*ValueDependent*/Val == CT_Dependent,
+           /*ValueDependent*/Val == CT_Dependent && !IsConstexpr,
            Val == CT_Dependent || Operand->isInstantiationDependent(),
            Operand->containsUnexpandedParameterPack()),
-      Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen)
+      Value(Val == CT_Cannot || IsConstexpr),
+      Operand(Operand), Range(Keyword, RParen)
   { }
 
   CXXNoexceptExpr(EmptyShell Empty)
Index: lib/Sema/SemaExprCXX.cpp
===================================================================
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -5799,8 +5799,10 @@
   }
 
   CanThrowResult CanThrow = canThrow(Operand);
+  bool IsConstexpr = Operand->isCXX11ConstantExpr(Context);
   return new (Context)
-      CXXNoexceptExpr(Context.BoolTy, Operand, CanThrow, KeyLoc, RParen);
+      CXXNoexceptExpr(Context.BoolTy, Operand, CanThrow, IsConstexpr,
+                      KeyLoc, RParen);
 }
 
 ExprResult Sema::ActOnNoexceptExpr(SourceLocation KeyLoc, SourceLocation,
Index: test/CXX/expr/expr.unary/expr.unary.noexcept/sema.cpp
===================================================================
--- test/CXX/expr/expr.unary/expr.unary.noexcept/sema.cpp
+++ test/CXX/expr/expr.unary/expr.unary.noexcept/sema.cpp
@@ -23,6 +23,7 @@
 void nothrowattr() __attribute__((nothrow));
 void noexcept_true() noexcept;
 void noexcept_false() noexcept(false);
+constexpr int constexprspec() { return 3; }
 
 void call() {
   N(nospec());
@@ -32,6 +33,7 @@
   P(nothrowattr());
   P(noexcept_true());
   N(noexcept_false());
+  P(constexprspec());
 }
 
 void (*pnospec)();

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9281.24442.patch
Type: text/x-patch
Size: 2177 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150426/28068849/attachment.bin>


More information about the cfe-commits mailing list