From 39fcc9a984e2820e4ea0fa2ac4abd17d9f3a31df Mon Sep 17 00:00:00 2001
From: dim <dim@FreeBSD.org>
Date: Sun, 20 Feb 2011 13:06:31 +0000
Subject: Vendor import of clang trunk r126079:
 http://llvm.org/svn/llvm-project/cfe/trunk@126079

---
 test/CXX/expr/expr.unary/expr.delete/p5.cpp        |  22 ++-
 test/CXX/expr/expr.unary/expr.new/p2-cxx0x.cpp     |  23 +++
 test/CXX/expr/expr.unary/expr.sizeof/p5-0x.cpp     |  38 +++++
 .../CXX/expr/expr.unary/expr.unary.noexcept/cg.cpp |  26 ++++
 .../expr/expr.unary/expr.unary.noexcept/sema.cpp   | 172 +++++++++++++++++++++
 test/CXX/expr/expr.unary/expr.unary.noexcept/ser.h |   8 +
 test/CXX/expr/expr.unary/expr.unary.op/p4.cpp      |   6 +-
 test/CXX/expr/expr.unary/expr.unary.op/p6.cpp      |  36 +++++
 8 files changed, 322 insertions(+), 9 deletions(-)
 create mode 100644 test/CXX/expr/expr.unary/expr.new/p2-cxx0x.cpp
 create mode 100644 test/CXX/expr/expr.unary/expr.sizeof/p5-0x.cpp
 create mode 100644 test/CXX/expr/expr.unary/expr.unary.noexcept/cg.cpp
 create mode 100644 test/CXX/expr/expr.unary/expr.unary.noexcept/sema.cpp
 create mode 100644 test/CXX/expr/expr.unary/expr.unary.noexcept/ser.h
 create mode 100644 test/CXX/expr/expr.unary/expr.unary.op/p6.cpp

(limited to 'test/CXX/expr/expr.unary')

diff --git a/test/CXX/expr/expr.unary/expr.delete/p5.cpp b/test/CXX/expr/expr.unary/expr.delete/p5.cpp
index 2fa30e5..ecb2918 100644
--- a/test/CXX/expr/expr.unary/expr.delete/p5.cpp
+++ b/test/CXX/expr/expr.unary/expr.delete/p5.cpp
@@ -24,11 +24,23 @@ void f0(T2_A *a) { T2_C x; x.f0(a); }
 class T2_A { };
 
 // An alternate version of the same.
-//
-// FIXME: Revisit this case when we have access control.
 class T3_A;
 template<typename T>
-struct T3_B { void f0(T *a) { delete a; } };
-struct T3_C { T3_B<T3_A> x; void f0(T3_A *a) { x.f0(a); } };
+struct T3_B { 
+  void f0(T *a) { 
+    delete a; // expected-error{{calling a private destructor of class 'T3_A'}}
+  } 
+};
+
+struct T3_C { 
+  T3_B<T3_A> x; 
+  void f0(T3_A *a) { 
+    x.f0(a); // expected-note{{in instantiation of member function 'T3_B<T3_A>::f0' requested here}}
+  } 
+};
+
 void f0(T3_A *a) { T3_C x; x.f0(a); }
