Clang Project

clang_source_code/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p6-0x.cpp
1// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
2// RUN: %clang_cc1 -std=c++1z -fsyntax-only -verify %s
3
4void f0() &; // expected-error {{non-member function cannot have '&' qualifier}}
5void f1() &&; // expected-error {{non-member function cannot have '&&' qualifier}}
6void f2() const volatile &&; // expected-error {{non-member function cannot have 'const volatile &&' qualifier}}
7
8struct X {
9  void f0() &;
10  void f1() &&;
11  static void f2() &; // expected-error{{static member function cannot have '&' qualifier}}
12  static void f3() &&; // expected-error{{static member function cannot have '&&' qualifier}}
13};
14
15typedef void func_type_lvalue() &;
16typedef void func_type_rvalue() &&;
17
18typedef func_type_lvalue *func_type_lvalue_ptr; // expected-error{{pointer to function type 'func_type_lvalue' (aka 'void () &') cannot have '&' qualifier}}
19typedef func_type_rvalue *func_type_rvalue_ptr; // expected-error{{pointer to function type 'func_type_rvalue' (aka 'void () &&') cannot have '&&' qualifier}}
20
21typedef func_type_lvalue &func_type_lvalue_ref; // expected-error{{reference to function type 'func_type_lvalue' (aka 'void () &') cannot have '&' qualifier}}
22typedef func_type_rvalue &func_type_rvalue_ref; // expected-error{{reference to function type 'func_type_rvalue' (aka 'void () &&') cannot have '&&' qualifier}}
23
24template<typename T = func_type_lvalue> struct wrap {
25  typedef T val;
26  typedef T *ptr; // expected-error-re 2{{pointer to function type '{{.*}}' cannot have '{{&|&&}}' qualifier}}
27  typedef T &ref; // expected-error-re 2{{reference to function type '{{.*}}' cannot have '{{&|&&}}' qualifier}}
28};
29
30using func_type_lvalue = wrap<>::val; // expected-note{{in instantiation of}}
31using func_type_lvalue = wrap<func_type_lvalue>::val;
32using func_type_rvalue = wrap<func_type_rvalue>::val; // expected-note{{in instantiation of}}
33
34using func_type_lvalue_ptr = wrap<>::ptr;
35using func_type_lvalue_ptr = wrap<func_type_lvalue>::ptr;
36using func_type_rvalue_ptr = wrap<func_type_rvalue>::ptr;
37
38using func_type_lvalue_ref = wrap<>::ref;
39using func_type_lvalue_ref = wrap<func_type_lvalue>::ref;
40using func_type_rvalue_ref = wrap<func_type_rvalue>::ref;
41
42func_type_lvalue f2; // expected-error{{non-member function of type 'func_type_lvalue' (aka 'void () &') cannot have '&' qualifier}}
43func_type_rvalue f3; // expected-error{{non-member function of type 'func_type_rvalue' (aka 'void () &&') cannot have '&&' qualifier}}
44
45struct Y {
46  func_type_lvalue f0;
47  func_type_rvalue f1;
48};
49
50void (X::*mpf1)() & = &X::f0;
51void (X::*mpf2)() && = &X::f1;
52
53
54void (f() &&); // expected-error{{non-member function cannot have '&&' qualifier}}
55
56// FIXME: These are ill-formed.
57template<typename T> struct pass {
58  void f(T);
59};
60pass<func_type_lvalue> pass0;
61pass<func_type_lvalue> pass1;
62
63template<typename T, typename U> struct is_same { static const bool value = false; };
64template<typename T> struct is_same<T, T> { static const bool value = true; };
65constexpr bool cxx1z = __cplusplus > 201402L;
66
67void noexcept_true() noexcept(true);
68void noexcept_false() noexcept(false);
69using func_type_noexcept_true = wrap<decltype(noexcept_true)>;
70using func_type_noexcept_false = wrap<decltype(noexcept_false)>;
71static_assert(is_same<func_type_noexcept_false, func_type_noexcept_true>::value == !cxx1z, "");
72static_assert(is_same<func_type_noexcept_false::val, func_type_noexcept_true::val>::value == !cxx1z, "");
73static_assert(is_same<func_type_noexcept_false::ptr, func_type_noexcept_true::ptr>::value == !cxx1z, "");
74static_assert(is_same<func_type_noexcept_false::ref, func_type_noexcept_true::ref>::value == !cxx1z, "");
75