Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #45: Implement is_noexcept meta function #56

Open
wants to merge 11 commits into
base: p2996
Choose a base branch
from

Conversation

delimbetov
Copy link

Issue number of the reported bug or feature request: #45

Describe your changes
Added is_noexcept as per P2996r3 spec.
The function checks for noexcept on:

  1. (virtual) Method and it's type
  2. Template method instantiation and it's type
  3. Function and it's type
  4. Function template instantiation and it's type
  5. Lambda and it's type

For everything else it returns false.

Testing performed
Tests added to libcxx to cover all supported scenarios.

libcxx/include/experimental/meta Outdated Show resolved Hide resolved
@@ -1006,6 +1011,37 @@ bool isAccessible(Sema &S, DeclContext *AccessDC, NamedDecl *D) {
return Result;
}

template <typename T>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be a template? Seems like T will always be CXXMethodDecl.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is CXXMethodDecl only in the "T->isRecordType()" branch. For "T->isFunctionPrototype()" it is FunctionProtoType.

I guess I could try extracting FunctionProtoType from CXXMethodDecl and make this function non-template. Would that be better if that's possible to do?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh I see, sorry about that. How about we just take the ExceptionSpecificationType, and inline this as a lambda in the isFunctionOrLambdaNoexcept function?

static bool isFunctionOrLambdaNoexcept(const QualType QT) {
  static auto isExceptionSpecNoexcept = [](ExceptionSpecificationType) {
    switch (...) // ...
  }
  
  if (auto *FPT = dyn_cast<FunctionProtoType>(QT)) {
    return isExceptionSpecNoexcept(FPT->getExceptionSpecType());
  } else if (auto *RT = dyn_cast<RecordType>(QT)) {
    auto *RDecl = cast<CXXRecordDecl>(RT->getDecl());
    if (RDecl->isLambda() && !RDecl->isGenericLambda())
      return isExceptionSpecNoexcept(
          RDecl->getLambdaCallOperator()->getExceptionSpecType());
  }
  return false;
}

What do you think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, done

@delimbetov delimbetov requested a review from katzdm June 13, 2024 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants