161 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify %s2// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s3// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s4// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s5// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s6 7// Tests that dependent expressions are always allowed, whereas non-dependent8// are checked as usual.9 10#include <stddef.h>11 12// Fake typeid, lacking a typeinfo header.13namespace std { class type_info {}; }14 15struct dummy {}; // expected-note 3 {{candidate constructor (the implicit copy constructor)}}16#if __cplusplus >= 201103L // C++11 or later17// expected-note@-2 3 {{candidate constructor (the implicit move constructor) not viable}}18#endif19 20template<typename T>21int f0(T x) {22 return (sizeof(x) == sizeof(int))? 0 : (sizeof(x) == sizeof(double))? 1 : 2;23}24 25template <typename T, typename U>26T f1(T t1, U u1, int i1, T** tpp)27{28 T t2 = i1;29 t2 = i1 + u1;30 ++u1;31 u1++;32 int i2 = u1;33 34 i1 = t1[u1];35 i1 *= t1;36 37 i1(u1, t1);38 u1(i1, t1);39 40 U u2 = (T)i1;41 static_cast<void>(static_cast<U>(reinterpret_cast<T>(42 dynamic_cast<U>(const_cast<T>(i1)))));43 44 new U(i1, t1);45 new int(t1, u1);46 new (t1, u1) int;47 delete t1;48 49 dummy d1 = sizeof(t1); // expected-error {{no viable conversion}}50 dummy d2 = offsetof(T, foo); // expected-error {{no viable conversion}}51 dummy d3 = __alignof(u1); // expected-error {{no viable conversion}}52 i1 = typeid(t1); // expected-error {{assigning to 'int' from incompatible type 'const std::type_info'}}53 i1 = tpp[0].size(); // expected-error {{'T *' is not a structure or union}}54 55 return u1;56}57 58template<typename T>59void f2(__restrict T x) {} // expected-note {{substitution failure [with T = int]: restrict requires a pointer or reference ('int' is invalid}}60 61void f3() {62 f2<int*>(0);63 f2<int>(0); // expected-error {{no matching function for call to 'f2'}}64}65 66#if __cplusplus >= 202002L67namespace GH138657 {68template <auto V> // #gh138657-template-head69class meta {};70template<int N>71class meta<N()> {}; // expected-error {{called object type 'int' is not a function or function point}}72 73template<int N[1]>74class meta<N()> {}; // expected-error {{called object type 'int *' is not a function or function point}}75 76template<char* N>77class meta<N()> {}; // expected-error {{called object type 'char *' is not a function or function point}}78 79struct S {};80template<S>81class meta<S()> {}; // expected-error {{template argument for non-type template parameter is treated as function type 'S ()'}}82 // expected-note@#gh138657-template-head {{template parameter is declared here}}83 84}85 86namespace GH115725 {87template<auto ...> struct X {};88template<typename T, typename ...Ts> struct A {89 template<Ts ...Ns, T *...Ps>90 A(X<0(Ps)...>, Ts (*...qs)[Ns]);91 // expected-error@-1{{called object type 'int' is not a function or function pointer}}92 93};94}95 96namespace GH68852 {97template <auto v>98struct constexpr_value {99 template <class... Ts>100 constexpr constexpr_value<v(Ts::value...)> call(Ts...) {101 //expected-error@-1 {{called object type 'int' is not a function or function pointer}}102 return {};103 }104};105 106template <auto v> constexpr static inline auto c_ = constexpr_value<v>{};107// expected-note@-1 {{in instantiation of template}}108auto k = c_<1>; // expected-note {{in instantiation of variable}}109 110}111 112#endif113#if __cplusplus >= 201702L114 115namespace GH138731 {116template <class...>117using void_t = void;118 119template <class T>120T&& declval();121 122struct S {123 S();124 static int f();125 static int var;126};127 128namespace invoke_detail {129 130template <typename F>131struct traits {132 template <typename... A>133 using result = decltype(declval<F>()(declval<A>()...));134};135 136template <typename F, typename... A>137using invoke_result_t = typename traits<F>::template result<A...>;138 139template <typename Void, typename F, typename... A>140inline constexpr bool is_invocable_v = false;141 142template <typename F, typename... A>143inline constexpr bool144 is_invocable_v<void_t<invoke_result_t<F, A...>>, F, A...> = true;145 146}147 148template <typename F, typename... A>149inline constexpr bool is_invocable_v =150 invoke_detail::is_invocable_v<void, F, A...>;151 152static_assert(!is_invocable_v<int>);153static_assert(!is_invocable_v<int, int>);154static_assert(!is_invocable_v<S>);155static_assert(is_invocable_v<decltype(&S::f)>);156static_assert(!is_invocable_v<decltype(&S::var)>);157 158}159 160#endif161