[PATCH] D113518: [clang][Sema] Create delegating constructors even in templates

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 29 12:07:40 PST 2021


aaron.ballman added inline comments.


================
Comment at: clang/lib/Sema/SemaDeclCXX.cpp:4524-4525
   if (!Dependent) {
-    if (Context.hasSameUnqualifiedType(QualType(ClassDecl->getTypeForDecl(),0),
-                                       BaseType))
+    if (Delegating)
       return BuildDelegatingInitializer(BaseTInfo, Init, ClassDecl);
 
----------------
Looking at the source for `BuildDelegatingInitializer()`, it looks like we should still be able to call this in a dependent context. In fact, it has a fixme comment specifically about that:
```
    // If we are in a dependent context, template instantiation will
    // perform this type-checking again. Just save the arguments that we
    // received in a ParenListExpr.
    // FIXME: This isn't quite ideal, since our ASTs don't capture all
    // of the information that we have about the base
    // initializer. However, deconstructing the ASTs is a dicey process,
    // and this approach is far more likely to get the corner cases right.
```
I'm wondering if the better fix here is to hoist the delegation check out of the `if (!Dependent)`. Did you try that and run into issues?


================
Comment at: clang/lib/Sema/SemaDeclCXX.cpp:5071
 
-  if (CXXDestructorDecl *Dtor = LookupDestructor(Constructor->getParent())) {
-    MarkFunctionReferenced(Initializer->getSourceLocation(), Dtor);
-    DiagnoseUseOfDecl(Dtor, Initializer->getSourceLocation());
-  }
+  if (!Constructor->isDependentContext()) {
+    if (CXXDestructorDecl *Dtor = LookupDestructor(Constructor->getParent())) {
----------------
Can you explain why this change was needed?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113518/new/

https://reviews.llvm.org/D113518



More information about the cfe-commits mailing list