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