xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/virtuals.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1 // RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -verify -std=c++11 %s
2 
3 class A {
4   virtual void f();
5   virtual void g() = 0; // expected-note{{unimplemented pure virtual method 'g' in 'A'}}
6 
7   void h() = 0; // expected-error {{'h' is not virtual and cannot be declared pure}}
8   void i() = 1; // expected-error {{initializer on function does not look like a pure-specifier}}
9   void j() = 0u; // expected-error {{initializer on function does not look like a pure-specifier}}
10 
11 
12   void k();
13 
14 public:
15   A(int);
16 };
17 
k()18 virtual void A::k() { } // expected-error{{'virtual' can only be specified inside the class definition}}
19 
20 class B : public A {
21   // Needs to recognize that overridden function is virtual.
22   void g() = 0;
23 
24   // Needs to recognize that function does not override.
25   void g(int) = 0; // expected-error{{'g' is not virtual and cannot be declared pure}}
26 };
27 
28 // Needs to recognize invalid uses of abstract classes.
fn(A)29 A fn(A) // expected-error{{parameter type 'A' is an abstract class}} \
30         // expected-error{{return type 'A' is an abstract class}}
31 {
32   A a; // expected-error{{variable type 'A' is an abstract class}}
33   (void)static_cast<A>(0); // expected-error{{allocating an object of abstract class type 'A'}}
34   try {
35   } catch(A) { // expected-error{{variable type 'A' is an abstract class}}
36   }
37 }
38 
39 namespace rdar9670557 {
40   typedef int func(int);
41   func *a();
42   struct X {
43     virtual func f = 0;
44     virtual func (g) = 0;
45     func *h = 0;
46   };
47 }
48 
49 namespace pr8264 {
50   struct Test {
51     virtual virtual void func();  // expected-warning {{duplicate 'virtual' declaration specifier}}
52   };
53 }
54