-class T3_A { private: ~T3_A(); };
+class T3_A { 
+private: 
+  ~T3_A(); // expected-note{{declared private here}}
+};
diff --git a/test/CXX/expr/expr.unary/expr.new/p2-cxx0x.cpp b/test/CXX/expr/expr.unary/expr.new/p2-cxx0x.cpp
new file mode 100644
index 0000000..c9a8887
--- /dev/null
+++ b/test/CXX/expr/expr.unary/expr.new/p2-cxx0x.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++0x
+
+template<typename T>
+struct only {
+  only(T);
+  template<typename U> only(U) = delete;
+};
+
+void f() {
+  only<const int*> p = new const auto (0);
+  only<double*> q = new (auto) (0.0);
+
+  new auto; // expected-error{{new expression for type 'auto' requires a constructor argument}}
+  new (const auto)(); // expected-error{{new expression for type 'auto const' requires a constructor argument}}
+  new (auto) (1,2,3); // expected-error{{new expression for type 'auto' contains multiple constructor arguments}}
+}
+
+void p2example() {
+  only<int*> r = new auto(1);
+  auto x = new auto('a');
+
+  only<char*> testX = x;
+}
diff --git a/test/CXX/expr/expr.unary/expr.sizeof/p5-0x.cpp b/test/CXX/expr/expr.unary/expr.sizeof/p5-0x.cpp
new file mode 100644
index 0000000..3824615
--- /dev/null
+++ b/test/CXX/expr/expr.unary/expr.sizeof/p5-0x.cpp
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s
+
+// Test parsing + semantic analysis
+template<typename ...Types> struct count_types {
+  static const unsigned value = sizeof...(Types);
+};
+
+template<int ...Values> struct count_ints {
+  static const unsigned value = sizeof...(Values);
+};
+
+// Test instantiation
+int check_types[count_types<short, int, long>::value == 3? 1 : -1];
+int check_ints[count_ints<1, 2, 3, 4, 5>::value == 5? 1 : -1];
+
+// Test instantiation involving function parameter packs.
+struct any {
+  template<typename T> any(T);
+};
+
+template<typename ...Inits>
+void init_me(Inits ...inits) {
+  any array[sizeof...(inits)] = { inits... };
+}
+
+template void init_me<int, float, double*>(int, float, double*);
+
+// Test parser and semantic recovery.
+template<int Value> struct count_ints_2 {
+  static const unsigned value = sizeof...(Value); // expected-error{{'Value' does not refer to the name of a parameter pack}}
+};
+
+template<typename ...Types> // expected-note{{parameter pack 'Types' declared here}}
+struct count_types_2 {
+  static const unsigned value = sizeof... Type; // expected-error{{missing parentheses around the size of parameter pack 'Type'}} \
+  // expected-error{{Type' does not refer to the name of a parameter pack; did you mean 'Types'?}}
+};
+
diff --git a/test/CXX/expr/expr.unary/expr.unary.noexcept/cg.cpp b/test/CXX/expr/expr.unary/expr.unary.noexcept/cg.cpp
new file mode 100644
index 0000000..6aec3a2
--- /dev/null
+++ b/test/CXX/expr/expr.unary/expr.unary.noexcept/cg.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -fexceptions -triple x86_64-apple-darwin10 -S -emit-llvm -std=c++0x -include %S/ser.h %s -o - | FileCheck %s
+// RUN: %clang_cc1 -fexceptions -triple x86_64-apple-darwin10 -emit-pch -o %t-ser.pch -std=c++0x -x c++ %S/ser.h
+// RUN: %clang_cc1 -fexceptions -triple x86_64-apple-darwin10 -S -emit-llvm -std=c++0x -include-pch %t-ser.pch %s -o - | FileCheck %s
+
+struct D {
+  ~D() throw();
+};
+struct E {
+  ~E() throw();
+};
+
+void test() {
+  bool b;
+  // CHECK: store i8 1
+  b = noexcept(0);
+  // CHECK: store i8 0
+  b = noexcept(throw 0);
+  b = f1();
+  b = f2();
+
+  // CHECK-NOT: call void @_ZN1ED1Ev
+  // CHECK: call void @_ZN1DD1Ev
+  D(), noexcept(E());
+}
+// CHECK: ret i1 true
+// CHECK: ret i1 false
diff --git a/test/CXX/expr/expr.unary/expr.unary.noexcept/sema.cpp b/test/CXX/expr/expr.unary/expr.unary.noexcept/sema.cpp
new file mode 100644
index 0000000..98c6f4e
--- /dev/null
+++ b/test/CXX/expr/expr.unary/expr.unary.noexcept/sema.cpp
@@ -0,0 +1,172 @@
+// RUN: %clang_cc1 -fexceptions -fsyntax-only -verify -std=c++0x -fms-extensions %s
+
+#define P(e) static_assert(noexcept(e), "expected nothrow")
+#define N(e) static_assert(!noexcept(e), "expected throw")
+#define B(b, e) static_assert(b == noexcept(e), "expectation failed")
+
+void simple() {
+  P(0);
+  P(0 + 0);
+  int i;
+  P(i);
+  P(sizeof(0));
+  P(static_cast<int>(0));
+  N(throw 0);
+  N((throw 0, 0));
+}
+
+void nospec();
+void allspec() throw(...);
+void intspec() throw(int);
+void emptyspec() throw();
+void nothrowattr() __attribute__((nothrow));
+
+void call() {
+  N(nospec());
+  N(allspec());
+  N(intspec());
+  P(emptyspec());
+  P(nothrowattr());
+}
+
+void (*pnospec)();
+void (*pallspec)() throw(...);
+void (*pintspec)() throw(int);
+void (*pemptyspec)() throw();
+
+void callptr() {
+  N(pnospec());
+  N((*pnospec)());
+  N(pallspec());
+  N((*pallspec)());
+  N(pintspec());
+  N((*pintspec)());
+  P(pemptyspec());
+  P((*pemptyspec)());
+}
+
+struct S1 {
+  void nospec();
+  void allspec() throw(...);
+  void intspec() throw(int);
+  void emptyspec() throw();
+};
+
+void callmem() {
+  S1 s;
+  N(s.nospec());
+  N(s.allspec());
+  N(s.intspec());
+  P(s.emptyspec());
+}
+
+void (S1::*mpnospec)();
+void (S1::*mpallspec)() throw(...);
+void (S1::*mpintspec)() throw(int);
+void (S1::*mpemptyspec)() throw();
+
+void callmemptr() {
+  S1 s;
+  N((s.*mpnospec)());
+  N((s.*mpallspec)());
+  N((s.*mpintspec)());
+  P((s.*mpemptyspec)());
+}
+
+struct S2 {
+  S2();
+  S2(int, int) throw();
+  void operator +();
+  void operator -() throw();
+  void operator +(int);
+  void operator -(int) throw();
+  operator int();
+  operator float() throw();
+};
+
+void *operator new(__typeof__(sizeof(int)) sz, int) throw();
+
+struct Bad1 {
+  ~Bad1() throw(int);
+};
+struct Bad2 {
+  void operator delete(void*) throw(int);
+};
+
+void implicits() {
+  N(new int);
+  P(new (0) int);
+  P(delete (int*)0);
+  N(delete (Bad1*)0);
+  N(delete (Bad2*)0);
+  N(S2());
+  P(S2(0, 0));
+  S2 s;
+  N(+s);
+  P(-s);
+  N(s + 0);
+  P(s - 0);
+  N(static_cast<int>(s));
+  P(static_cast<float>(s));
+  N(Bad1());
+}
+
+struct V {
+  virtual ~V() throw();
+};
+struct D : V {};
+
+void dyncast() {
+  V *pv = 0;
+  D *pd = 0;
+  P(dynamic_cast<V&>(*pd));
+  P(dynamic_cast<V*>(pd));
+  N(dynamic_cast<D&>(*pv));
+  P(dynamic_cast<D*>(pv));
+}
+
+namespace std {
+  struct type_info {};
+}
+
+void idtype() {
+  P(typeid(V));
+  P(typeid((V*)0));
+  P(typeid(*(S1*)0));
+  N(typeid(*(V*)0));
+}
+
+void uneval() {
+  P(sizeof(typeid(*(V*)0)));
+  P(typeid(typeid(*(V*)0)));
+}
+
+struct G1 {};
+struct G2 { int i; };
+struct G3 { S2 s; };
+
+void gencon() {
+  P(G1());
+  P(G2());
+  N(G3());
+}
+
+template <typename T, bool b>
+void late() {
+  B(b, typeid(*(T*)0));
+  B(b, T(1));
+  B(b, static_cast<T>(S2(0, 0)));
+  B(b, S1() + T());
+}
+struct S3 {
+  virtual ~S3() throw();
+  S3() throw();
+  explicit S3(int);
+  S3(const S2&);
+};
+void operator +(const S1&, float) throw();
+void operator +(const S1&, const S3&);
+void tlate() {
+  late<float, true>();
+  late<S3, false>();
+}
diff --git a/test/CXX/expr/expr.unary/expr.unary.noexcept/ser.h b/test/CXX/expr/expr.unary/expr.unary.noexcept/ser.h
new file mode 100644
index 0000000..e6e7b79
--- /dev/null
+++ b/test/CXX/expr/expr.unary/expr.unary.noexcept/ser.h
@@ -0,0 +1,8 @@
+// Serialization testing helper for noexcept, included by cg.cpp.
+
+inline bool f1() {
+  return noexcept(0);
+}
+inline bool f2() {
+  return noexcept(throw 0);
+}
diff --git a/test/CXX/expr/expr.unary/expr.unary.op/p4.cpp b/test/CXX/expr/expr.unary/expr.unary.op/p4.cpp
index 170c734..06cc610 100644
--- a/test/CXX/expr/expr.unary/expr.unary.op/p4.cpp
+++ b/test/CXX/expr/expr.unary/expr.unary.op/p4.cpp
@@ -7,8 +7,7 @@ namespace test0 {
     template<typename T> void g(T);
 
     void test() {
-      // FIXME: this diagnostic is terrible
-      foo(&g<int>); // expected-error {{cannot initialize a parameter of type 'void (test0::A::*)(int)' with an rvalue of type '<overloaded function type>'}}
+      foo(&g<int>); // expected-error {{can't form member pointer of type 'void (test0::A::*)(int)' without '&' and class name}}
     }
   };
 }
