18d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin -g -emit-llvm -o - | FileCheck %s
28d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt// This test is for a crash when emitting debug info for not-yet-completed
38d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt// types.
48d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt// Test that we don't actually emit a forward decl for the offending class:
5c5ec7f57ead87efa365800228aa0b09a12d9e6c4Dmitry Shmidt// CHECK:  [ DW_TAG_structure_type ] [Derived<int>] {{.*}} [def]
6c5ec7f57ead87efa365800228aa0b09a12d9e6c4Dmitry Shmidt// rdar://problem/15931354
78d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidttemplate <class A> class Derived;
88d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt
98d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidttemplate <class A> class Base {
108d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt  static Derived<A> *create();
118d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt};
128d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt
138d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidttemplate <class A> struct Derived : Base<A> {
148d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt};
158d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt
168d520ff1dc2da35cdca849e982051b86468016d8Dmitry ShmidtBase<int> *f;
178d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt
188d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt// During the instantiation of Derived<int>, Base<int> becomes required to be
198d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt// complete - since the declaration has already been emitted (due to 'f',
208d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt// above), we immediately try to build debug info for Base<int> which then
218d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt// requires the (incomplete definition) of Derived<int> which is problematic.
228d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt//
238d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt// (if 'f' is not present, the point at which Base<int> becomes required to be
248d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt// complete during the instantiation of Derived<int> is a no-op because
258d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt// Base<int> was never emitted so we ignore it and carry on until we
268d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt// wire up the base class of Derived<int> in the debug info later on)
278d520ff1dc2da35cdca849e982051b86468016d8Dmitry ShmidtDerived<int> d;
288d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt