[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaCXX / attr-exclude_from_explicit_instantiation.diagnose_on_undefined_entity.cpp
blob24e24221939fa400cd88632dc52d620dc208144d
1 // RUN: %clang_cc1 -fsyntax-only -Wundefined-func-template -Wundefined-var-template -verify %s
3 // Test that a diagnostic is emitted when an entity marked with the
4 // exclude_from_explicit_instantiation attribute is not defined in
5 // the current TU but it is used (and it is hence implicitly
6 // instantiated).
8 #define EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((exclude_from_explicit_instantiation))
10 template <class T>
11 struct Foo {
12 EXCLUDE_FROM_EXPLICIT_INSTANTIATION void non_static_member_function(); // expected-note{{forward declaration of template entity is here}}
13 EXCLUDE_FROM_EXPLICIT_INSTANTIATION static void static_member_function(); // expected-note{{forward declaration of template entity is here}}
14 EXCLUDE_FROM_EXPLICIT_INSTANTIATION static int static_data_member; // expected-note{{forward declaration of template entity is here}}
15 struct EXCLUDE_FROM_EXPLICIT_INSTANTIATION nested {
16 static int static_member_function(); // expected-note{{forward declaration of template entity is here}}
20 extern template struct Foo<int>;
22 void use() {
23 Foo<int> foo;
25 foo.non_static_member_function(); // expected-warning{{instantiation of function 'Foo<int>::non_static_member_function' required here, but no definition is available}}
26 // expected-note@-1 {{add an explicit instantiation}}
28 Foo<int>::static_member_function(); // expected-warning{{instantiation of function 'Foo<int>::static_member_function' required here, but no definition is available}}
29 // expected-note@-1 {{add an explicit instantiation}}
31 (void)Foo<int>::static_data_member; // expected-warning{{instantiation of variable 'Foo<int>::static_data_member' required here, but no definition is available}}
32 // expected-note@-1 {{add an explicit instantiation}}
34 Foo<int>::nested::static_member_function(); // expected-warning{{instantiation of function 'Foo<int>::nested::static_member_function' required here, but no definition is available}}
35 // expected-note@-1 {{add an explicit instantiation}}