1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++14 %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
3 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
5 char *const_cast_test(const char *var
)
7 return const_cast<char*>(var
);
17 struct B
*dynamic_cast_test(struct A
*a
)
19 return dynamic_cast<struct B
*>(a
);
22 char *reinterpret_cast_test()
24 return reinterpret_cast<char*>(0xdeadbeef);
27 double static_cast_test(int i
)
29 return static_cast<double>(i
);
32 char postfix_expr_test()
34 return reinterpret_cast<char*>(0xdeadbeef)[0];
37 // This was being incorrectly tentatively parsed.
39 template <class T
> class A
{}; // expected-note 2{{here}}
40 void foo() { A
<int>(*(A
<int>*)0); } // expected-warning {{binding dereferenced null pointer to reference has undefined behavior}}
45 void test2(char x
, struct B
* b
) {
46 (void)const_cast<::c
>(&x
);
47 #if __cplusplus <= 199711L
48 // expected-error@-2 {{found '<::' after a const_cast which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}}
51 (void)dynamic_cast<::a
>(b
);
52 #if __cplusplus <= 199711L
53 // expected-error@-2 {{found '<::' after a dynamic_cast which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}}
56 (void)reinterpret_cast<::c
>(x
);
57 #if __cplusplus <= 199711L
58 // expected-error@-2 {{found '<::' after a reinterpret_cast which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}}
61 (void)static_cast<::c
>(&x
);
62 #if __cplusplus <= 199711L
63 // expected-error@-2 {{found '<::' after a static_cast which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}}
66 // Do not do digraph correction.
67 (void)static_cast<: :c
>(&x
); //\
68 expected
-error
{{expected
'<' after
'static_cast'}} \
69 expected
-error
{{expected expression
}}\
70 expected
-error
{{expected
']'}}\
71 expected
-note
{{to match
this '['}}
72 (void)static_cast<: // expected-error {{expected '<' after 'static_cast'}} \
73 expected
-note
{{to match
this '['}}
74 :c
>(&x
); // expected-error {{expected expression}} \
75 expected
-error
{{expected
']'}}
78 test1::A LC
:B
> c
; // expected-error {{class template 'test1::A' requires template arguments}} expected-error 2{{}}
79 (void)static_cast LC
:c
>(&x
); // expected-error {{expected '<' after 'static_cast'}} expected-error 2{{}} expected-note{{}}
80 test1::A
<:C B
> d
; // expected-error {{class template 'test1::A' requires template arguments}} expected-error 2{{}}
81 (void)static_cast<:C c
>(&x
); // expected-error {{expected '<' after 'static_cast'}} expected-error 2{{}} expected-note{{}}
85 #if __cplusplus <= 199711L
86 // expected-error@-2 {{found '<::' after a template name which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}}
89 (void)static_cast LCC c
>(&x
);
90 #if __cplusplus <= 199711L
91 // expected-error@-2 {{found '<::' after a static_cast which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}}
95 // This note comes from "::D[:F> A5;"
96 template <class T
> class D
{}; // expected-note{{template is declared here}}
97 template <class T
> void E() {};
102 #if __cplusplus <= 199711L
103 // expected-error@-2 {{found '<::' after a template name which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}}
107 #if __cplusplus <= 199711L
108 // expected-error@-2 {{found '<::' after a template name which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}}
112 #if __cplusplus <= 199711L
113 // expected-error@-2 {{found '<::' after a template name which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}}
117 #if __cplusplus <= 199711L
118 // expected-error@-2 {{found '<::' after a template name which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}}
126 // Make sure that parser doesn't expand '[:' to '< ::'
127 ::D
[:F
> A5
; // expected-error {{class template '::D' requires template arguments}} \
128 // expected-error {{expected expression}} \
129 // expected-error {{expected unqualified-id}}
132 // Ensure that a C-style cast doesn't turn off colon protection.
136 int test1
= true ? (int)A
: b
;
139 extern B
f(), (*p
)();
140 (true ? (B(*)())f
: p
)();
143 void PR19751(int n
) {
144 struct T
{ void operator++(int); };
145 (T())++; // ok, not an ill-formed cast to function type
146 (T())++n
; // expected-error {{C-style cast from 'int' to 'T ()' is not allowed}}
149 // PR13619. Must be at end of file.
150 int n
= reinterpret_cast // expected-error {{expected '<'}} expected-error {{expected ';'}}