brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.7 KiB · b07126a Raw
141 lines · cpp
1// RUN: %clang_cc1 -std=c++20 -Wno-unused-value -fsyntax-only -verify %s2 3namespace GH49266 {4struct X {5  X() = default;6  X(X const&) = delete; // expected-note {{'X' has been explicitly marked deleted here}}7};8 9void take_by_copy(auto &...args) {10  [...args = args] {}(); // expected-error {{call to deleted constructor}}11}12 13void take_by_ref(auto &...args) {14  [&...args = args] {}(); // args is passed by reference and not copied.15}16 17void foo() {18  X x;19  take_by_copy(x); // expected-note {{in instantiation of function template specialization}}20  take_by_ref(x);21}22}23 24namespace GH48937 {25 26template <typename... Ts>27consteval int f(Ts... ts) {28  return ([]<Ts a = 42>(){ return a;}, ...)();29}30 31static_assert(f(0, 42) == 42);32 33template <typename Ts>34int g(Ts ts) {35  return ([]<Ts a = 42>(){ return a;}, ...)();  // expected-error {{pack expansion does not contain any unexpanded parameter packs}}36}37 38template <typename... Ts>39int h(Ts... ts) {40  return ([]<Ts a = 42>(){ return a;})();  // expected-error {{expression contains unexpanded parameter pack 'Ts'}}41}42 43}44 45namespace GH63677 {46 47template<typename>48void f() {49  []<typename... Ts>() -> void {50    [...us = Ts{}]{51      (Ts(us), ...);52    };53  }.template operator()<int, int>();54}55 56template void f<int>();57 58template <class>59inline constexpr auto fun =60  []<class... Ts>(Ts... ts) {61    return [... us = (Ts&&) ts]<class Fun>(Fun&& fn) mutable {62      return static_cast<Fun&&>(fn)(static_cast<Ts&&>(us)...);63    };64  };65 66void f() {67  [[maybe_unused]] auto s = fun<int>(1, 2, 3, 4);68}69 70}71 72namespace GH61460 {73 74template<typename... Ts>75void f1(Ts... ts);76 77template <typename... Ts> void g(Ts... p1s) {78  (void)[&](auto... p2s) {79    (80        [&] {81          p1s;82          f1(p1s);83          sizeof(p1s);84          p2s;85        },86        ...);87  };88}89 90template <typename... Ts> void g2(Ts... p1s) {91  (void)[&](auto... p2s) { [&] { p1s; p2s; }; }; // expected-error {{unexpanded parameter pack 'p2s'}}92}93 94void f1() { g(); }95 96} // namespace GH6146097 98namespace GH112352 {99 100template <class>101constexpr bool foo = false;102 103template <int>104constexpr bool bar = false;105 106template <template<class> class>107constexpr bool baz = false;108 109struct S {110  template <typename... Types, int... Values> void foldExpr1() {111    (void)[]<int... Is> {112      ([] {113        Is;114        // Propagate up the flag ContainsUnexpandedParameterPack from VarDecl.115        S var(foo<Types>);116        foo<Types>;117        bar<Values>;118        int a = Values;119      } &&120       ...);121    };122  }123 124  template <template<class> class... TTPs> void foldExpr2() {125    (void)[]<int... Is> {126      ([] {127        Is;128        baz<TTPs>;129        TTPs<int> D;130      } && ...);131    };132  }133};134 135void use() {136  S().foldExpr1();137  S().foldExpr2();138}139 140} // namespace GH112352141