no-body.cpp revision 4447af930ab888a3a37cadaa2e638f54bbd9c2ea
17c64ef05e179d29646030e9d453081844ecc537aLarisse Voufo// RUN: %clang_cc1 -fsyntax-only -verify %s
2472e66e9d32e587a028bc676aa63bd7137f3d4d4Larisse Voufo// RUN: cp %s %t
34447af930ab888a3a37cadaa2e638f54bbd9c2eaLarisse Voufo// RUN: not %clang_cc1 -x c++ -fixit %t -DFIXING
44447af930ab888a3a37cadaa2e638f54bbd9c2eaLarisse Voufo// RUN: %clang_cc1 -x c++ %t -DFIXING
57c64ef05e179d29646030e9d453081844ecc537aLarisse Voufo
67c64ef05e179d29646030e9d453081844ecc537aLarisse Voufotemplate<typename T> void f(T) { }
77c64ef05e179d29646030e9d453081844ecc537aLarisse Voufotemplate<typename T> void g(T) { }
87c64ef05e179d29646030e9d453081844ecc537aLarisse Voufotemplate<typename T> struct x { };
97c64ef05e179d29646030e9d453081844ecc537aLarisse Voufotemplate<typename T> struct y { };  // expected-note {{declared here}}
107c64ef05e179d29646030e9d453081844ecc537aLarisse Voufo
117c64ef05e179d29646030e9d453081844ecc537aLarisse Voufonamespace good {
127c64ef05e179d29646030e9d453081844ecc537aLarisse Voufo  template void f<int>(int);
137c64ef05e179d29646030e9d453081844ecc537aLarisse Voufo  template void g(int);
147c64ef05e179d29646030e9d453081844ecc537aLarisse Voufo  template struct x<int>;
157c64ef05e179d29646030e9d453081844ecc537aLarisse Voufo}
167c64ef05e179d29646030e9d453081844ecc537aLarisse Voufo
177c64ef05e179d29646030e9d453081844ecc537aLarisse Voufonamespace unsupported {
184447af930ab888a3a37cadaa2e638f54bbd9c2eaLarisse Voufo#ifndef FIXING
197c64ef05e179d29646030e9d453081844ecc537aLarisse Voufo template struct y;     // expected-error {{elaborated type refers to a template}}
204447af930ab888a3a37cadaa2e638f54bbd9c2eaLarisse Voufo#endif
217c64ef05e179d29646030e9d453081844ecc537aLarisse Voufo}
227c64ef05e179d29646030e9d453081844ecc537aLarisse Voufo
237c64ef05e179d29646030e9d453081844ecc537aLarisse Voufotemplate<typename T> void f0(T) { }
247c64ef05e179d29646030e9d453081844ecc537aLarisse Voufotemplate<typename T> void g0(T) { }
257c64ef05e179d29646030e9d453081844ecc537aLarisse Voufotemplate<typename T> struct x0 { }; // expected-note {{explicitly specialized declaration is here}}
267c64ef05e179d29646030e9d453081844ecc537aLarisse Voufotemplate<typename T> struct y0 { };
277c64ef05e179d29646030e9d453081844ecc537aLarisse Voufo
287c64ef05e179d29646030e9d453081844ecc537aLarisse Voufo// Should recover as if definition
297c64ef05e179d29646030e9d453081844ecc537aLarisse Voufonamespace noargs_body {
304447af930ab888a3a37cadaa2e638f54bbd9c2eaLarisse Voufo#ifndef FIXING
317c64ef05e179d29646030e9d453081844ecc537aLarisse Voufo  template void g0(int) { } // expected-error {{function cannot be defined in an explicit instantiation; if this declaration is meant to be a function definition, remove the 'template' keyword}}
324447af930ab888a3a37cadaa2e638f54bbd9c2eaLarisse Voufo#endif
334447af930ab888a3a37cadaa2e638f54bbd9c2eaLarisse Voufo  template struct y0 { };     // expected-error {{class cannot be defined in an explicit instantiation; if this declaration is meant to be a class definition, remove the 'template' keyword}}
347c64ef05e179d29646030e9d453081844ecc537aLarisse Voufo}
357c64ef05e179d29646030e9d453081844ecc537aLarisse Voufo
367c64ef05e179d29646030e9d453081844ecc537aLarisse Voufo// Explicit specializations expected in global scope
377c64ef05e179d29646030e9d453081844ecc537aLarisse Voufonamespace exp_spec {
384447af930ab888a3a37cadaa2e638f54bbd9c2eaLarisse Voufo#ifndef FIXING
397c64ef05e179d29646030e9d453081844ecc537aLarisse Voufo  template<> void f0<int>(int) { }  // expected-error {{no function template matches function template specialization 'f0'}}
407c64ef05e179d29646030e9d453081844ecc537aLarisse Voufo  template<> struct x0<int> { };    // expected-error {{class template specialization of 'x0' must originally be declared in the global scope}}
414447af930ab888a3a37cadaa2e638f54bbd9c2eaLarisse Voufo#endif
427c64ef05e179d29646030e9d453081844ecc537aLarisse Voufo}
437c64ef05e179d29646030e9d453081844ecc537aLarisse Voufo
447c64ef05e179d29646030e9d453081844ecc537aLarisse Voufotemplate<typename T> void f1(T) { }
457c64ef05e179d29646030e9d453081844ecc537aLarisse Voufotemplate<typename T> struct x1 { };  // expected-note {{explicitly specialized declaration is here}}
467c64ef05e179d29646030e9d453081844ecc537aLarisse Voufo
477c64ef05e179d29646030e9d453081844ecc537aLarisse Voufo// Should recover as if specializations,
487c64ef05e179d29646030e9d453081844ecc537aLarisse Voufo// thus also complain about not being in global scope.
497c64ef05e179d29646030e9d453081844ecc537aLarisse Voufonamespace args_bad {
504447af930ab888a3a37cadaa2e638f54bbd9c2eaLarisse Voufo#ifndef FIXING
517c64ef05e179d29646030e9d453081844ecc537aLarisse Voufo  template void f1<int>(int) { }    // expected-error {{explicit template instantiation cannot have a definition; if this definition is meant to be an explicit specialization, add '<>' after the 'template' keyword}} \
527c64ef05e179d29646030e9d453081844ecc537aLarisse Voufo                                       expected-error {{no function template matches function template specialization 'f1'}}
537c64ef05e179d29646030e9d453081844ecc537aLarisse Voufo  template struct x1<int> { };      // expected-error {{explicit template instantiation cannot have a definition; if this definition is meant to be an explicit specialization, add '<>' after the 'template' keyword}} \
547c64ef05e179d29646030e9d453081844ecc537aLarisse Voufo                                       expected-error {{class template specialization of 'x1' must originally be declared in the global scope}}
554447af930ab888a3a37cadaa2e638f54bbd9c2eaLarisse Voufo#endif
567c64ef05e179d29646030e9d453081844ecc537aLarisse Voufo}
577c64ef05e179d29646030e9d453081844ecc537aLarisse Voufo
587c64ef05e179d29646030e9d453081844ecc537aLarisse Voufotemplate<typename T> void f2(T) { }
597c64ef05e179d29646030e9d453081844ecc537aLarisse Voufotemplate<typename T> struct x2 { };
607c64ef05e179d29646030e9d453081844ecc537aLarisse Voufo
617c64ef05e179d29646030e9d453081844ecc537aLarisse Voufo// Should recover as if specializations
627c64ef05e179d29646030e9d453081844ecc537aLarisse Voufotemplate void f2<int>(int) { }    // expected-error {{explicit template instantiation cannot have a definition; if this definition is meant to be an explicit specialization, add '<>' after the 'template' keyword}}
637c64ef05e179d29646030e9d453081844ecc537aLarisse Voufotemplate struct x2<int> { };      // expected-error {{explicit template instantiation cannot have a definition; if this definition is meant to be an explicit specialization, add '<>' after the 'template' keyword}}
64