blob: 69680e421b0da2dff128678e4dac1539cb4e4826 [file] [log] [blame]
Richard Smithea698b32011-04-14 21:45:45 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Reid Spencer5f016e22007-07-11 17:01:13 +00002
3char *const_cast_test(const char *var)
4{
5 return const_cast<char*>(var);
6}
7
Reid Spencer5f016e22007-07-11 17:01:13 +00008struct A {
9 virtual ~A() {}
10};
11
12struct B : public A {
13};
14
15struct B *dynamic_cast_test(struct A *a)
16{
17 return dynamic_cast<struct B*>(a);
18}
Reid Spencer5f016e22007-07-11 17:01:13 +000019
20char *reinterpret_cast_test()
21{
22 return reinterpret_cast<char*>(0xdeadbeef);
23}
24
25double static_cast_test(int i)
26{
27 return static_cast<double>(i);
28}
Argyrios Kyrtzidisb348b812008-08-16 19:45:32 +000029
30char postfix_expr_test()
31{
32 return reinterpret_cast<char*>(0xdeadbeef)[0];
Daniel Dunbard7d5f022009-03-24 02:24:46 +000033}
John McCall51e2a5d2010-04-30 03:11:01 +000034
35// This was being incorrectly tentatively parsed.
36namespace test1 {
Richard Smithea698b32011-04-14 21:45:45 +000037 template <class T> class A {}; // expected-note 2{{here}}
John McCall51e2a5d2010-04-30 03:11:01 +000038 void foo() { A<int>(*(A<int>*)0); }
39}
Richard Smithea698b32011-04-14 21:45:45 +000040
41typedef char* c;
42typedef A* a;
43void 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 :
David Blaikie4b02dff2013-03-05 06:21:38 +000061 test1::A LC:B> c; // expected-error {{class template 'test1::A' requires template arguments}} expected-error 2{{}}
Richard Smithea698b32011-04-14 21:45:45 +000062 (void)static_cast LC:c>(&x); // expected-error {{expected '<' after 'static_cast'}} expected-error 2{{}} expected-note{{}}
David Blaikie4b02dff2013-03-05 06:21:38 +000063 test1::A<:C B> d; // expected-error {{class template 'test1::A' requires template arguments}} expected-error 2{{}}
Richard Smithea698b32011-04-14 21:45:45 +000064 (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 Trieu950be712011-09-19 19:01:00 +000070
Richard Trieuc11030e2011-09-20 20:03:50 +000071 // This note comes from "::D[:F> A5;"
72template <class T> class D {}; // expected-note{{template is declared here}}
Richard Trieu950be712011-09-19 19:01:00 +000073template <class T> void E() {};
74class F {};
75
76void test3() {
77 ::D<::F> A1; // expected-error{{found '<::' after a template name which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}}
78 D<::F> A2; // 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 E<::F>(); // expected-error{{found '<::' after a template name which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}}
81
82 ::D< ::F> A3;
83 D< ::F> A4;
84 ::E< ::F>();
85 E< ::F>();
Richard Trieuc11030e2011-09-20 20:03:50 +000086
87 // Make sure that parser doesn't expand '[:' to '< ::'
David Blaikie4b02dff2013-03-05 06:21:38 +000088 ::D[:F> A5; // expected-error {{class template '::D' requires template arguments}} \
Richard Trieuc11030e2011-09-20 20:03:50 +000089 // expected-error {{expected expression}} \
Richard Smith05766812012-08-18 00:55:03 +000090 // expected-error {{expected unqualified-id}}
Richard Trieu950be712011-09-19 19:01:00 +000091}
Richard Smith78fe3e02012-08-20 17:37:52 +000092
93// PR13619. Must be at end of file.
94int n = reinterpret_cast // expected-error {{expected '<'}} expected-error {{expected ';'}}