Douglas Gregor | 555f57e | 2011-06-25 00:56:27 +0000 | [diff] [blame^] | 1 | // RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -verify %s |
Sebastian Redl | 9ba73ad | 2009-01-09 19:57:06 +0000 | [diff] [blame] | 2 | |
| 3 | class A { |
| 4 | virtual void f(); |
Douglas Gregor | 555f57e | 2011-06-25 00:56:27 +0000 | [diff] [blame^] | 5 | virtual void g() = 0; // expected-note{{unimplemented pure virtual method 'g' in 'A'}} |
Sebastian Redl | 9ba73ad | 2009-01-09 19:57:06 +0000 | [diff] [blame] | 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 | |
Douglas Gregor | 021c3b3 | 2009-03-11 23:00:04 +0000 | [diff] [blame] | 11 | |
| 12 | void k(); |
| 13 | |
Sebastian Redl | 9ba73ad | 2009-01-09 19:57:06 +0000 | [diff] [blame] | 14 | public: |
| 15 | A(int); |
| 16 | }; |
| 17 | |
Douglas Gregor | 021c3b3 | 2009-03-11 23:00:04 +0000 | [diff] [blame] | 18 | virtual void A::k() { } // expected-error{{'virtual' can only be specified inside the class definition}} |
| 19 | |
Sebastian Redl | 9ba73ad | 2009-01-09 19:57:06 +0000 | [diff] [blame] | 20 | class B : public A { |
| 21 | // Needs to recognize that overridden function is virtual. |
Douglas Gregor | 555f57e | 2011-06-25 00:56:27 +0000 | [diff] [blame^] | 22 | void g() = 0; |
Sebastian Redl | 9ba73ad | 2009-01-09 19:57:06 +0000 | [diff] [blame] | 23 | |
| 24 | // Needs to recognize that function does not override. |
Douglas Gregor | 555f57e | 2011-06-25 00:56:27 +0000 | [diff] [blame^] | 25 | void g(int) = 0; // expected-error{{'g' is not virtual and cannot be declared pure}} |
Sebastian Redl | 9ba73ad | 2009-01-09 19:57:06 +0000 | [diff] [blame] | 26 | }; |
| 27 | |
| 28 | // Needs to recognize invalid uses of abstract classes. |
Douglas Gregor | 555f57e | 2011-06-25 00:56:27 +0000 | [diff] [blame^] | 29 | A fn(A) // expected-error{{parameter type 'A' is an abstract class}} \ |
| 30 | // expected-error{{return type 'A' is an abstract class}} |
Sebastian Redl | 9ba73ad | 2009-01-09 19:57:06 +0000 | [diff] [blame] | 31 | { |
Douglas Gregor | 555f57e | 2011-06-25 00:56:27 +0000 | [diff] [blame^] | 32 | A a; // expected-error{{variable type 'A' is an abstract class}} |
| 33 | (void)static_cast<A>(0); |
Sebastian Redl | 9ba73ad | 2009-01-09 19:57:06 +0000 | [diff] [blame] | 34 | try { |
Douglas Gregor | 555f57e | 2011-06-25 00:56:27 +0000 | [diff] [blame^] | 35 | } catch(A) { // expected-error{{variable type 'A' is an abstract class}} |
Sebastian Redl | 9ba73ad | 2009-01-09 19:57:06 +0000 | [diff] [blame] | 36 | } |
| 37 | } |
Douglas Gregor | 555f57e | 2011-06-25 00:56:27 +0000 | [diff] [blame^] | 38 | |
| 39 | namespace rdar9670557 { |
| 40 | typedef int func(int); |
| 41 | struct X { |
| 42 | virtual func f = 0; |
| 43 | }; |
| 44 | } |