1efeeccfb5efa94b6b4198298a80ad9a699bebcceRichard Smith// RUN: %clang_cc1 -fsyntax-only -verify %s -pedantic
21f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlssontemplate<typename T>
31f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlssonstruct S {
41f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson S() { }
51f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson};
61f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson
71f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlssontemplate<typename T>
81f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlssonstruct vector {
9b2b5cc0cf908d516a107d373db963f692449a8a8Chandler Carruth  void push_back(const T&) { int a[sizeof(T) ? -1: -1]; } // expected-error {{array with a negative size}}
101f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson};
111f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson
12d2592a34a059e7cbb2b11dc53649ac4912422909Argyrios Kyrtzidisclass ExprEngine {
131f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlssonpublic:
141f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson typedef vector<S<void *> >CheckersOrdered;
151f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson CheckersOrdered Checkers;
161f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson
171f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson template <typename CHECKER>
181f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson void registerCheck(CHECKER *check) {
197c2342dd4c9947806842e5aca3d2bb2e542853c9John McCall   Checkers.push_back(S<void *>()); // expected-note {{in instantiation of member function 'vector<S<void *> >::push_back' requested here}}
201f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson }
211f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson};
221f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson
231f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlssonclass RetainReleaseChecker { };
241f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson
25d2592a34a059e7cbb2b11dc53649ac4912422909Argyrios Kyrtzidisvoid f(ExprEngine& Eng) {
26d2592a34a059e7cbb2b11dc53649ac4912422909Argyrios Kyrtzidis   Eng.registerCheck(new RetainReleaseChecker); // expected-note {{in instantiation of function template specialization 'ExprEngine::registerCheck<RetainReleaseChecker>' requested here}}
271f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson}
28c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall
29c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall// PR 5838
30c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCallnamespace test1 {
31c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  template<typename T> struct A {
32c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall    int a;
33c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  };
34c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall
35c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  template<typename T> struct B : A<float>, A<T> {
36c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall    void f() {
37c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall      a = 0; // should not be ambiguous
38c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall    }
39c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  };
40c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  template struct B<int>;
41c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall
42c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  struct O {
43c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall    int a;
44c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall    template<typename T> struct B : A<T> {
45c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall      void f() {
46110acc1ae8d978f9b423394eaf0cace61b1339f0John McCall        a = 0; // expected-error {{'test1::O::a' is not a member of class 'test1::O::B<int>'}}
47c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall      }
48c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall    };
49c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  };
50c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  template struct O::B<int>; // expected-note {{in instantiation}}
51c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall}
5243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
5343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall// PR7248
5443fed0de4f5bc189e45562491f83d5193eb8dac0John McCallnamespace test2 {
5543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  template <class T> struct A {
5643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    void foo() {
5743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      T::bar(); // expected-error {{type 'int' cannot}}
5843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    }
5943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  };
6043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
6143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  template <class T> class B {
6243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    void foo(A<T> a) {
6343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      a.test2::template A<T>::foo(); // expected-note {{in instantiation}}
6443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    }
6543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  };
6643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
6743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  template class B<int>;
6843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall}
69efeeccfb5efa94b6b4198298a80ad9a699bebcceRichard Smith
70efeeccfb5efa94b6b4198298a80ad9a699bebcceRichard Smithnamespace PR14124 {
71efeeccfb5efa94b6b4198298a80ad9a699bebcceRichard Smith  template<typename T> struct S {
72efeeccfb5efa94b6b4198298a80ad9a699bebcceRichard Smith    int value;
73efeeccfb5efa94b6b4198298a80ad9a699bebcceRichard Smith  };
74efeeccfb5efa94b6b4198298a80ad9a699bebcceRichard Smith  template<typename T> void f() { S<T>::value; } // expected-error {{invalid use of non-static data member 'value'}}
75efeeccfb5efa94b6b4198298a80ad9a699bebcceRichard Smith  template void f<int>(); // expected-note {{in instantiation of}}
76efeeccfb5efa94b6b4198298a80ad9a699bebcceRichard Smith
77efeeccfb5efa94b6b4198298a80ad9a699bebcceRichard Smith  struct List { List *next; };
78efeeccfb5efa94b6b4198298a80ad9a699bebcceRichard Smith  template<typename T, T *(T::*p) = &T::next> struct A {};
79efeeccfb5efa94b6b4198298a80ad9a699bebcceRichard Smith  A<List> a; // ok
80efeeccfb5efa94b6b4198298a80ad9a699bebcceRichard Smith  void operator&(struct Whatever);
81efeeccfb5efa94b6b4198298a80ad9a699bebcceRichard Smith  template<typename T, T *(T::*p) = &T::next> struct B {};
82efeeccfb5efa94b6b4198298a80ad9a699bebcceRichard Smith  B<List> b; // still ok
83efeeccfb5efa94b6b4198298a80ad9a699bebcceRichard Smith}
84