[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Parser / opencl-cxx-virtual.cl
blob72d463d9c62fc34cdd5a9521b3896f28772ec109
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
4 #ifdef FUNCPTREXT
5 #pragma OPENCL EXTENSION __cl_clang_function_pointers : enable
6 //expected-no-diagnostics
7 #endif
9 // Test that virtual functions and abstract classes are rejected
10 // unless specific clang extension is used.
11 class virtual_functions {
12 virtual void bad1() {}
13 #ifndef FUNCPTREXT
14 //expected-error@-2 {{virtual functions are not supported in C++ for OpenCL}}
15 #endif
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
24 template <typename T>
25 class X {
26 virtual T f();
27 #ifndef FUNCPTREXT
28 //expected-error@-2 {{virtual functions are not supported in C++ for OpenCL}}
29 #endif
32 // Test that virtual base classes are allowed.
33 struct A {
34 int a;
35 void foo();
38 struct B : virtual A {
39 int b;
42 struct C : public virtual A {
43 int c;
46 struct D : B, C {
47 int d;
50 kernel void virtual_inheritance() {
51 D d;
53 d.foo();
54 d.a = 11;
55 d.b = 22;
56 d.c = 33;
57 d.d = 44;