@@ -39,7 +38,6 @@ namespace test2 {
   };
 
   void A::test() {
-    // FIXME: This diagnostic is terrible.
-    int (A::*ptr)(int) = &(A::foo); // expected-error {{cannot initialize a variable of type 'int (test2::A::*)(int)' with an rvalue of type '<overloaded function type>'}}
+    int (A::*ptr)(int) = &(A::foo); // expected-error {{can't form member pointer of type 'int (test2::A::*)(int)' without '&' and class name}}
   }
 }
diff --git a/test/CXX/expr/expr.unary/expr.unary.op/p6.cpp b/test/CXX/expr/expr.unary/expr.unary.op/p6.cpp
new file mode 100644
index 0000000..543a86d
--- /dev/null
+++ b/test/CXX/expr/expr.unary/expr.unary.op/p6.cpp
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// -- prvalue of arithmetic
+
+bool b = !0;
+
+bool b2 = !1.2;
+
+bool b3 = !4;
+
+// -- unscoped enumeration
+enum { E, F };
+
+bool b4 = !E;
+bool b5 = !F;
+
+// --  pointer, 
+bool b6 = !&b4;
+void f();
+bool b61 = !&f;
+
+// -- or pointer to member type can be converted to a prvalue of type bool.
+struct S { void f() { } };
+
+bool b7 = !&S::f;
+
+
+bool b8 = !S(); //expected-error {{invalid argument type 'S'}}
+
+namespace PR8181
+{
+  void f() { }
+  void f(char) { }
+  bool b = !&f;  //expected-error {{cannot resolve overloaded function from context}}
+
+}
-- 
cgit v1.1