Richard Smith | ea698b3 | 2011-04-14 21:45:45 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2 | |
| 3 | char *const_cast_test(const char *var) |
| 4 | { |
| 5 | return const_cast<char*>(var); |
| 6 | } |
| 7 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 8 | struct A { |
| 9 | virtual ~A() {} |
| 10 | }; |
| 11 | |
| 12 | struct B : public A { |
| 13 | }; |
| 14 | |
| 15 | struct B *dynamic_cast_test(struct A *a) |
| 16 | { |
| 17 | return dynamic_cast<struct B*>(a); |
| 18 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 19 | |
| 20 | char *reinterpret_cast_test() |
| 21 | { |
| 22 | return reinterpret_cast<char*>(0xdeadbeef); |
| 23 | } |
| 24 | |
| 25 | double static_cast_test(int i) |
| 26 | { |
| 27 | return static_cast<double>(i); |
| 28 | } |
Argyrios Kyrtzidis | b348b81 | 2008-08-16 19:45:32 +0000 | [diff] [blame] | 29 | |
| 30 | char postfix_expr_test() |
| 31 | { |
| 32 | return reinterpret_cast<char*>(0xdeadbeef)[0]; |
Daniel Dunbar | d7d5f02 | 2009-03-24 02:24:46 +0000 | [diff] [blame] | 33 | } |
John McCall | 51e2a5d | 2010-04-30 03:11:01 +0000 | [diff] [blame] | 34 | |
| 35 | // This was being incorrectly tentatively parsed. |
| 36 | namespace test1 { |
Richard Smith | ea698b3 | 2011-04-14 21:45:45 +0000 | [diff] [blame] | 37 | template <class T> class A {}; // expected-note 2{{here}} |
John McCall | 51e2a5d | 2010-04-30 03:11:01 +0000 | [diff] [blame] | 38 | void foo() { A<int>(*(A<int>*)0); } |
| 39 | } |
Richard Smith | ea698b3 | 2011-04-14 21:45:45 +0000 | [diff] [blame] | 40 | |
| 41 | typedef char* c; |
| 42 | typedef A* a; |
| 43 | void test2(char x, struct B * b) { |
| 44 | (void)const_cast<::c>(&x); // expected-error{{found '<::' after a const_cast which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}} |
| 45 | (void)dynamic_cast<::a>(b); // expected-error{{found '<::' after a dynamic_cast which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}} |
| 46 | (void)reinterpret_cast<::c>(x); // expected-error{{found '<::' after a reinterpret_cast which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}} |
| 47 | (void)static_cast<::c>(&x); // expected-error{{found '<::' after a static_cast which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}} |
| 48 | |
| 49 | // Do not do digraph correction. |
| 50 | (void)static_cast<: :c>(&x); //\ |
| 51 | expected-error {{expected '<' after 'static_cast'}} \ |
| 52 | expected-error {{expected expression}}\ |
| 53 | expected-error {{expected ']'}}\ |
| 54 | expected-note {{to match this '['}} |
| 55 | (void)static_cast<: // expected-error {{expected '<' after 'static_cast'}} \ |
| 56 | expected-note {{to match this '['}} |
| 57 | :c>(&x); // expected-error {{expected expression}} \ |
| 58 | expected-error {{expected ']'}} |
| 59 | #define LC <: |
| 60 | #define C : |
| 61 | test1::A LC:B> c; // expected-error {{cannot refer to class template 'A' without a template argument list}} expected-error 2{{}} expected-note{{}} |
| 62 | (void)static_cast LC:c>(&x); // expected-error {{expected '<' after 'static_cast'}} expected-error 2{{}} expected-note{{}} |
| 63 | test1::A<:C B> d; // expected-error {{cannot refer to class template 'A' without a template argument list}} expected-error 2{{}} expected-note{{}} |
| 64 | (void)static_cast<:C c>(&x); // expected-error {{expected '<' after 'static_cast'}} expected-error 2{{}} expected-note{{}} |
| 65 | |
| 66 | #define LCC <:: |
| 67 | test1::A LCC B> e; // expected-error{{found '<::' after a template name which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}} |
| 68 | (void)static_cast LCC c>(&x); // expected-error{{found '<::' after a static_cast which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}} |
| 69 | } |
Richard Trieu | 950be71 | 2011-09-19 19:01:00 +0000 | [diff] [blame] | 70 | |
| 71 | template <class T> class D {}; |
| 72 | template <class T> void E() {}; |
| 73 | class F {}; |
| 74 | |
| 75 | void test3() { |
| 76 | ::D<::F> A1; // expected-error{{found '<::' after a template name which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}} |
| 77 | D<::F> A2; // expected-error{{found '<::' after a template name which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}} |
| 78 | ::E<::F>(); // expected-error{{found '<::' after a template name which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}} |
| 79 | E<::F>(); // expected-error{{found '<::' after a template name which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}} |
| 80 | |
| 81 | ::D< ::F> A3; |
| 82 | D< ::F> A4; |
| 83 | ::E< ::F>(); |
| 84 | E< ::F>(); |
| 85 | } |