37 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -Wundefined-func-template -Wundefined-var-template -verify %s2 3// Test that a diagnostic is emitted when an entity marked with the4// exclude_from_explicit_instantiation attribute is not defined in5// the current TU but it is used (and it is hence implicitly6// instantiated).7 8#define EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((exclude_from_explicit_instantiation))9 10template <class T>11struct 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}}17 };18};19 20extern template struct Foo<int>;21 22void use() {23 Foo<int> foo;24 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}}27 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}}30 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}}33 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}}36}37