diff options
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/Parser/cxx0x-lambda-expressions.cpp | 2 | ||||
-rw-r--r-- | clang/test/SemaCXX/builtin-assume-aligned.cpp | 13 | ||||
-rw-r--r-- | clang/test/SemaCXX/diagnose_if.cpp | 27 | ||||
-rw-r--r-- | clang/test/SemaCXX/lambda-expressions.cpp | 30 | ||||
-rw-r--r-- | clang/test/SemaTemplate/concepts.cpp | 71 |
5 files changed, 135 insertions, 8 deletions
diff --git a/clang/test/Parser/cxx0x-lambda-expressions.cpp b/clang/test/Parser/cxx0x-lambda-expressions.cpp index f90f8ce..5b57c7f 100644 --- a/clang/test/Parser/cxx0x-lambda-expressions.cpp +++ b/clang/test/Parser/cxx0x-lambda-expressions.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -Wno-unused-value -verify=expected,cxx14ext,cxx17ext,cxx20ext,cxx23ext -std=c++03 -Wno-c99-designator %s -Wno-c++11-extensions +// RUN: %clang_cc1 -fsyntax-only -Wno-unused-value -verify=expected,cxx14ext,cxx17ext,cxx20ext,cxx23ext -std=c++03 -Wno-c99-designator %s -Wno-c++11-extensions -Wno-local-type-template-args // RUN: %clang_cc1 -fsyntax-only -Wno-unused-value -verify=expected,cxx14ext,cxx17ext,cxx20ext,cxx23ext -std=c++11 -Wno-c99-designator %s // RUN: %clang_cc1 -fsyntax-only -Wno-unused-value -verify=expected,cxx17ext,cxx20ext,cxx23ext -std=c++14 -Wno-c99-designator %s // RUN: %clang_cc1 -fsyntax-only -Wno-unused-value -verify=expected,cxx20ext,cxx23ext -std=c++17 -Wno-c99-designator %s diff --git a/clang/test/SemaCXX/builtin-assume-aligned.cpp b/clang/test/SemaCXX/builtin-assume-aligned.cpp index 48bd841..30296c7 100644 --- a/clang/test/SemaCXX/builtin-assume-aligned.cpp +++ b/clang/test/SemaCXX/builtin-assume-aligned.cpp @@ -47,3 +47,16 @@ constexpr void *s1 = __builtin_assume_aligned(x, 32); constexpr void *s2 = __builtin_assume_aligned(x, 32, 5); constexpr void *s3 = __builtin_assume_aligned(x, 32, -1); + +constexpr int add(int a, int b) { + return a+b; +} +constexpr void *c1 = __builtin_assume_aligned(p, add(1,1)); +constexpr void *c2 = __builtin_assume_aligned(p, add(2,1)); // expected-error {{not a power of 2}} + +constexpr long kAlignment = 128; +long AllocateAlignedBytes_payload; +void AllocateAlignedBytes() { + void *m = __builtin_assume_aligned( + reinterpret_cast<void *>(AllocateAlignedBytes_payload), kAlignment); +} diff --git a/clang/test/SemaCXX/diagnose_if.cpp b/clang/test/SemaCXX/diagnose_if.cpp index 1b9e660..0af8bb7 100644 --- a/clang/test/SemaCXX/diagnose_if.cpp +++ b/clang/test/SemaCXX/diagnose_if.cpp @@ -1,5 +1,7 @@ // RUN: %clang_cc1 %s -verify -fno-builtin -std=c++14 +// RUN: %clang_cc1 %s -verify -fno-builtin -std=c++20 -verify=expected,cxx20 // RUN: %clang_cc1 %s -verify -fno-builtin -std=c++14 -fexperimental-new-constant-interpreter +// RUN: %clang_cc1 %s -verify -fno-builtin -std=c++20 -verify=expected,cxx20 -fexperimental-new-constant-interpreter #define _diagnose_if(...) __attribute__((diagnose_if(__VA_ARGS__))) @@ -665,3 +667,28 @@ void run() { switch (constexpr Foo i = 2) { default: break; } // expected-error{{oh no}} } } + +namespace GH160776 { + +struct ConstructorTemplate { + template <class T> + explicit ConstructorTemplate(T x) + _diagnose_if(sizeof(T) == sizeof(char), "oh no", "error") {} // expected-note {{diagnose_if}} + + template <class T> +#if __cplusplus >= 202002L + requires (sizeof(T) == 1) // cxx20-note {{evaluated to false}} +#endif + operator T() _diagnose_if(sizeof(T) == sizeof(char), "oh no", "error") { // expected-note {{diagnose_if}} \ + // cxx20-note {{constraints not satisfied}} + return T{}; + } +}; + +void run() { + ConstructorTemplate x('1'); // expected-error {{oh no}} + char y = x; // expected-error {{oh no}} + int z = x; // cxx20-error {{no viable conversion}} +} + +} diff --git a/clang/test/SemaCXX/lambda-expressions.cpp b/clang/test/SemaCXX/lambda-expressions.cpp index 8ea8e32..f9d7cfc 100644 --- a/clang/test/SemaCXX/lambda-expressions.cpp +++ b/clang/test/SemaCXX/lambda-expressions.cpp @@ -149,7 +149,8 @@ namespace PR12031 { void f(int i, X x); void g() { const int v = 10; - f(v, [](){}); + f(v, [](){}); // cxx03-warning {{template argument uses local type}} \ + // cxx03-note {{while substituting}} } } @@ -572,26 +573,37 @@ namespace PR27994 { struct A { template <class T> A(T); }; template <class T> -struct B { +struct B { // #PR27994_B int x; - A a = [&] { int y = x; }; - A b = [&] { [&] { [&] { int y = x; }; }; }; - A d = [&](auto param) { int y = x; }; // cxx03-cxx11-error {{'auto' not allowed in lambda parameter}} - A e = [&](auto param) { [&] { [&](auto param2) { int y = x; }; }; }; // cxx03-cxx11-error 2 {{'auto' not allowed in lambda parameter}} + A a = [&] { int y = x; }; // cxx03-warning {{template argument uses unnamed type}} \ + // cxx03-note {{while substituting}} cxx03-note {{unnamed type used}} + A b = [&] { [&] { [&] { int y = x; }; }; }; // cxx03-warning {{template argument uses unnamed type}} \ + // cxx03-note {{while substituting}} cxx03-note {{unnamed type used}} + A d = [&](auto param) { int y = x; }; // cxx03-cxx11-error {{'auto' not allowed in lambda parameter}} \ + // cxx03-warning {{template argument uses unnamed type}} \ + // cxx03-note {{while substituting}} cxx03-note {{unnamed type used}} + A e = [&](auto param) { [&] { [&](auto param2) { int y = x; }; }; }; // cxx03-cxx11-error 2 {{'auto' not allowed in lambda parameter}} \ + // cxx03-warning {{template argument uses unnamed type}} \ + // cxx03-note {{while substituting}} cxx03-note {{unnamed type used}} }; B<int> b; +// cxx03-note@#PR27994_B 4{{in instantiation of default member initializer}} +// cxx03-note@-2 4{{in evaluation of exception}} template <class T> struct C { struct D { + // cxx03-note@-1 {{in instantiation of default member initializer}} int x; - A f = [&] { int y = x; }; + A f = [&] { int y = x; }; // cxx03-warning {{template argument uses unnamed type}} \ + // cxx03-note {{while substituting}} cxx03-note {{unnamed type used}} }; }; int func() { C<int> a; decltype(a)::D b; + // cxx03-note@-1 {{in evaluation of exception}} } } @@ -606,8 +618,12 @@ struct S1 { void foo1() { auto s0 = S1([name=]() {}); // expected-error {{expected expression}} + // cxx03-warning@-1 {{template argument uses local type}} \ + // cxx03-note@-1 {{while substituting deduced template arguments}} auto s1 = S1([name=name]() {}); // expected-error {{use of undeclared identifier 'name'; did you mean 'name1'?}} // cxx03-cxx11-warning@-1 {{initialized lambda captures are a C++14 extension}} + // cxx03-warning@-2 {{template argument uses local type}} \ + // cxx03-note@-2 {{while substituting deduced template arguments}} } } diff --git a/clang/test/SemaTemplate/concepts.cpp b/clang/test/SemaTemplate/concepts.cpp index 6d29f8b..e5e081f 100644 --- a/clang/test/SemaTemplate/concepts.cpp +++ b/clang/test/SemaTemplate/concepts.cpp @@ -1333,4 +1333,75 @@ static_assert(__cpp17_iterator<not_move_constructible>); \ // expected-note@#is_move_constructible_v {{because 'is_move_constructible_v<parameter_mapping_regressions::case3::not_move_constructible>' evaluated to false}} } +namespace case4 { + +template<bool b> +concept bool_ = b; + +template<typename... Ts> +concept unary = bool_<sizeof...(Ts) == 1>; + +static_assert(!unary<>); +static_assert(unary<void>); + +} + +namespace case5 { + +template<int size> +concept true1 = size == size; + +template<typename... Ts> +concept true2 = true1<sizeof...(Ts)>; + +template<typename... Ts> +concept true3 = true2<Ts...>; + +static_assert(true3<void>); + +} + +namespace case6 { + +namespace std { +template <int __v> +struct integral_constant { + static const int value = __v; +}; + +template <class _Tp, class... _Args> +constexpr bool is_constructible_v = __is_constructible(_Tp, _Args...); + +template <class _From, class _To> +constexpr bool is_convertible_v = __is_convertible(_From, _To); + +template <class> +struct tuple_size; + +template <class _Tp> +constexpr decltype(sizeof(int)) tuple_size_v = tuple_size<_Tp>::value; +} // namespace std + +template <int N, int X> +concept FixedExtentConstructibleFromExtent = X == N; + +template <int Extent> +struct span { + int static constexpr extent = Extent; + template <typename R, int N = std::tuple_size_v<R>> + requires(FixedExtentConstructibleFromExtent<extent, N>) + span(R); +}; + +template <class, int> +struct array {}; + +template <class _Tp, decltype(sizeof(int)) _Size> +struct std::tuple_size<array<_Tp, _Size>> : integral_constant<_Size> {}; + +static_assert(std::is_convertible_v<array<int, 3>, span<3>>); +static_assert(!std::is_constructible_v<span<4>, array<int, 3>>); + +} + } |