blob: a340e9d86b65ad5b95328f09a8fbf87b02eeb09a [file] [log] [blame]
Richard Smith762bb9d2011-10-13 22:29:44 +00001// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -verify -std=c++11 %s
Sebastian Redl9ba73ad2009-01-09 19:57:06 +00002
3class A {
4 virtual void f();
Douglas Gregor555f57e2011-06-25 00:56:27 +00005 virtual void g() = 0; // expected-note{{unimplemented pure virtual method 'g' in 'A'}}
Sebastian Redl9ba73ad2009-01-09 19:57:06 +00006
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 Gregor021c3b32009-03-11 23:00:04 +000011
12 void k();
13
Sebastian Redl9ba73ad2009-01-09 19:57:06 +000014public:
15 A(int);
16};
17
Douglas Gregor021c3b32009-03-11 23:00:04 +000018virtual void A::k() { } // expected-error{{'virtual' can only be specified inside the class definition}}
19
Sebastian Redl9ba73ad2009-01-09 19:57:06 +000020class B : public A {
21 // Needs to recognize that overridden function is virtual.
Douglas Gregor555f57e2011-06-25 00:56:27 +000022 void g() = 0;
Sebastian Redl9ba73ad2009-01-09 19:57:06 +000023
24 // Needs to recognize that function does not override.
Douglas Gregor555f57e2011-06-25 00:56:27 +000025 void g(int) = 0; // expected-error{{'g' is not virtual and cannot be declared pure}}
Sebastian Redl9ba73ad2009-01-09 19:57:06 +000026};
27
28// Needs to recognize invalid uses of abstract classes.
Douglas Gregor555f57e2011-06-25 00:56:27 +000029A fn(A) // expected-error{{parameter type 'A' is an abstract class}} \
30 // expected-error{{return type 'A' is an abstract class}}
Sebastian Redl9ba73ad2009-01-09 19:57:06 +000031{
Douglas Gregor555f57e2011-06-25 00:56:27 +000032 A a; // expected-error{{variable type 'A' is an abstract class}}
Aaron Ballman0a84e7a2012-05-07 01:10:33 +000033 (void)static_cast<A>(0); // expected-error{{allocating an object of abstract class type 'A'}}
Sebastian Redl9ba73ad2009-01-09 19:57:06 +000034 try {
Douglas Gregor555f57e2011-06-25 00:56:27 +000035 } catch(A) { // expected-error{{variable type 'A' is an abstract class}}
Sebastian Redl9ba73ad2009-01-09 19:57:06 +000036 }
37}
Douglas Gregor555f57e2011-06-25 00:56:27 +000038
39namespace rdar9670557 {
40 typedef int func(int);
Richard Smith1ab0d902011-06-25 02:28:38 +000041 func *a();
Douglas Gregor555f57e2011-06-25 00:56:27 +000042 struct X {
43 virtual func f = 0;
Richard Smith1ab0d902011-06-25 02:28:38 +000044 virtual func (g) = 0;
45 func *h = 0;
Douglas Gregor555f57e2011-06-25 00:56:27 +000046 };
47}