[clang] [Clang][Sema] Fix err_constexpr_virtual_base diagnostic so that it only diagnoses on constructors and destructors (PR #163690)

Shafik Yaghmour via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 16 10:02:39 PDT 2025


================
@@ -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);
----------------
shafik wrote:

That is not really my intent but leaving it enabled for C++26 is also not correct. I can leave it enabled for C++26 but it is such a trivial addition it seems silly not to. If the objections are strong I can take out the C++26 check.

https://github.com/llvm/llvm-project/pull/163690


More information about the cfe-commits mailing list