summaryrefslogtreecommitdiff
path: root/clang/test/SemaTemplate/instantiate-declref.cpp
diff options
context:
space:
mode:
authorZancanaro; Carlo <czan8762@plang3.cs.usyd.edu.au>2012-09-24 09:58:17 +1000
committerZancanaro; Carlo <czan8762@plang3.cs.usyd.edu.au>2012-09-24 09:58:17 +1000
commit222e2a7620e6520ffaf4fc4e69d79c18da31542e (patch)
tree7bfbc05bfa3b41c8f9d2e56d53a0bc3e310df239 /clang/test/SemaTemplate/instantiate-declref.cpp
parent3d206f03985b50beacae843d880bccdc91a9f424 (diff)
Add the clang library to the repo (with some of my changes, too).
Diffstat (limited to 'clang/test/SemaTemplate/instantiate-declref.cpp')
-rw-r--r--clang/test/SemaTemplate/instantiate-declref.cpp117
1 files changed, 117 insertions, 0 deletions
diff --git a/clang/test/SemaTemplate/instantiate-declref.cpp b/clang/test/SemaTemplate/instantiate-declref.cpp
new file mode 100644
index 0000000..7d4a2ff
--- /dev/null
+++ b/clang/test/SemaTemplate/instantiate-declref.cpp
@@ -0,0 +1,117 @@
+// 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{{no struct named 'UeberInner' in 'N::Outer::Inner::InnerTemplate<int>'}}
+
+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) { }
+}
+
+// PR5517
+namespace test0 {
+ template <int K> struct X {
+ X() { extern void x(); }
+ };
+ void g() { X<2>(); }
+}
+
+// <rdar://problem/8302161>
+namespace test1 {
+ template <typename T> void f(T const &t) {
+ union { char c; T t_; };
+ c = 'a'; // <- this shouldn't silently fail to instantiate
+ T::foo(); // expected-error {{has no members}}
+ }
+ template void f(int const &); // expected-note {{requested here}}
+}
+
+namespace test2 {
+ template<typename T> void f() {
+ T::error; // expected-error {{no member}}
+ }
+ void g() {
+ // This counts as an odr-use, so should trigger the instantiation of f<int>.
+ (void)&f<int>; // expected-note {{here}}
+ }
+}