brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.0 KiB · 00ba291 Raw
134 lines · cpp
1// RUN: %clang_cc1 -std=c++03 -verify -Dstatic_assert=_Static_assert -Wno-c++11-extensions -Wno-c++14-extensions -Wno-c++17-extensions -Wno-c++20-extensions %s2// RUN: %clang_cc1 -std=c++11 -verify=expected,cxx11,cxx11-cxx14 -Wno-c++20-extensions -Wno-c++17-extensions -Wno-c++14-extensions  %s3// RUN: %clang_cc1 -std=c++14 -verify=expected,cxx11-cxx14,cxx14 -Wno-c++20-extensions -Wno-c++17-extensions %s4// RUN: %clang_cc1 -std=c++17 -verify -Wno-c++20-extensions %s5// RUN: %clang_cc1 -std=c++20 -verify %s6 7template<typename, typename>8inline const bool is_same = false;9 10template<typename T>11inline const bool is_same<T, T> = true;12 13template<typename T>14struct DummyTemplate { };15 16void func() {17  auto L0 = []<typename T>(T arg) {18    static_assert(is_same<T, int>); // expected-error {{static assertion failed}}19  };20  L0(0);21  L0(0.0); // expected-note {{in instantiation}}22 23  auto L1 = []<int I> {24    static_assert(I == 5); // expected-error {{static assertion failed}}25  };26  L1.operator()<5>();27  L1.operator()<6>(); // expected-note {{in instantiation}}28 29  auto L2 = []<template<typename> class T, class U>(T<U> &&arg) {30    static_assert(is_same<T<U>, DummyTemplate<float> >); // // expected-error {{static assertion failed}}31  };32  L2(DummyTemplate<float>());33  L2(DummyTemplate<double>()); // expected-note {{in instantiation}}34}35 36template<typename T> // expected-note {{declared here}}37struct ShadowMe {38  void member_func() {39    auto L = []<typename T> { }; // expected-error {{'T' shadows template parameter}}40  }41};42 43#if __cplusplus >= 201102L44template<typename T>45constexpr T outer() {46  // FIXME: The C++11 error seems wrong47  return []<T x>() { return x; }.template operator()<123>(); // expected-error {{no matching member function}}  \48                                                                expected-note {{candidate template ignored}}    \49        cxx11-note {{non-literal type '<dependent type>' cannot be used in a constant expression}} \50        cxx14-note {{non-literal type}}51}52static_assert(outer<int>() == 123); // cxx11-cxx14-error {{not an integral constant expression}} cxx11-cxx14-note {{in call}}53template int *outer<int *>(); // expected-note {{in instantiation}}54#endif55 56#if __cplusplus >= 202002L57namespace GH62611 {58template <auto A = [](auto x){}>59struct C {60  static constexpr auto B = A;61};62 63int test() {64  C<>::B(42);65}66 67namespace AutoParam68{69template <auto A = [](auto x) { return x;}>70auto B = A;71static_assert(B<>(42) == 42);72}73 74namespace TypeParam75{76template <typename T = decltype([](auto x) {return x;})>77auto B = T{};78static_assert(B<>(42) == 42);79}80 81}82 83namespace GH64689 {84void f();85void foo() {86  []<typename T>(int)87    noexcept(requires(int t) { f(); })88    -> decltype(requires(int t) { f(); })89    requires requires(int t) { f(); }90  {return {};}.operator()<int>(0);91  [](auto)92    noexcept(requires(int t) { f(); })93    -> decltype(requires(int t) { f(); })94    requires requires(int t) { f(); }95  {return {};}(1);96}97 98}99#endif100 101#if __cplusplus >= 202002L102namespace {103struct S {};104constexpr S gs;105void f() {106  constexpr int x{};107  const int y{};108  auto b = []<int=x, int=y>{};109  using A = decltype([]<int=x>{});110 111  int z; // expected-note {{'z' declared here}}112  auto c = []<int t=z>{113    // expected-error@-1 {{no matching function for call to object of type}} \114    // expected-error@-1 {{variable 'z' cannot be implicitly captured in a lambda with no capture-default specified}} \115    // expected-note@-1 {{lambda expression begins here}} \116    // expected-note@-1 4{{capture}} \117    // expected-note@-1 {{candidate template ignored: substitution failure: reference to local variable 'z' declared in enclosing function}}118    return t;119  }();120 121  auto class_type_global = []<S=gs>{};122 123  static constexpr S static_s;124  auto class_type_static = []<S=static_s>{};125 126  constexpr S s;  // expected-note {{'s' declared here}}127  auto class_type = []<S=s>{};128  // expected-error@-1 {{variable 's' cannot be implicitly captured in a lambda with no capture-default specified}} \129  // expected-note@-1 {{lambda expression begins here}} \130  // expected-note@-1 4{{capture}}131}132}133#endif134