[PATCH] D113517: Correct handling of the 'throw()' exception specifier in C++17.

Arthur O'Dwyer via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 10 08:25:19 PST 2021

Quuxplusone added a comment.

Peanut gallery says: It seems like `Proto->canThrow()` is already returning the correct answer for C++17-and-later: a function declared `throw()` cannot throw. So from the POV of C++17-and-later, this could be a simple patch:

  - if (isNoexceptExceptionSpec(EST) && Proto->canThrow() == CT_Cannot) {
  + if (Proto->canThrow() == CT_Cannot) {

and the only reason we can't do this is because C++14-and-earlier needs a different behavior.

Meanwhile, it looks as if every other use of `isNoexceptExceptionSpec` (or its inverse `isDynamicExceptionSpec`) is related to pretty-printing the exception specification, and isn't used for semantics at all.
Perhaps a cleaner way to preserve the current special case for C++14-and-earlier is to add a "language version" parameter to `canThrow`, and/or introduce an `isEssentiallyNoexcept()` helper:

  - if (isNoexceptExceptionSpec(EST) && Proto->canThrow() == CT_Cannot) {
  + if (Proto->isEssentiallyNoexcept(getLangOpts())) {

  rG LLVM Github Monorepo



More information about the cfe-commits mailing list