[PATCH] D74238: [clang] Improve diagnostic note for implicit conversion sequences that would work if more than one implicit user-defined conversion were allowed.

Richard Smith - zygoloid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 16 17:31:04 PDT 2020


rsmith added a comment.

How do you defend against attempting an infinite sequence of user-defined conversion? For example:

  template<int N> struct X {
      operator X<N + 1>();
  };
  X<0> x0 = X<1>();



================
Comment at: clang/lib/Sema/SemaOverload.cpp:7333
+    // Save the bad conversion in the candidate, for later use by diagnostics.
+    Candidate.Conversions[0].setBad(BadConversionSequence::no_conversion,
+                                    From, CallResultType);
----------------
`Conversions[0]` is for the conversion of the object argument to the implicit object parameter. This should be stored in `Candidate.FinalConversion` instead.


================
Comment at: clang/lib/Sema/SemaOverload.cpp:11349
+  if (Cand->FailureKind == ovl_fail_bad_final_conversion
+      && Cand->Conversions[0].isBad()) {
+    SetAsMultipleUserDefined(Cand->Conversions[0]);
----------------
`&&` goes on the previous line (here and below).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74238





More information about the cfe-commits mailing list