llvm-project/clang/test/Parser/opencl-cxx-virtual.cl
Anastasia Stulova 4fde2b6a0c [OpenCL] Add clang extension for function pointers.
The new clang internal extension '__cl_clang_function_pointers'
allows use of function pointers and other features that have
the same functionality:
- Use of member function pointers;
- Unrestricted use of references to functions;
- Virtual member functions.

This not a vendor extension and therefore it doesn't require any
special target support. Exposing this functionality fully
will require vendor or Khronos extension.

Tags: #clang

Differential Revision: https://reviews.llvm.org/D94021
2021-01-06 20:39:57 +00:00

59 lines
1.2 KiB
Common Lisp

// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=clc++ -fsyntax-only -verify
// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=clc++ -fsyntax-only -verify -DFUNCPTREXT
#ifdef FUNCPTREXT
#pragma OPENCL EXTENSION __cl_clang_function_pointers : enable
//expected-no-diagnostics
#endif
// Test that virtual functions and abstract classes are rejected
// unless specific clang extension is used.
class virtual_functions {
virtual void bad1() {}
#ifndef FUNCPTREXT
//expected-error@-2 {{virtual functions are not supported in C++ for OpenCL}}
#endif
virtual void bad2() = 0;
#ifndef FUNCPTREXT
//expected-error@-2 {{virtual functions are not supported in C++ for OpenCL}}
//expected-error@-3 {{'bad2' is not virtual and cannot be declared pure}}
#endif
};
template <typename T>
class X {
virtual T f();
#ifndef FUNCPTREXT
//expected-error@-2 {{virtual functions are not supported in C++ for OpenCL}}
#endif
};
// Test that virtual base classes are allowed.
struct A {
int a;
void foo();
};
struct B : virtual A {
int b;
};
struct C : public virtual A {
int c;
};
struct D : B, C {
int d;
};
kernel void virtual_inheritance() {
D d;
d.foo();
d.a = 11;
d.b = 22;
d.c = 33;
d.d = 44;
}