Commit bfd64335 authored by Richard Smith's avatar Richard Smith
Browse files

Fix merging of two arity-only pack deductions.

If we deduced the arity of a pack in two different ways, but didn't
deduce an element of the pack in either of those deductions, we'd merge
that element to produce a null template argument, which we'd incorrectly
interpret as the merge having failed.

Testcase based on one supplied by Hubert Tong.
parent a19461d9
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -355,7 +355,7 @@ checkDeducedTemplateArguments(ASTContext &Context,
      TemplateArgument Merged = checkDeducedTemplateArguments(
          Context, DeducedTemplateArgument(*XA, X.wasDeducedFromArrayBound()),
          DeducedTemplateArgument(*YA, Y.wasDeducedFromArrayBound()));
      if (Merged.isNull())
      if (Merged.isNull() && !(XA->isNull() && YA->isNull()))
        return DeducedTemplateArgument();
      NewPack.push_back(Merged);
    }
+16 −0
Original line number Diff line number Diff line
@@ -581,3 +581,19 @@ namespace PR44890 {
    return w.get<0>();
  }
}

namespace merge_size_only_deductions {
#if __cplusplus >= 201703L
  // Based on a testcase by Hubert Tong.
  template<typename ...> struct X {};
  template<auto ...> struct Y {};
  template<typename T> struct id { using Type = T; };

  template<typename ...T, typename T::Type ...V>
    int f(X<char [V] ...>, Y<V ...>, X<T ...>);

  using size_t = __SIZE_TYPE__;
  int a = f(X<char [1], char [2]>(), Y<(size_t)1, (size_t)2>(), X<id<size_t>, id<size_t>>());
  int b = f(X<char [1], char [2]>(), Y<1, 2>(), X<id<int>, id<int>>());
#endif
}