diff options
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p1.cpp | 61 | ||||
-rw-r--r-- | clang/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p2.cpp | 13 | ||||
-rw-r--r-- | clang/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p5.cpp | 25 | ||||
-rw-r--r-- | clang/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p6.cpp | 25 | ||||
-rw-r--r-- | clang/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p7.cpp | 18 | ||||
-rw-r--r-- | clang/test/CXX/concepts-ts/dcl.dcl/lit.cfg.py | 26 | ||||
-rw-r--r-- | clang/test/CXX/concepts-ts/expr/expr.prim/expr.prim.id/p3.cpp | 4 | ||||
-rw-r--r-- | clang/test/CXX/expr/expr.prim/expr.prim.id/p3.cpp | 149 | ||||
-rw-r--r-- | clang/test/CXX/temp/temp.constr/temp.constr.decl/class-template-decl.cpp (renamed from clang/test/CXX/concepts-ts/temp/temp.constr/temp.constr.decl/class-template-decl.cpp) | 0 | ||||
-rw-r--r-- | clang/test/PCH/cxx2a-concept-specialization-expr.cpp | 32 | ||||
-rw-r--r-- | clang/test/Parser/cxx2a-concept-declaration.cpp | 61 |
11 files changed, 225 insertions, 189 deletions
diff --git a/clang/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p1.cpp b/clang/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p1.cpp deleted file mode 100644 index 863b608b5b7..00000000000 --- a/clang/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p1.cpp +++ /dev/null @@ -1,61 +0,0 @@ -// RUN: %clang_cc1 -std=c++14 -fconcepts-ts -fcxx-exceptions -x c++ -verify %s - -namespace A { - template<typename T> concept bool C1() { return true; } - - template<typename T> concept bool C2 = true; -} - -template<typename T> concept bool C3() { return (throw 0, true); } -static_assert(noexcept(C3<int>()), "function concept should be treated as if noexcept(true) specified"); - -template<typename T> concept bool D1(); // expected-error {{function concept declaration must be a definition}} - -struct B { - template<typename T> concept bool D2() { return true; } // expected-error {{concept declarations may only appear in namespace scope}} -}; - -struct C { - template<typename T> static concept bool D3 = true; // expected-error {{concept declarations may only appear in namespace scope}} -}; - -concept bool D4() { return true; } // expected-error {{'concept' can only appear on the definition of a function template or variable template}} - -concept bool D5 = true; // expected-error {{'concept' can only appear on the definition of a function template or variable template}} - -template<typename T> -concept bool D6; // expected-error {{variable concept declaration must be initialized}} - -template<typename T> -concept bool D7() throw(int) { return true; } // expected-error {{function concept cannot have exception specification}} - -// Tag - -concept class CC1 {}; // expected-error {{'concept' can only appear on the definition of a function template or variable template}} -concept struct CS1 {}; // expected-error {{'concept' can only appear on the definition of a function template or variable template}} -concept union CU1 {}; // expected-error {{'concept' can only appear on the definition of a function template or variable template}} -concept enum CE1 {}; // expected-error {{'concept' can only appear on the definition of a function template or variable template}} -template <typename T> concept class TCC1 {}; // expected-error {{'concept' can only appear on the definition of a function template or variable template}} -template <typename T> concept struct TCS1 {}; // expected-error {{'concept' can only appear on the definition of a function template or variable template}} -template <typename T> concept union TCU1 {}; // expected-error {{'concept' can only appear on the definition of a function template or variable template}} -typedef concept int CI; // expected-error {{'concept' can only appear on the definition of a function template or variable template}} -void fpc(concept int i) {} // expected-error {{'concept' can only appear on the definition of a function template or variable template}} - -concept bool; // expected-error {{'concept' can only appear on the definition of a function template or variable template}} - -template <typename T> concept bool VCEI{ true }; -template concept bool VCEI<int>; // expected-error {{'concept' cannot be applied on an explicit instantiation}} -extern template concept bool VCEI<int>; // expected-error {{'concept' cannot be applied on an explicit instantiation}} - -template <typename T> concept bool VCPS{ true }; -template <typename T> concept bool VCPS<T *>{ true }; // expected-error {{'concept' cannot be applied on an partial specialization}} - -template <typename T> concept bool VCES{ true }; -template <> concept bool VCES<int>{ true }; // expected-error {{'concept' cannot be applied on an explicit specialization}} - -template <typename T> concept bool FCEI() { return true; } -template concept bool FCEI<int>(); // expected-error {{'concept' cannot be applied on an explicit instantiation}} -extern template concept bool FCEI<int>(); // expected-error {{'concept' cannot be applied on an explicit instantiation}} - -template <typename T> concept bool FCES() { return true; } -template <> concept bool FCES<bool>() { return true; } // expected-error {{'concept' cannot be applied on an explicit specialization}} diff --git a/clang/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p2.cpp b/clang/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p2.cpp deleted file mode 100644 index 477910986de..00000000000 --- a/clang/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p2.cpp +++ /dev/null @@ -1,13 +0,0 @@ -// RUN: %clang_cc1 -std=c++14 -fconcepts-ts -x c++ -verify %s - -template<typename T> concept thread_local bool VCTL = true; // expected-error {{variable concept cannot be declared 'thread_local'}} - -template<typename T> concept constexpr bool VCC = true; // expected-error {{variable concept cannot be declared 'constexpr'}} - -template<typename T> concept inline bool FCI() { return true; } // expected-error {{function concept cannot be declared 'inline'}} - -struct X { - template<typename T> concept friend bool FCF() { return true; } // expected-error {{function concept cannot be declared 'friend'}} -}; - -template<typename T> concept constexpr bool FCC() { return true; } // expected-error {{function concept cannot be declared 'constexpr'}} diff --git a/clang/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p5.cpp b/clang/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p5.cpp deleted file mode 100644 index 69672ca8306..00000000000 --- a/clang/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p5.cpp +++ /dev/null @@ -1,25 +0,0 @@ -// RUN: %clang_cc1 -std=c++14 -fconcepts-ts -x c++ -verify %s - -template<typename T> -concept bool fcpv(void) { return true; } - -template<typename T> -concept bool fcpi(int i = 0) { return true; } // expected-error {{function concept cannot have any parameters}} - -template<typename... Ts> -concept bool fcpp(Ts... ts) { return true; } // expected-error {{function concept cannot have any parameters}} - -template<typename T> -concept bool fcpva(...) { return true; } // expected-error {{function concept cannot have any parameters}} - -template<typename T> -concept const bool fcrtc() { return true; } // expected-error {{declared return type of function concept must be 'bool'}} - -template<typename T> -concept int fcrti() { return 5; } // expected-error {{declared return type of function concept must be 'bool'}} - -template<typename T> -concept float fcrtf() { return 5.5; } // expected-error {{declared return type of function concept must be 'bool'}} - -template<typename T> -concept decltype(auto) fcrtd(void) { return true; } // expected-error {{declared return type of function concept must be 'bool'}} diff --git a/clang/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p6.cpp b/clang/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p6.cpp deleted file mode 100644 index f8a1bb72e39..00000000000 --- a/clang/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p6.cpp +++ /dev/null @@ -1,25 +0,0 @@ -// RUN: %clang_cc1 -std=c++14 -fconcepts-ts -x c++ -verify %s - -template<typename T> -concept bool vc { true }; - -template<typename T> -struct B { typedef bool Boolean; }; - -template<int N> -B<void>::Boolean concept vctb(!0); - -template<typename T> -concept const bool vctc { true }; // expected-error {{declared type of variable concept must be 'bool'}} - -template<typename T> -concept int vcti { 5 }; // expected-error {{declared type of variable concept must be 'bool'}} - -template<typename T> -concept float vctf { 5.5 }; // expected-error {{declared type of variable concept must be 'bool'}} - -template<typename T> -concept auto vcta { true }; // expected-error {{declared type of variable concept must be 'bool'}} - -template<typename T> -concept decltype(auto) vctd { true }; // expected-error {{declared type of variable concept must be 'bool'}} diff --git a/clang/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p7.cpp b/clang/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p7.cpp deleted file mode 100644 index 1bad6bb9329..00000000000 --- a/clang/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p7.cpp +++ /dev/null @@ -1,18 +0,0 @@ -// RUN: %clang_cc1 -std=c++14 -fconcepts-ts -x c++ -verify %s - -template <typename T> concept bool FCEI() { return true; } // expected-note {{previous declaration is here}} expected-note {{previous declaration is here}} -template bool FCEI<int>(); // expected-error {{function concept cannot be explicitly instantiated}} -extern template bool FCEI<double>(); // expected-error {{function concept cannot be explicitly instantiated}} - -template <typename T> concept bool FCES() { return true; } // expected-note {{previous declaration is here}} -template <> bool FCES<int>() { return true; } // expected-error {{function concept cannot be explicitly specialized}} - -template <typename T> concept bool VC { true }; // expected-note {{previous declaration is here}} expected-note {{previous declaration is here}} -template bool VC<int>; // expected-error {{variable concept cannot be explicitly instantiated}} -extern template bool VC<double>; // expected-error {{variable concept cannot be explicitly instantiated}} - -template <typename T> concept bool VCES { true }; // expected-note {{previous declaration is here}} -template <> bool VCES<int> { true }; // expected-error {{variable concept cannot be explicitly specialized}} - -template <typename T> concept bool VCPS { true }; // expected-note {{previous declaration is here}} -template <typename T> bool VCPS<T *> { true }; // expected-error {{variable concept cannot be partially specialized}} diff --git a/clang/test/CXX/concepts-ts/dcl.dcl/lit.cfg.py b/clang/test/CXX/concepts-ts/dcl.dcl/lit.cfg.py deleted file mode 100644 index c705e3cb93b..00000000000 --- a/clang/test/CXX/concepts-ts/dcl.dcl/lit.cfg.py +++ /dev/null @@ -1,26 +0,0 @@ -# -*- Python -*- - -import os -import lit.formats - -from lit.llvm import llvm_config - -# Configuration file for the 'lit' test runner. - -# name: The name of this test suite. -config.name = 'Clang-Concepts-TS-Unsupported' - -# testFormat: The test format to use to interpret tests. -# -# For now we require '&&' between commands, until they get globally killed and -# the test runner updated. -config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell) - -# suffixes: A list of file extensions to treat as test files. -config.suffixes = ['.c', '.cpp', '.cppm', '.m', '.mm', '.cu', - '.ll', '.cl', '.s', '.S', '.modulemap', '.test', '.rs'] - -config.unsupported = True - -# test_source_root: The root path where tests are located. -config.test_source_root = os.path.dirname(__file__) diff --git a/clang/test/CXX/concepts-ts/expr/expr.prim/expr.prim.id/p3.cpp b/clang/test/CXX/concepts-ts/expr/expr.prim/expr.prim.id/p3.cpp deleted file mode 100644 index 16da146a966..00000000000 --- a/clang/test/CXX/concepts-ts/expr/expr.prim/expr.prim.id/p3.cpp +++ /dev/null @@ -1,4 +0,0 @@ -// RUN: %clang_cc1 -std=c++2a -fconcepts-ts -verify %s - -template<typename T> concept C = true; -static_assert(C<int>); // expected-error{{sorry, unimplemented concepts feature concept specialization used}} diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.id/p3.cpp b/clang/test/CXX/expr/expr.prim/expr.prim.id/p3.cpp new file mode 100644 index 00000000000..dd3f0c0e3d6 --- /dev/null +++ b/clang/test/CXX/expr/expr.prim/expr.prim.id/p3.cpp @@ -0,0 +1,149 @@ +// RUN: %clang_cc1 -std=c++2a -verify -triple x86_64-linux-gnu %s + +template<typename T> concept C1 = true; // expected-note{{template is declared here}} +static_assert(C1<int>); +static_assert(C1); +// expected-error@-1{{use of concept 'C1' requires template arguments}} + +template<typename T> concept C2 = sizeof(T) == 4; +static_assert(C2<int>); +static_assert(!C2<long long int>); +static_assert(C2<char[4]>); +static_assert(!C2<char[5]>); + +template<typename T> concept C3 = sizeof(*T{}) == 4; +static_assert(C3<int*>); +static_assert(!C3<long long int>); + +struct A { + static constexpr int add(int a, int b) { + return a + b; + } +}; +struct B { + static int add(int a, int b) { // expected-note{{declared here}} + return a + b; + } +}; +template<typename U> +concept C4 = U::add(1, 2) == 3; +// expected-error@-1{{substitution into constraint expression resulted in a non-constant expression}} +// expected-note@-2{{non-constexpr function 'add' cannot be used in a constant expression}} +static_assert(C4<A>); +static_assert(!C4<B>); // expected-note {{while checking the satisfaction of concept 'C4<B>' requested here}} + +template<typename T, typename U> +constexpr bool is_same_v = false; + +template<typename T> +constexpr bool is_same_v<T, T> = true; + +template<typename T, typename U> +concept Same = is_same_v<T, U>; + +static_assert(Same<int, int>); +static_assert(Same<int, decltype(1)>); +static_assert(!Same<int, unsigned int>); +static_assert(!Same<A, B>); +static_assert(Same<A, A>); + +static_assert(Same<bool, decltype(C1<int>)>); +static_assert(Same<bool, decltype(C2<int>)>); +static_assert(Same<bool, decltype(C3<int*>)>); +static_assert(Same<bool, decltype(C4<A>)>); + +template<typename T> concept C5 = T{}; // expected-error {{atomic constraint must be of type 'bool' (found 'int')}} +constexpr bool x = C5<int>; // expected-note {{while checking the satisfaction of concept 'C5<int>' requested here}} + +template<int x> +concept IsEven = (x % 2) == 0; + +static_assert(IsEven<20>); +static_assert(!IsEven<11>); + +template<template<typename T> typename P> +concept IsTypePredicate = is_same_v<decltype(P<bool>::value), const bool> + && is_same_v<decltype(P<int>::value), const bool> + && is_same_v<decltype(P<long long>::value), const bool>; + +template<typename T> struct T1 {}; +template<typename T> struct T2 { static constexpr bool value = sizeof(T) == 2; }; + +static_assert(IsTypePredicate<T2>); +static_assert(!IsTypePredicate<T1>); + +namespace piecewise_substitution { + template <typename T> + concept True = true; + + template <typename T> + concept A = True<T> || T::value; + + template <typename T> + concept B = (True<T> || T::value); + + template <typename T> + concept C = !True<T> && T::value || true; + + template <typename T> + concept D = (!True<T> && T::value) || true; + + template <typename T> + concept E = T::value || True<T>; + + template <typename T> + concept F = (T::value || True<T>); + + template <typename T> + concept G = T::value && !True<T> || true; + + template <typename T> + concept H = (T::value && !True<T>) || true; + + template <typename T> + concept I = T::value; + + static_assert(A<int>); + static_assert(B<int>); + static_assert(C<int>); + static_assert(D<int>); + static_assert(E<int>); + static_assert(F<int>); + static_assert(G<int>); + static_assert(H<int>); + static_assert(!I<int>); +} + +// Short ciruiting + +template<typename T> struct T3 { using type = typename T::type; }; +// expected-error@-1{{type 'char' cannot be used prior to '::' because it has no members}} +// expected-error@-2{{type 'short' cannot be used prior to '::' because it has no members}} + +template<typename T> +concept C6 = sizeof(T) == 1 && sizeof(typename T3<T>::type) == 1; +// expected-note@-1{{while substituting template arguments into constraint expression here}} +// expected-note@-2{{in instantiation of template class 'T3<char>' requested here}} + +template<typename T> +concept C7 = sizeof(T) == 1 || sizeof( +// expected-note@-1{{while substituting template arguments into constraint expression here}} + typename + T3<T> +// expected-note@-1{{in instantiation of template class 'T3<short>' requested here}} + ::type) == 1; + +static_assert(!C6<short>); +static_assert(!C6<char>); // expected-note{{while checking the satisfaction of concept 'C6<char>' requested here}} +static_assert(C7<char>); +static_assert(!C7<short>); // expected-note{{while checking the satisfaction of concept 'C7<short>' requested here}} + +// Make sure argument list is converted when instantiating a CSE. + +template<typename T, typename U = int> +concept SameSize = sizeof(T) == sizeof(U); + +template<typename T> +struct X { static constexpr bool a = SameSize<T>; }; + +static_assert(X<unsigned>::a); diff --git a/clang/test/CXX/concepts-ts/temp/temp.constr/temp.constr.decl/class-template-decl.cpp b/clang/test/CXX/temp/temp.constr/temp.constr.decl/class-template-decl.cpp index d1ad0404ef4..d1ad0404ef4 100644 --- a/clang/test/CXX/concepts-ts/temp/temp.constr/temp.constr.decl/class-template-decl.cpp +++ b/clang/test/CXX/temp/temp.constr/temp.constr.decl/class-template-decl.cpp diff --git a/clang/test/PCH/cxx2a-concept-specialization-expr.cpp b/clang/test/PCH/cxx2a-concept-specialization-expr.cpp new file mode 100644 index 00000000000..6227d57c872 --- /dev/null +++ b/clang/test/PCH/cxx2a-concept-specialization-expr.cpp @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -std=c++2a -emit-pch %s -o %t +// RUN: %clang_cc1 -std=c++2a -include-pch %t -verify %s + +// expected-no-diagnostics + +#ifndef HEADER +#define HEADER + +template<typename... T> +concept C = true; + +namespace n { + template<typename... T> + concept C = true; +} + +void f() { + (void)C<int>; + (void)C<int, void>; + (void)n::C<void>; +} + +#else /*included pch*/ + +int main() { + (void)C<int>; + (void)C<int, void>; + (void)n::C<void>; + f(); +} + +#endif // HEADER diff --git a/clang/test/Parser/cxx2a-concept-declaration.cpp b/clang/test/Parser/cxx2a-concept-declaration.cpp index d80b3db428c..4dcfa3f8543 100644 --- a/clang/test/Parser/cxx2a-concept-declaration.cpp +++ b/clang/test/Parser/cxx2a-concept-declaration.cpp @@ -14,8 +14,6 @@ template<template<typename> concept T> concept D2 = true; // expected-error@-2{{template template parameter requires 'class' after the parameter list}} // expected-error@-3{{concept template parameter list must have at least one parameter; explicit specialization of concepts is not allowed}} -template<typename T> concept C2 = 0.f; // expected-error {{constraint expression must be of type 'bool' but is of type 'float'}} - struct S1 { template<typename T> concept C1 = true; // expected-error {{concept declarations may only appear in global or namespace scope}} }; @@ -26,15 +24,15 @@ extern "C++" { template<typename A> template<typename B> -concept C4 = true; // expected-error {{extraneous template parameter list in concept definition}} +concept C2 = true; // expected-error {{extraneous template parameter list in concept definition}} -template<typename T> concept C5 = true; // expected-note {{previous}} expected-note {{previous}} -int C5; // expected-error {{redefinition}} -struct C5 {}; // expected-error {{redefinition}} +template<typename T> concept C3 = true; // expected-note {{previous}} expected-note {{previous}} +int C3; // expected-error {{redefinition}} +struct C3 {}; // expected-error {{redefinition}} -struct C6 {}; // expected-note{{previous definition is here}} -template<typename T> concept C6 = true; -// expected-error@-1{{redefinition of 'C6' as different kind of symbol}} +struct C4 {}; // expected-note{{previous definition is here}} +template<typename T> concept C4 = true; +// expected-error@-1{{redefinition of 'C4' as different kind of symbol}} // TODO: Add test to prevent explicit specialization, partial specialization // and explicit instantiation of concepts. @@ -43,31 +41,60 @@ template<typename T, T v> struct integral_constant { static constexpr T value = v; }; namespace N { - template<typename T> concept C7 = true; + template<typename T> concept C5 = true; } -using N::C7; +using N::C5; -template <bool word> concept C8 = integral_constant<bool, wor>::value; +template <bool word> concept C6 = integral_constant<bool, wor>::value; // expected-error@-1{{use of undeclared identifier 'wor'; did you mean 'word'?}} // expected-note@-2{{'word' declared here}} -template<typename T> concept bool C9 = true; +template<typename T> concept bool C7 = true; // expected-warning@-1{{ISO C++2a does not permit the 'bool' keyword after 'concept'}} -template<> concept C10 = false; +template<> concept C8 = false; // expected-error@-1{{concept template parameter list must have at least one parameter; explicit specialization of concepts is not allowed}} -template<> concept C9<int> = false; +template<> concept C7<int> = false; // expected-error@-1{{name defined in concept definition must be an identifier}} -template<typename T> concept N::C11 = false; +template<typename T> concept N::C9 = false; // expected-error@-1{{name defined in concept definition must be an identifier}} class A { }; // expected-note@-1{{'A' declared here}} -template<typename T> concept A::C12 = false; +template<typename T> concept A::C10 = false; // expected-error@-1{{expected namespace name}} template<typename T> concept operator int = false; // expected-error@-1{{name defined in concept definition must be an identifier}} + +template<bool x> concept C11 = 2; // expected-error {{atomic constraint must be of type 'bool' (found 'int')}} +template<bool x> concept C12 = 2 && x; // expected-error {{atomic constraint must be of type 'bool' (found 'int')}} +template<bool x> concept C13 = x || 2 || x; // expected-error {{atomic constraint must be of type 'bool' (found 'int')}} +template<bool x> concept C14 = 8ull && x || x; // expected-error {{atomic constraint must be of type 'bool' (found 'unsigned long long')}} +template<typename T> concept C15 = sizeof(T); // expected-error {{atomic constraint must be of type 'bool' (found 'unsigned long')}} +template<typename T> concept C16 = true && (0 && 0); // expected-error {{atomic constraint must be of type 'bool' (found 'int')}} +// expected-warning@-1{{use of logical '&&' with constant operand}} +// expected-note@-2{{use '&' for a bitwise operation}} +// expected-note@-3{{remove constant to silence this warning}} +template<typename T> concept C17 = T{}; +static_assert(!C17<bool>); +template<typename T> concept C18 = (bool&&)true; +static_assert(C18<int>); +template<typename T> concept C19 = (const bool&)true; +static_assert(C19<int>); +template<typename T> concept C20 = (const bool)true; +static_assert(C20<int>); +template <bool c> concept C21 = integral_constant<bool, c>::value && true; +static_assert(C21<true>); +static_assert(!C21<false>); +template <bool c> concept C22 = integral_constant<bool, c>::value; +static_assert(C22<true>); +static_assert(!C22<false>); + +template <bool word> concept C23 = integral_constant<bool, wor>::value; +// expected-error@-1{{use of undeclared identifier 'wor'; did you mean 'word'?}} +// expected-note@-2{{'word' declared here}} + |