[cfe-commits] r93177 - /cfe/trunk/test/CXX/temp/temp.decls/temp.mem/p5.cpp

Douglas Gregor dgregor at apple.com
Mon Jan 11 11:52:23 PST 2010


Author: dgregor
Date: Mon Jan 11 13:52:23 2010
New Revision: 93177

URL: http://llvm.org/viewvc/llvm-project?rev=93177&view=rev
Log:
Test case for naming of conversion function template specializations

Added:
    cfe/trunk/test/CXX/temp/temp.decls/temp.mem/p5.cpp

Added: cfe/trunk/test/CXX/temp/temp.decls/temp.mem/p5.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.decls/temp.mem/p5.cpp?rev=93177&view=auto

==============================================================================
--- cfe/trunk/test/CXX/temp/temp.decls/temp.mem/p5.cpp (added)
+++ cfe/trunk/test/CXX/temp/temp.decls/temp.mem/p5.cpp Mon Jan 11 13:52:23 2010
@@ -0,0 +1,78 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+struct A { 
+  template <class T> operator T*();
+}; 
+
+template <class T> A::operator T*() { return 0; }
+template <> A::operator char*(){ return 0; } // specialization
+template A::operator void*(); // explicit instantiation
+
+int main() { 
+  A a;
+  int *ip; 
+  ip = a.operator int*();
+}
+
+// PR5742
+namespace PR5742 {
+  template <class T> struct A { };
+  template <class T> struct B { };
+
+  struct S {
+    template <class T> operator T();
+  } s;
+
+  void f() {
+    s.operator A<A<int> >();
+    s.operator A<B<int> >();
+    s.operator A<B<A<int> > >();
+  }
+}
+
+// PR5762
+class Foo {
+ public:
+  template <typename T> operator T();
+  
+  template <typename T>
+  T As() {
+    return this->operator T();
+  }
+
+  template <typename T>
+  T As2() {
+    return operator T();
+  }
+  
+  int AsInt() {
+    return this->operator int();
+  }
+};
+
+template float Foo::As();
+template double Foo::As2();
+
+// Partial ordering with conversion function templates.
+struct X0 {
+  template<typename T> operator T*() {
+    T x;
+    x = 17; // expected-error{{read-only variable is not assignable}}
+  }
+  
+  template<typename T> operator T*() const; // expected-note{{explicit instantiation refers here}}
+  
+  template<typename T> operator const T*() const {
+    T x = T();
+    return x; // expected-error{{cannot initialize return object of type 'char const *' with an lvalue of type 'char'}}
+  }
+};
+
+template X0::operator const char*() const; // expected-note{{'X0::operator char const *<char>' requested here}}
+template X0::operator const int*(); // expected-note{{'X0::operator int const *<int const>' requested here}}
+template X0::operator float*() const; // expected-error{{explicit instantiation of undefined function template}}
+
+void test_X0(X0 x0, const X0 &x0c) {
+  x0.operator const int*();
+  x0.operator float *();
+  x0c.operator const char*();
+}





More information about the cfe-commits mailing list