xref: /llvm-project/clang/test/SemaObjCXX/deduction.mm (revision da518417fa48d875a2950448f6c2027d816d51ad)
1bb4ea81aSJohn McCall// RUN: %clang_cc1 -fsyntax-only -verify %s
2bb4ea81aSJohn McCall
3bb4ea81aSJohn McCall@class NSString;
4bb4ea81aSJohn McCall
5bb4ea81aSJohn McCall// Reduced from WebKit.
6bb4ea81aSJohn McCallnamespace test0 {
7bb4ea81aSJohn McCall  template <typename T> struct RemovePointer {
8bb4ea81aSJohn McCall    typedef T Type;
9bb4ea81aSJohn McCall  };
10bb4ea81aSJohn McCall
11bb4ea81aSJohn McCall  template <typename T> struct RemovePointer<T*> {
12bb4ea81aSJohn McCall    typedef T Type;
13bb4ea81aSJohn McCall  };
14bb4ea81aSJohn McCall
15bb4ea81aSJohn McCall  template <typename T> struct RetainPtr {
16bb4ea81aSJohn McCall    typedef typename RemovePointer<T>::Type ValueType;
17bb4ea81aSJohn McCall    typedef ValueType* PtrType;
18bb4ea81aSJohn McCall    RetainPtr(PtrType ptr);
19bb4ea81aSJohn McCall  };
20bb4ea81aSJohn McCall
21bb4ea81aSJohn McCall  void test(NSString *S) {
22bb4ea81aSJohn McCall    RetainPtr<NSString*> ptr(S);
23bb4ea81aSJohn McCall  }
2401f21ad9SJohn McCall
2501f21ad9SJohn McCall  void test(id S) {
2601f21ad9SJohn McCall    RetainPtr<id> ptr(S);
2701f21ad9SJohn McCall  }
28bb4ea81aSJohn McCall}
298b07ec25SJohn McCall
308b07ec25SJohn McCall@class Test1Class;
318b07ec25SJohn McCall@protocol Test1Protocol;
328b07ec25SJohn McCallnamespace test1 {
338b07ec25SJohn McCall  template <typename T> struct RemovePointer {
348b07ec25SJohn McCall    typedef T type;
358b07ec25SJohn McCall  };
368b07ec25SJohn McCall  template <typename T> struct RemovePointer<T*> {
378b07ec25SJohn McCall    typedef T type;
388b07ec25SJohn McCall  };
398b07ec25SJohn McCall  template <typename A, typename B> struct is_same {};
408b07ec25SJohn McCall  template <typename A> struct is_same<A,A> {
418b07ec25SJohn McCall    static void foo();
428b07ec25SJohn McCall  };
438b07ec25SJohn McCall  template <typename T> struct tester {
448b07ec25SJohn McCall    void test() {
458b07ec25SJohn McCall      is_same<T, typename RemovePointer<T>::type*>::foo(); // expected-error 2 {{no member named 'foo'}}
468b07ec25SJohn McCall    }
478b07ec25SJohn McCall  };
488b07ec25SJohn McCall
498b07ec25SJohn McCall  template struct tester<id>;
508b07ec25SJohn McCall  template struct tester<id<Test1Protocol> >;
518b07ec25SJohn McCall  template struct tester<Class>;
528b07ec25SJohn McCall  template struct tester<Class<Test1Protocol> >;
538b07ec25SJohn McCall  template struct tester<Test1Class*>;
548b07ec25SJohn McCall  template struct tester<Test1Class<Test1Protocol>*>;
558b07ec25SJohn McCall
568b07ec25SJohn McCall  template struct tester<Test1Class>; // expected-note {{in instantiation}}
578b07ec25SJohn McCall  template struct tester<Test1Class<Test1Protocol> >; // expected-note {{in instantiation}}
588b07ec25SJohn McCall}
59*da518417SJohn McCall
60*da518417SJohn McCallnamespace test2 {
61*da518417SJohn McCall  template <typename T> void foo(const T* t) {}
62*da518417SJohn McCall  void test(id x) {
63*da518417SJohn McCall    foo(x);
64*da518417SJohn McCall  }
65*da518417SJohn McCall}
66