summaryrefslogtreecommitdiff
path: root/test/SemaTemplate/instantiate-declref.cpp
blob: da8b263ab3abe59f70c98cee123162d8af0baa38 (plain)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// RUN: %clang_cc1 -fsyntax-only -verify %s
namespace N {
  struct Outer {
    struct Inner {
      template<typename T>
      struct InnerTemplate {
        struct VeryInner {
          typedef T type;

          static enum K1 { K1Val = sizeof(T) } Kind1;
          static enum { K2Val = sizeof(T)*2 } Kind2;
          enum { K3Val = sizeof(T)*2 } Kind3;

          void foo() {
            K1 k1 = K1Val;
            Kind1 = K1Val;
            Outer::Inner::InnerTemplate<type>::VeryInner::Kind2 = K2Val;
            Kind3 = K3Val;
          }

          struct UeberInner {
            void bar() {
              K1 k1 = K1Val;
              Kind1 = K1Val;
              Outer::Inner::InnerTemplate<type>::VeryInner::Kind2 = K2Val;

              InnerTemplate t;
              InnerTemplate<type> t2;
            }
          };
        };
      };
    };
  };
}

typedef int INT;
template struct N::Outer::Inner::InnerTemplate<INT>::VeryInner;
template struct N::Outer::Inner::InnerTemplate<INT>::UeberInner; // expected-error{{'UeberInner' does not name a tag member}}

namespace N2 {
  struct Outer2 {
    template<typename T, typename U = T>
    struct Inner {
      void foo() {
        enum { K1Val = sizeof(T) } k1;
        enum K2 { K2Val = sizeof(T)*2 } k2a;

        K2 k2b = K2Val;

        struct S { T x, y; } s1;
        struct { U x, y; } s2;
        s1.x = s2.x; // expected-error{{incompatible}}

        typedef T type;
        type t2 = s1.x;

        typedef struct { T z; } type2;
        type2 t3 = { s1.x };

        Inner i1;
        i1.foo();
        Inner<T> i2;
        i2.foo();
      }
    };
  };
}

template struct N2::Outer2::Inner<float>;
template struct N2::Outer2::Inner<int*, float*>; // expected-note{{instantiation}}

// Test dependent pointer-to-member expressions.
template<typename T>
struct smart_ptr {
  struct safe_bool {
    int member;
  };
  
  operator int safe_bool::*() const { 
    return ptr? &safe_bool::member : 0;
  }
  
  T* ptr;
};

void test_smart_ptr(smart_ptr<int> p) {
  if (p) { }
}