xref: /aosp_15_r20/external/clang/test/Parser/cxx-concepts-ambig-constraint-expr.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -std=c++14 -fconcepts-ts -x c++ %s -verify
2*67e74705SXin Li 
3*67e74705SXin Li // Test parsing of constraint-expressions in cases where the grammar is
4*67e74705SXin Li // ambiguous with the expectation that the longest token sequence which matches
5*67e74705SXin Li // the syntax is consumed without backtracking.
6*67e74705SXin Li 
7*67e74705SXin Li // type-specifier-seq in conversion-type-id
8*67e74705SXin Li template <typename T> requires (bool)&T::operator short
9*67e74705SXin Li unsigned int foo(); // expected-error {{C++ requires a type specifier for all declarations}}
10*67e74705SXin Li 
11*67e74705SXin Li // type-specifier-seq in new-type-id
12*67e74705SXin Li template <typename T> requires (bool)sizeof new (T::f()) short
13*67e74705SXin Li unsigned int bar(); // expected-error {{C++ requires a type specifier for all declarations}}
14*67e74705SXin Li 
15*67e74705SXin Li template<typename T> requires (bool)sizeof new (T::f()) unsigned // expected-error {{'struct' cannot be signed or unsigned}}
16*67e74705SXin Li struct X { }; // expected-error {{'X' cannot be defined in a type specifier}}
17*67e74705SXin Li 
18*67e74705SXin Li // C-style cast
19*67e74705SXin Li // of function call on function-style cast
20*67e74705SXin Li template <typename T> requires (bool(T()))
21*67e74705SXin Li T (*fp)(); // expected-error {{use of undeclared identifier 'fp'}}
22*67e74705SXin Li 
23*67e74705SXin Li // function-style cast
24*67e74705SXin Li // as the callee in a function call
25*67e74705SXin Li struct A {
26*67e74705SXin Li   static int t;
TA27*67e74705SXin Li   template <typename T> requires bool(T())
28*67e74705SXin Li   (A(T (&t))) { } // expected-error {{called object type 'bool' is not a function or function pointer}}
29*67e74705SXin Li };
30