| 1 |
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++2a %s |
| 2 |
|
| 3 |
namespace basic { |
| 4 |
struct ForwardDeclaration; // expected-note{{forward declaration of 'basic::ForwardDeclaration'}} |
| 5 |
// expected-note@-1{{forward declaration of 'basic::ForwardDeclaration'}} |
| 6 |
struct NonPolymorphic {}; |
| 7 |
struct Polymorphic { |
| 8 |
virtual ~Polymorphic(); |
| 9 |
}; |
| 10 |
|
| 11 |
template <typename T> |
| 12 |
struct Foo { |
| 13 |
virtual ~Foo(); |
| 14 |
}; |
| 15 |
|
| 16 |
template <> |
| 17 |
struct Foo<int> { |
| 18 |
}; |
| 19 |
|
| 20 |
template <typename T> |
| 21 |
struct Bar { |
| 22 |
using SubType = typename T::SubType; |
| 23 |
SubType *ty() const; |
| 24 |
}; |
| 25 |
|
| 26 |
struct Thing1 { |
| 27 |
using SubType = Thing1; |
| 28 |
}; |
| 29 |
|
| 30 |
struct Thing2 { |
| 31 |
using SubType = Thing2; |
| 32 |
virtual ~Thing2(); |
| 33 |
}; |
| 34 |
|
| 35 |
struct Thing3 { |
| 36 |
using SubType = int; |
| 37 |
}; |
| 38 |
|
| 39 |
struct Thing4 { |
| 40 |
using SubType = Polymorphic; |
| 41 |
}; |
| 42 |
|
| 43 |
struct Thing5 { |
| 44 |
using SubType = NonPolymorphic; |
| 45 |
}; |
| 46 |
|
| 47 |
struct Thing6 { |
| 48 |
using SubType = ForwardDeclaration; |
| 49 |
}; |
| 50 |
|
| 51 |
template <typename T> |
| 52 |
const void *getThing(const Bar<T> *b = nullptr) { |
| 53 |
return __builtin_get_vtable_pointer(b->ty()); // expected-error{{__builtin_get_vtable_pointer requires an argument of class pointer type, but 'SubType *' (aka 'int *') was provided}} |
| 54 |
// expected-error@-1{{__builtin_get_vtable_pointer requires an argument of polymorphic class pointer type, but 'Thing1' has no virtual methods}} |
| 55 |
// expected-error@-2{{__builtin_get_vtable_pointer requires an argument of polymorphic class pointer type, but 'NonPolymorphic' has no virtual methods}} |
| 56 |
// expected-error@-3{{__builtin_get_vtable_pointer requires an argument with a complete type, but 'SubType' (aka 'ForwardDeclaration') is incomplete}} |
| 57 |
} |
| 58 |
template <typename> |
| 59 |
struct IncompleteTemplate; // expected-note{{template is declared here}} |
| 60 |
template <typename> |
| 61 |
struct MonomorphicTemplate { |
| 62 |
}; |
| 63 |
template <typename> |
| 64 |
struct PolymorphicTemplate { |
| 65 |
virtual ~PolymorphicTemplate(); |
| 66 |
}; |
| 67 |
|
| 68 |
void test_function(int); // expected-note{{possible target for call}} |
| 69 |
void test_function(double); // expected-note{{possible target for call}} |
| 70 |
|
| 71 |
void getVTablePointer() { |
| 72 |
ForwardDeclaration *fd = nullptr; |
| 73 |
NonPolymorphic np; |
| 74 |
Polymorphic p; |
| 75 |
NonPolymorphic np_array[1]; |
| 76 |
Polymorphic p_array[1]; |
| 77 |
__builtin_get_vtable_pointer(0); // expected-error{{__builtin_get_vtable_pointer requires an argument of class pointer type, but 'int' was provided}} |
| 78 |
__builtin_get_vtable_pointer(nullptr); // expected-error{{__builtin_get_vtable_pointer requires an argument of class pointer type, but 'std::nullptr_t' was provided}} |
| 79 |
__builtin_get_vtable_pointer(0.5); // expected-error{{__builtin_get_vtable_pointer requires an argument of class pointer type, but 'double' was provided}} |
| 80 |
__builtin_get_vtable_pointer(fd); // expected-error{{__builtin_get_vtable_pointer requires an argument with a complete type, but 'ForwardDeclaration' is incomplete}} |
| 81 |
__builtin_get_vtable_pointer(np); // expected-error{{__builtin_get_vtable_pointer requires an argument of class pointer type, but 'NonPolymorphic' was provided}} |
| 82 |
__builtin_get_vtable_pointer(&np); // expected-error{{__builtin_get_vtable_pointer requires an argument of polymorphic class pointer type, but 'NonPolymorphic' has no virtual methods}} |
| 83 |
__builtin_get_vtable_pointer(p); // expected-error{{__builtin_get_vtable_pointer requires an argument of class pointer type, but 'Polymorphic' was provided}} |
| 84 |
__builtin_get_vtable_pointer(&p); // expected-warning{{ignoring return value of function declared with const attribute}} |
| 85 |
__builtin_get_vtable_pointer(p_array); // expected-warning{{ignoring return value of function declared with const attribute}} |
| 86 |
__builtin_get_vtable_pointer(&p_array); // expected-error{{__builtin_get_vtable_pointer requires an argument of class pointer type, but 'Polymorphic (*)[1]' was provided}} |
| 87 |
__builtin_get_vtable_pointer(np_array); // expected-error{{__builtin_get_vtable_pointer requires an argument of polymorphic class pointer type, but 'NonPolymorphic' has no virtual methods}} |
| 88 |
__builtin_get_vtable_pointer(&np_array); // expected-error{{__builtin_get_vtable_pointer requires an argument of class pointer type, but 'NonPolymorphic (*)[1]' was provided}} |
| 89 |
__builtin_get_vtable_pointer(test_function); // expected-error{{reference to overloaded function could not be resolved; did you mean to call it?}} |
| 90 |
Foo<double> Food; |
| 91 |
Foo<int> Fooi; |
| 92 |
__builtin_get_vtable_pointer(Food); // expected-error{{__builtin_get_vtable_pointer requires an argument of class pointer type, but 'Foo<double>' was provided}} |
| 93 |
(void)__builtin_get_vtable_pointer(&Food); |
| 94 |
__builtin_get_vtable_pointer(Fooi); // expected-error{{__builtin_get_vtable_pointer requires an argument of class pointer type, but 'Foo<int>' was provided}} |
| 95 |
__builtin_get_vtable_pointer(&Fooi); // expected-error{{__builtin_get_vtable_pointer requires an argument of polymorphic class pointer type, but 'Foo<int>' has no virtual methods}} |
| 96 |
|
| 97 |
IncompleteTemplate<bool> *incomplete = nullptr; |
| 98 |
(void)__builtin_get_vtable_pointer(incomplete); // expected-error{{implicit instantiation of undefined template 'basic::IncompleteTemplate<bool>'}} |
| 99 |
PolymorphicTemplate<bool> *ptb = nullptr; |
| 100 |
MonomorphicTemplate<bool> *mtb = nullptr; |
| 101 |
PolymorphicTemplate<int> pti; |
| 102 |
MonomorphicTemplate<int> mti; |
| 103 |
PolymorphicTemplate<float> ptf; |
| 104 |
MonomorphicTemplate<float> mtf; |
| 105 |
(void)__builtin_get_vtable_pointer(ptb); |
| 106 |
__builtin_get_vtable_pointer(mtb); // expected-error{{__builtin_get_vtable_pointer requires an argument of polymorphic class pointer type, but 'MonomorphicTemplate<bool>' has no virtual methods}} |
| 107 |
__builtin_get_vtable_pointer(pti); // expected-error{{__builtin_get_vtable_pointer requires an argument of class pointer type, but 'PolymorphicTemplate<int>' was provided}} |
| 108 |
__builtin_get_vtable_pointer(mti); // expected-error{{__builtin_get_vtable_pointer requires an argument of class pointer type, but 'MonomorphicTemplate<int>' was provided}} |
| 109 |
(void)__builtin_get_vtable_pointer(&ptf); |
| 110 |
__builtin_get_vtable_pointer(&mtf); // expected-error{{__builtin_get_vtable_pointer requires an argument of polymorphic class pointer type, but 'MonomorphicTemplate<float>' has no virtual methods}} |
| 111 |
|
| 112 |
getThing<Thing1>(); // expected-note{{in instantiation of function template specialization 'basic::getThing<basic::Thing1>' requested here}} |
| 113 |
getThing<Thing2>(); |
| 114 |
getThing<Thing3>(); // expected-note{{in instantiation of function template specialization 'basic::getThing<basic::Thing3>' requested here}} |
| 115 |
getThing<Thing4>(); |
| 116 |
getThing<Thing5>(); // expected-note{{in instantiation of function template specialization 'basic::getThing<basic::Thing5>' requested here}} |
| 117 |
getThing<Thing6>(); // expected-note{{in instantiation of function template specialization 'basic::getThing<basic::Thing6>' requested here}} |
| 118 |
} |
| 119 |
|
| 120 |
} // namespace basic |