This is an archive of the discontinued LLVM Phabricator instance.

C++11: noexcept should check whether the expression is a constant expression
AbandonedPublic

Authored by ismailp on Mar 13 2013, 8:15 AM.

Details

Reviewers
rsmith
Summary

This is an attempt to fix PR15481.

noexcept operator currently ignores whether given call is a constant expression. The patch adds a check whether given call expression is a constant expression. If so, canCalleeThrow returns CT_Cannot.

Diff Detail

Event Timeline

Generally speaking, I'd prefer for us to implement the resolution of core issue 1351 rather than patching up our implementation of the broken C++11 rules. However, even the core issue 1351 rules are broken when the callee is a function pointer...

lib/Sema/SemaExceptionSpec.cpp
825–831

This is not right. We should try to evaluate the call even if we can't resolve it to a particular declaration.

850–851

Likewise, this should attempt evaluation (although it's not clear to me how this could happen...).

864–867

Please reverse the order of these checks; FT->isNothrow will typically be a much cheaper test.

I have read the resolution for the issue 1351, and I was curious about aligning this with the removal of dynamic exception specifications as well. Could you please confirm whether I understood this part correctly; given the example in issue 1351, in the move constructor declaration, "noexcept" is represented with an empty set:
B(B&&, int = (throw Y(), 0)) throw(Y) noexcept;
The union of set of potential exceptions is: {Y} U {Y} U {} = {Y};
Likewise, if it was:
B(B&&, int = (throw Y(), 0)) throw(Z) noexcept;
The union of set of potential exceptions: {Y} U {Z} U {} = {Y, Z}

Could you please explain the purpose of having throw(E) and noexcept on the same declarator? I understand throw(E) and noexcept(false) would be compatible.

ismailp abandoned this revision.Mar 27 2013, 1:59 AM