OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [gcc/] [testsuite/] [g++.dg/] [cpp0x/] [decltype4.C] - Blame information for rev 315

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 301 jeremybenn
// { dg-do "compile" }
2
// { dg-options "-std=gnu++0x" }
3
 
4
template
5
struct is_same
6
{
7
  static const bool value = false;
8
};
9
 
10
template
11
struct is_same
12
{
13
  static const bool value = true;
14
};
15
 
16
#define CHECK_DECLTYPE(DECLTYPE,RESULT) \
17
  static_assert(is_same< DECLTYPE , RESULT >::value, #DECLTYPE " should be " #RESULT)
18
 
19
struct A {
20
  int x;
21
  int& y;
22
  int foo(char);
23
  int& bar() const;
24
};
25
 
26
CHECK_DECLTYPE(decltype(&A::x), int A::*);
27
decltype(&A::y) Ay; // { dg-error "cannot create pointer to reference member|invalid type" }
28
CHECK_DECLTYPE(decltype(&A::foo), int (A::*) (char));
29
CHECK_DECLTYPE(decltype(&A::bar), int& (A::*) () const);
30
 
31
CHECK_DECLTYPE(decltype("decltype"), const char(&)[9]);
32
CHECK_DECLTYPE(decltype(1), int);
33
 
34
int an_int = 5;
35
int& i = an_int;
36
const int j = an_int;
37
 
38
CHECK_DECLTYPE(decltype(i)&, int&);
39
CHECK_DECLTYPE(const decltype(j), const int);
40
 
41
int foo();
42
CHECK_DECLTYPE(decltype(foo()), int);
43
float& bar(int);
44
CHECK_DECLTYPE(decltype (bar(1)), float&);
45
const A bar();
46
CHECK_DECLTYPE(decltype (bar()), const A);
47
const A& bar2();
48
CHECK_DECLTYPE(decltype (bar2()), const A&);
49
 
50
void wibble() {
51
  CHECK_DECLTYPE(decltype(1+2), int);
52
  int* p;
53
  CHECK_DECLTYPE(decltype(*p), int&);
54
  int a[10];
55
  CHECK_DECLTYPE(decltype(a[3]), int&);
56
  int i; int& j = i;
57
  CHECK_DECLTYPE(decltype (i = 5), int&);
58
  CHECK_DECLTYPE(decltype (j = 5), int&);
59
 
60
  CHECK_DECLTYPE(decltype (++i), int&);
61
  CHECK_DECLTYPE(decltype (i++), int);
62
}
63
 
64
struct B {
65
  int bit : 2;
66
  const int cbit : 3;
67
 
68
  void foo()
69
  {
70
    CHECK_DECLTYPE(decltype(bit), int);
71
    CHECK_DECLTYPE(decltype((bit)), int&);
72
    CHECK_DECLTYPE(decltype(cbit), const int);
73
    CHECK_DECLTYPE(decltype((cbit)), const int&);
74
  }
75
};
76
 
77
B b;
78
const B& bc = b;
79
CHECK_DECLTYPE(decltype(b.bit), int);
80
CHECK_DECLTYPE(decltype(bc.bit), int);
81
CHECK_DECLTYPE(decltype((b.bit)), int&);
82
CHECK_DECLTYPE(decltype((bc.bit)), const int&);

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.