[PATCH] D56731: Add -Wimplicit-ctad warning to diagnose CTAD on types with no user defined deduction guides.
Eric Fiselier via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 15 21:21:41 PST 2019
EricWF marked 10 inline comments as done.
EricWF added inline comments.
================
Comment at: include/clang/Basic/DiagnosticSemaKinds.td:2129
+def warn_class_template_argument_deduction_no_user_defined_guides : Warning<
+ "using class template argument deduction for %0 that has no user-defined deduction guides" >,
+ InGroup<ImplicitCTADUsage>, DefaultIgnore;
----------------
rsmith wrote:
> gromer wrote:
> > I'd prefer a phrasing more along the lines of "using class template argument deduction for %0 that might not intentionally support it". That gives us more room to do things like add an attribute later if necessary, and it helps the user understand why this warning indicates a potential problem.
> I like that approach; something like "using class template argument deduction for %0 that might not intend to support it" -- or perhaps more directly "%0 might not intend to support class template argument deduction" -- along with a note describing how to syntactically suppress the warning (w"add a deduction guide to suppress this warning" or "use the [[clang::ctad]] attribute to suppress this warning" or whatever we decide is best).
This sounds like a reasonable change to me. Done.
I'm not sure an attribute is needed at this point; AFAIK there is no case where a user defined guide can't be added. Even if it's just a dummy guide to suppress the warning. For example:
```
struct allow_ctad_t {
allow_ctad_t() = delete;
};
template <class T>
struct TestSuppression {
TestSuppression(int, T) {}
};
TestSuppression(allow_ctad_t) -> TestSuppression<void>;
```
Also, before we add an attribute, we want to be sure that it's not harmful to allowing users to suppress the warning without actually addressing the root problem (tha implicit CTAD results are often surprising). I would like to see real world examples of types that don't need user-defined guides to work.
================
Comment at: lib/Sema/SemaInit.cpp:9287
+ HasUserDeclaredDeductionGuideCandidate |= !GD->isImplicit();
+
----------------
rsmith wrote:
> Quuxplusone wrote:
> > Nitpick: I don't know if this is LLVM style, but I wish this were written as
> >
> > if (!GD->isImplicit())
> > HasUserDeclaredDeductionGuideCandidate = true;
> >
> > for clarity. Also, is it "user-defined" (per the error message) or "user-declared" (per the name of this variable)?
> Formally, it's actually just "any deduction guides". Constructors aren't transformed into deduction guides; rather, deduction guides and constructors both form candidates for CTAD. So `HasAnyDeductionGuides` would work. (I also think we should omit the "candidates", because we don't care whether any deduction guides were candidates for this particular overload resolution, only whether there are any at all -- if we're excluding explicit deduction guides and the only deduction guides are explicit, we still want to (and do!) suppress the warning.
I changed the name to `HasAnyDeductionGuides`.
Otherwise, I think I've address all of the cases in your comment.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D56731/new/
https://reviews.llvm.org/D56731
More information about the cfe-commits
mailing list