Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / SemaCXX / attr-exclude_from_explicit_instantiation.extern_declaration.cpp
blob4cb02252ba3505da03ebea234b8255a83c8cb59a
1 // RUN: %clang_cc1 -Wno-unused-local-typedef -fsyntax-only -verify %s
3 // Test that extern instantiation declarations cause members marked with
4 // the exclude_from_explicit_instantiation attribute to be instantiated in
5 // the current TU.
7 #define EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((exclude_from_explicit_instantiation))
9 template <class T>
10 struct Foo {
11 EXCLUDE_FROM_EXPLICIT_INSTANTIATION inline void non_static_member_function1();
13 EXCLUDE_FROM_EXPLICIT_INSTANTIATION void non_static_member_function2();
15 EXCLUDE_FROM_EXPLICIT_INSTANTIATION static inline void static_member_function1();
17 EXCLUDE_FROM_EXPLICIT_INSTANTIATION static void static_member_function2();
19 EXCLUDE_FROM_EXPLICIT_INSTANTIATION static int static_data_member;
21 struct EXCLUDE_FROM_EXPLICIT_INSTANTIATION member_class1 {
22 static void static_member_function() {
23 using Fail = typename T::invalid; // expected-error{{no type named 'invalid' in 'Empty'}}
27 struct member_class2 {
28 EXCLUDE_FROM_EXPLICIT_INSTANTIATION static void static_member_function() {
29 using Fail = typename T::invalid; // expected-error{{no type named 'invalid' in 'Empty'}}
34 template <class T>
35 inline void Foo<T>::non_static_member_function1() {
36 using Fail = typename T::invalid; // expected-error{{no type named 'invalid' in 'Empty'}}
39 template <class T>
40 void Foo<T>::non_static_member_function2() {
41 using Fail = typename T::invalid; // expected-error{{no type named 'invalid' in 'Empty'}}
44 template <class T>
45 inline void Foo<T>::static_member_function1() {
46 using Fail = typename T::invalid; // expected-error{{no type named 'invalid' in 'Empty'}}
49 template <class T>
50 void Foo<T>::static_member_function2() {
51 using Fail = typename T::invalid; // expected-error{{no type named 'invalid' in 'Empty'}}
54 template <class T>
55 int Foo<T>::static_data_member = T::invalid; // expected-error{{no member named 'invalid' in 'Empty'}}
57 struct Empty { };
58 extern template struct Foo<Empty>;
60 int main() {
61 Foo<Empty> foo;
62 foo.non_static_member_function1(); // expected-note{{in instantiation of}}
63 foo.non_static_member_function2(); // expected-note{{in instantiation of}}
64 Foo<Empty>::static_member_function1(); // expected-note{{in instantiation of}}
65 Foo<Empty>::static_member_function2(); // expected-note{{in instantiation of}}
66 (void)foo.static_data_member; // expected-note{{in instantiation of}}
67 Foo<Empty>::member_class1::static_member_function(); // expected-note{{in instantiation of}}
68 Foo<Empty>::member_class2::static_member_function(); // expected-note{{in instantiation of}}