[clang] [clang] Implement P2582R1: CTAD from inherited constructors (PR #98788)

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 22 02:38:48 PDT 2024


================
@@ -936,19 +940,21 @@ Expr *buildIsDeducibleConstraint(Sema &SemaRef,
         Context.DeclarationNames.getCXXDeductionGuideName(AliasTemplate));
   };
 
+  TemplateDecl *TD = DeducingTemplate ? DeducingTemplate : AliasTemplate;
+
   SmallVector<TypeSourceInfo *> IsDeducibleTypeTraitArgs = {
       Context.getTrivialTypeSourceInfo(
           Context.getDeducedTemplateSpecializationType(
-              TemplateName(AliasTemplate), /*DeducedType=*/QualType(),
+              TemplateName(TD), /*DeducedType=*/QualType(),
----------------
hokein wrote:

```cpp
template <typename T> struct B {
  B(T);
};
template <typename T> struct C : public B<T> {
  using B<T>::B;
};

C c(1);

// implicit code
// template <typename> class CC;
//
// template <typename T>
// class CC<B<T>> {
// public:
//    typedef C<T> type;
// };
```
If I read the code correctly,  we will build the `__is_deducible(C, typename CC<B<T>>::type)` for the deduction guide of `C` (`auto (T) -> typename CC<B<T>>::type`).  I'm not sure this is correct.

Intuitively, this constraint is not necessary, if `CC<B<T>>::type` is valid, it must be the type of `C<T>`, then `is_deducible(C, C<T>)` is always true.

Unfortunately, the standard doesn't specify the transformation of the associated constraint (oversight?). If we only replace the return type, then the constraint will be `is_deducible(B,  typename CC<B<T>>::type)`  which is always false. 

Perhaps we should always drop the `is_deducible` constraint for this case.

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


More information about the cfe-commits mailing list