reference, declarationdefinition
definition → references, declarations, derived classes, virtual overrides
reference to multiple definitions → definitions
unreferenced
    1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -O0 -o - %s | FileCheck %s

// Test that we do not assume that entities marked with the
// exclude_from_explicit_instantiation attribute are instantiated
// in another TU when an extern template instantiation declaration
// is present. We test that by making sure that definitions are
// generated in this TU despite there being an extern template
// instantiation declaration, which is normally not the case.

#define EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((exclude_from_explicit_instantiation))

template <class T>
struct Foo {
  EXCLUDE_FROM_EXPLICIT_INSTANTIATION        inline void non_static_member_function1();
  EXCLUDE_FROM_EXPLICIT_INSTANTIATION               void non_static_member_function2();

  EXCLUDE_FROM_EXPLICIT_INSTANTIATION static inline void static_member_function1();
  EXCLUDE_FROM_EXPLICIT_INSTANTIATION static        void static_member_function2();

  EXCLUDE_FROM_EXPLICIT_INSTANTIATION static        int static_data_member;

  struct EXCLUDE_FROM_EXPLICIT_INSTANTIATION member_class1 {
    static void static_member_function() { }
  };

  struct member_class2 {
    EXCLUDE_FROM_EXPLICIT_INSTANTIATION static void static_member_function() { }
  };
};

template <class T> inline void Foo<T>::non_static_member_function1() { }
template <class T>        void Foo<T>::non_static_member_function2() { }

template <class T> inline void Foo<T>::static_member_function1() { }
template <class T>        void Foo<T>::static_member_function2() { }

template <class T>        int Foo<T>::static_data_member = 0;

extern template struct Foo<int>;

void use() {
  Foo<int> f;

  // An inline non-static member function marked with the attribute is not
  // part of the extern template declaration, so a definition must be emitted
  // in this TU.
  // CHECK-DAG: define linkonce_odr void @_ZN3FooIiE27non_static_member_function1Ev
  f.non_static_member_function1();

  // A non-inline non-static member function marked with the attribute is
  // not part of the extern template declaration, so a definition must be
  // emitted in this TU.
  // CHECK-DAG: define linkonce_odr void @_ZN3FooIiE27non_static_member_function2Ev
  f.non_static_member_function2();

  // An inline static member function marked with the attribute is not
  // part of the extern template declaration, so a definition must be
  // emitted in this TU.
  // CHECK-DAG: define linkonce_odr void @_ZN3FooIiE23static_member_function1Ev
  Foo<int>::static_member_function1();

  // A non-inline static member function marked with the attribute is not
  // part of the extern template declaration, so a definition must be
  // emitted in this TU.
  // CHECK-DAG: define linkonce_odr void @_ZN3FooIiE23static_member_function2Ev
  Foo<int>::static_member_function2();

  // A static data member marked with the attribute is not part of the
  // extern template declaration, so a definition must be emitted in this TU.
  // CHECK-DAG: @_ZN3FooIiE18static_data_memberE = linkonce_odr global
  int& odr_use = Foo<int>::static_data_member;

  // A member class marked with the attribute is not part of the extern
  // template declaration (it is not recursively instantiated), so its member
  // functions must be emitted in this TU.
  // CHECK-DAG: define linkonce_odr void @_ZN3FooIiE13member_class122static_member_functionEv
  Foo<int>::member_class1::static_member_function();

  // A member function marked with the attribute in a member class is not
  // part of the extern template declaration of the parent class template, so
  // it must be emitted in this TU.
  // CHECK-DAG: define linkonce_odr void @_ZN3FooIiE13member_class222static_member_functionEv
  Foo<int>::member_class2::static_member_function();
}