Sven van Haastregt | 49ffffb | 2018-04-23 11:23:47 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -fsyntax-only -verify |
| 2 | |
| 3 | // Test that virtual functions and abstract classes are rejected. |
| 4 | class virtual_functions { |
| 5 | virtual void bad1() {} |
| 6 | //expected-error@-1 {{virtual functions are not supported in OpenCL C++}} |
| 7 | |
| 8 | virtual void bad2() = 0; |
| 9 | //expected-error@-1 {{virtual functions are not supported in OpenCL C++}} |
| 10 | //expected-error@-2 {{'bad2' is not virtual and cannot be declared pure}} |
| 11 | }; |
| 12 | |
| 13 | template <typename T> |
| 14 | class X { |
| 15 | virtual T f(); |
| 16 | //expected-error@-1 {{virtual functions are not supported in OpenCL C++}} |
| 17 | }; |
| 18 | |
| 19 | // Test that virtual base classes are allowed. |
| 20 | struct A { |
| 21 | int a; |
| 22 | void foo(); |
| 23 | }; |
| 24 | |
| 25 | struct B : virtual A { |
| 26 | int b; |
| 27 | }; |
| 28 | |
| 29 | struct C : public virtual A { |
| 30 | int c; |
| 31 | }; |
| 32 | |
| 33 | struct D : B, C { |
| 34 | int d; |
| 35 | }; |
| 36 | |
| 37 | kernel void virtual_inheritance() { |
| 38 | D d; |
| 39 | |
| 40 | d.foo(); |
| 41 | d.a = 11; |
| 42 | d.b = 22; |
| 43 | d.c = 33; |
| 44 | d.d = 44; |
| 45 | } |