Home | History | Annotate | Download | only in SemaCXX
      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 
     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.
     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 
     55 namespace VirtualFriend {
     56   // DR (filed but no number yet): reject meaningless pure-specifier on a friend declaration.
     57   struct A { virtual int f(); };
     58   struct B { friend int A::f() = 0; }; // expected-error {{friend declaration cannot have a pure-specifier}}
     59   struct C {
     60     virtual int f();
     61     friend int C::f() = 0; // expected-error {{friend declaration cannot have a pure-specifier}}
     62   };
     63 }
     64