-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[Clang][Sema] Fix err_constexpr_virtual_base diagnostic so that it only diagnoses on constructors and destructors #163690
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
f6bded3
171fadb
7e9ecfc
6ade7a7
0daaba3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1918,23 +1918,22 @@ static bool CheckConstexprMissingReturn(Sema &SemaRef, const FunctionDecl *Dcl); | |
|
|
||
| bool Sema::CheckConstexprFunctionDefinition(const FunctionDecl *NewFD, | ||
| CheckConstexprKind Kind) { | ||
| const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(NewFD); | ||
| if (MD && MD->isInstance()) { | ||
| if ((!getLangOpts().CPlusPlus26 && isa<CXXConstructorDecl>(NewFD)) || | ||
| ((getLangOpts().CPlusPlus20 && !getLangOpts().CPlusPlus26) && | ||
| isa<CXXDestructorDecl>(NewFD))) { | ||
| const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(NewFD); | ||
|
||
| // C++11 [dcl.constexpr]p4: | ||
| // The definition of a constexpr constructor shall satisfy the following | ||
| // constraints: | ||
| // - the class shall not have any virtual base classes; | ||
| // | ||
| // FIXME: This only applies to constructors and destructors, not arbitrary | ||
| // member functions. | ||
| const CXXRecordDecl *RD = MD->getParent(); | ||
| if (RD->getNumVBases()) { | ||
| if (Kind == CheckConstexprKind::CheckValid) | ||
| return false; | ||
|
|
||
| Diag(NewFD->getLocation(), diag::err_constexpr_virtual_base) | ||
| << isa<CXXConstructorDecl>(NewFD) | ||
| << getRecordDiagFromTagKind(RD->getTagKind()) << RD->getNumVBases(); | ||
| << isa<CXXConstructorDecl>(NewFD) | ||
| << getRecordDiagFromTagKind(RD->getTagKind()) << RD->getNumVBases(); | ||
| for (const auto &I : RD->vbases()) | ||
| Diag(I.getBeginLoc(), diag::note_constexpr_virtual_base_here) | ||
| << I.getSourceRange(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to check for C++20? I think some other function will diagnose that destructor can't be constexpr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have explicit constexpr destructor before C++20 and so this would be a spurious diagnostic.