[PATCH] D55097: [constexpr][c++2a] Try-catch blocks in constexpr functions

Erik Pilkington via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 4 13:51:15 PST 2018


erik.pilkington added a comment.

Hi Bruno, thanks for working on this!



================
Comment at: include/clang/Basic/DiagnosticSemaKinds.td:2370
+  "use of this statement in a constexpr %select{function|constructor}0 "
+  "is incompatible with C++ standards before C++20">,
+  InGroup<CXXPre2aCompat>, DefaultIgnore;
----------------
I guess this should technically be C++2a


================
Comment at: include/clang/Basic/DiagnosticSemaKinds.td:2431
+  "function try block in constexpr %select{function|constructor}0 is "
+  "incompatible with C++ standards before C++20">,
+  InGroup<CXXPre2aCompat>, DefaultIgnore;
----------------
(ditto)


================
Comment at: lib/Sema/SemaDeclCXX.cpp:1913-1916
+  case Stmt::CXXCatchStmtClass:
+    // In case we got a valid constexpr try block, the catch block can be
+    // ignored since it will never be evaluated in a constexpr context.
+    return true;
----------------
I think we still need to check out the catch stmt (even if it'll never be evaluated) to make sure that it doesn't have any prohibited statements. i.e., we should error here:
```
constexpr int f() { 
  try { return 0; }
  catch (...) {
    merp: goto merp;
  }
}
```
But I believe that this patch will accept this.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55097/new/

https://reviews.llvm.org/D55097





More information about the cfe-commits mailing list