Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Cedric Venet | 3d65864 | 2009-02-14 20:20:19 +0000 | [diff] [blame] | 2 | |
Richard Smith | d37b360 | 2012-02-10 11:05:11 +0000 | [diff] [blame] | 3 | void f() const; // expected-error {{non-member function cannot have 'const' qualifier}} |
| 4 | void (*pf)() const; // expected-error {{pointer to function type cannot have 'const' qualifier}} |
| 5 | extern void (&rf)() const; // expected-error {{reference to function type cannot have 'const' qualifier}} |
Cedric Venet | 3d65864 | 2009-02-14 20:20:19 +0000 | [diff] [blame] | 6 | |
Richard Smith | d37b360 | 2012-02-10 11:05:11 +0000 | [diff] [blame] | 7 | typedef void cfn() const; |
| 8 | cfn f2; // expected-error {{non-member function of type 'cfn' (aka 'void () const') cannot have 'const' qualifier}} |
Cedric Venet | 3d65864 | 2009-02-14 20:20:19 +0000 | [diff] [blame] | 9 | |
| 10 | class C { |
| 11 | void f() const; |
| 12 | cfn f2; |
Richard Smith | d37b360 | 2012-02-10 11:05:11 +0000 | [diff] [blame] | 13 | static void f3() const; // expected-error {{static member function cannot have 'const' qualifier}} |
| 14 | static cfn f4; // expected-error {{static member function of type 'cfn' (aka 'void () const') cannot have 'const' qualifier}} |
Cedric Venet | 3d65864 | 2009-02-14 20:20:19 +0000 | [diff] [blame] | 15 | |
| 16 | void m1() { |
| 17 | x = 0; |
| 18 | } |
| 19 | |
| 20 | void m2() const { |
| 21 | x = 0; // expected-error {{read-only variable is not assignable}} |
| 22 | } |
| 23 | |
| 24 | int x; |
| 25 | }; |
Sebastian Redl | f9ea1f3 | 2010-07-12 23:11:43 +0000 | [diff] [blame] | 26 | |
| 27 | void (C::*mpf)() const; |
| 28 | cfn C::*mpg; |
Richard Smith | e925322 | 2012-10-24 23:51:56 +0000 | [diff] [blame] | 29 | |
| 30 | // Don't crash! |
| 31 | void (PR14171)() const; // expected-error {{non-member function cannot have 'const' qualifier}} |
Reid Kleckner | 12df246 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 32 | |
| 33 | // Test template instantiation of decayed array types. Not really related to |
| 34 | // type quals. |
| 35 | template <typename T> void arrayDecay(const T a[]) { } |
| 36 | void instantiateArrayDecay() { |
| 37 | int a[1]; |
| 38 | arrayDecay(a); |
| 39 | } |