aboutsummaryrefslogtreecommitdiff
path: root/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p2.cpp
blob: 7b5577520d4212121930091b1fe28efc21610d70 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify %s -std=c++11

struct S {
  virtual ~S();

  void g() throw (auto(*)()->int);

  // Note, this is not permitted: conversion-declarator cannot have a trailing return type.
  // FIXME: don't issue the second diagnostic for this.
  operator auto(*)()->int(); // expected-error{{'auto' not allowed here}} expected-error {{C++ requires a type specifier}}
};

typedef auto Fun(int a) -> decltype(a + a);
typedef auto (*PFun)(int a) -> decltype(a + a);

void g(auto (*f)() -> int) {
  try { }
  catch (auto (&f)() -> int) { }
  catch (auto (*const f[10])() -> int) { }
}

namespace std {
  class type_info;
}

template<typename T> struct U {};

void j() {
  (void)typeid(auto(*)()->void);
  (void)sizeof(auto(*)()->void);
  (void)__alignof(auto(*)()->void);

  U<auto(*)()->void> v;

  int n;
  (void)static_cast<auto(*)()->void>(&j);
  auto p = reinterpret_cast<auto(*)()->int>(&j);
  (void)const_cast<auto(**)()->int>(&p);
  (void)(auto(*)()->void)(&j);
}

template <auto (*f)() -> void = &j> class C { };
struct F : auto(*)()->int {}; // expected-error{{expected class name}}
template<typename T = auto(*)()->int> struct G { };

int g();
auto (*h)() -> auto = &g; // expected-error{{'auto' not allowed here}}
auto (*i)() = &g; // ok; auto deduced as int.
auto (*k)() -> int = i; // ok; no deduction.