1// RUN: %clang_cc1 -fms-compatibility -std=c++11 %s -verify 2 3// MSVC should compile this file without errors. 4 5namespace test_basic { 6template <typename T = Baz> // expected-warning {{using the undeclared type 'Baz' as a default template argument is a Microsoft extension}} 7struct Foo { T x; }; 8typedef int Baz; 9template struct Foo<>; 10} 11 12namespace test_namespace { 13namespace nested { 14template <typename T = Baz> // expected-warning {{using the undeclared type 'Baz' as a default template argument is a Microsoft extension}} 15struct Foo { 16 static_assert(sizeof(T) == 4, "should get int, not double"); 17}; 18typedef int Baz; 19} 20typedef double Baz; 21template struct nested::Foo<>; 22} 23 24namespace test_inner_class_template { 25struct Outer { 26 template <typename T = Baz> // expected-warning {{using the undeclared type 'Baz' as a default template argument is a Microsoft extension}} 27 struct Foo { 28 static_assert(sizeof(T) == 4, "should get int, not double"); 29 }; 30 typedef int Baz; 31}; 32typedef double Baz; 33template struct Outer::Foo<>; 34} 35 36namespace test_nontype_param { 37template <typename T> struct Bar { T x; }; 38typedef int Qux; 39template <Bar<Qux> *P> 40struct Foo { 41}; 42Bar<int> g; 43template struct Foo<&g>; 44} 45 46// MSVC accepts this, but Clang doesn't. 47namespace test_template_instantiation_arg { 48template <typename T> struct Bar { T x; }; 49template <typename T = Bar<Weber>> // expected-error {{use of undeclared identifier 'Weber'}} 50struct Foo { 51 static_assert(sizeof(T) == 4, "Bar should have gotten int"); 52 // FIXME: These diagnostics are bad. 53}; // expected-error {{expected ',' or '>' in template-parameter-list}} 54// expected-warning@-1 {{does not declare anything}} 55typedef int Weber; 56} 57 58#ifdef __clang__ 59// These are negative test cases that MSVC doesn't compile either. Try to use 60// unique undeclared identifiers so typo correction doesn't find types declared 61// above. 62 63namespace test_undeclared_nontype_parm_type { 64template <Zargon N> // expected-error {{unknown type name 'Zargon'}} 65struct Foo { int x[N]; }; 66typedef int Zargon; 67template struct Foo<4>; 68} 69 70namespace test_undeclared_nontype_parm_type_no_name { 71template <typename T, Asdf> // expected-error {{unknown type name 'Asdf'}} 72struct Foo { T x; }; 73template struct Foo<int, 0>; 74} 75 76namespace test_undeclared_type_arg { 77template <typename T> 78struct Foo { T x; }; 79template struct Foo<Yodel>; // expected-error {{use of undeclared identifier 'Yodel'}} 80} 81 82namespace test_undeclared_nontype_parm_arg { 83// Bury an undeclared type as a template argument to the type of a non-type 84// template parameter. 85template <typename T> struct Bar { T x; }; 86 87template <Bar<Xylophone> *P> // expected-error {{use of undeclared identifier 'Xylophone'}} 88// expected-note@-1 {{template parameter is declared here}} 89struct Foo { }; 90 91typedef int Xylophone; 92Bar<Xylophone> g; 93template struct Foo<&g>; // expected-error {{cannot be converted}} 94} 95 96#endif 97