1// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=clc++ -fsyntax-only -verify
2// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=clc++ -fsyntax-only -verify -DFUNCPTREXT
3
4#ifdef FUNCPTREXT
5#pragma OPENCL EXTENSION __cl_clang_function_pointers : enable
6//expected-no-diagnostics
7#endif
8
9// Test that virtual functions and abstract classes are rejected
10// unless specific clang extension is used.
11class virtual_functions {
12  virtual void bad1() {}
13#ifndef FUNCPTREXT
14  //expected-error@-2 {{virtual functions are not supported in C++ for OpenCL}}
15#endif
16
17  virtual void bad2() = 0;
18#ifndef FUNCPTREXT
19  //expected-error@-2 {{virtual functions are not supported in C++ for OpenCL}}
20  //expected-error@-3 {{'bad2' is not virtual and cannot be declared pure}}
21#endif
22};
23
24template <typename T>
25class X {
26  virtual T f();
27#ifndef FUNCPTREXT
28  //expected-error@-2 {{virtual functions are not supported in C++ for OpenCL}}
29#endif
30};
31
32// Test that virtual base classes are allowed.
33struct A {
34  int a;
35  void foo();
36};
37
38struct B : virtual A {
39  int b;
40};
41
42struct C : public virtual A {
43  int c;
44};
45
46struct D : B, C {
47  int d;
48};
49
50kernel void virtual_inheritance() {
51  D d;
52
53  d.foo();
54  d.a = 11;
55  d.b = 22;
56  d.c = 33;
57  d.d = 44;
58}
59