2011-04-15 05:45:45 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
|
2015-12-10 09:07:17 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
|
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
|
2007-01-23 14:12:15 +08:00
|
|
|
|
|
|
|
char *const_cast_test(const char *var)
|
|
|
|
{
|
|
|
|
return const_cast<char*>(var);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct A {
|
|
|
|
virtual ~A() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct B : public A {
|
|
|
|
};
|
|
|
|
|
|
|
|
struct B *dynamic_cast_test(struct A *a)
|
|
|
|
{
|
|
|
|
return dynamic_cast<struct B*>(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *reinterpret_cast_test()
|
|
|
|
{
|
|
|
|
return reinterpret_cast<char*>(0xdeadbeef);
|
|
|
|
}
|
|
|
|
|
|
|
|
double static_cast_test(int i)
|
|
|
|
{
|
|
|
|
return static_cast<double>(i);
|
|
|
|
}
|
2008-08-17 03:45:32 +08:00
|
|
|
|
|
|
|
char postfix_expr_test()
|
|
|
|
{
|
|
|
|
return reinterpret_cast<char*>(0xdeadbeef)[0];
|
2009-03-24 10:24:46 +08:00
|
|
|
}
|
2010-04-30 11:11:01 +08:00
|
|
|
|
|
|
|
// This was being incorrectly tentatively parsed.
|
|
|
|
namespace test1 {
|
2011-04-15 05:45:45 +08:00
|
|
|
template <class T> class A {}; // expected-note 2{{here}}
|
2010-04-30 11:11:01 +08:00
|
|
|
void foo() { A<int>(*(A<int>*)0); }
|
|
|
|
}
|
2011-04-15 05:45:45 +08:00
|
|
|
|
|
|
|
typedef char* c;
|
|
|
|
typedef A* a;
|
|
|
|
void test2(char x, struct B * b) {
|
2015-12-10 09:07:17 +08:00
|
|
|
(void)const_cast<::c>(&x);
|
|
|
|
#if __cplusplus <= 199711L
|
|
|
|
// expected-error@-2 {{found '<::' after a const_cast which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
(void)dynamic_cast<::a>(b);
|
|
|
|
#if __cplusplus <= 199711L
|
|
|
|
// expected-error@-2 {{found '<::' after a dynamic_cast which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
(void)reinterpret_cast<::c>(x);
|
|
|
|
#if __cplusplus <= 199711L
|
|
|
|
// expected-error@-2 {{found '<::' after a reinterpret_cast which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
(void)static_cast<::c>(&x);
|
|
|
|
#if __cplusplus <= 199711L
|
|
|
|
// expected-error@-2 {{found '<::' after a static_cast which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}}
|
|
|
|
#endif
|
2011-04-15 05:45:45 +08:00
|
|
|
|
|
|
|
// Do not do digraph correction.
|
|
|
|
(void)static_cast<: :c>(&x); //\
|
|
|
|
expected-error {{expected '<' after 'static_cast'}} \
|
|
|
|
expected-error {{expected expression}}\
|
|
|
|
expected-error {{expected ']'}}\
|
|
|
|
expected-note {{to match this '['}}
|
|
|
|
(void)static_cast<: // expected-error {{expected '<' after 'static_cast'}} \
|
|
|
|
expected-note {{to match this '['}}
|
|
|
|
:c>(&x); // expected-error {{expected expression}} \
|
|
|
|
expected-error {{expected ']'}}
|
|
|
|
#define LC <:
|
|
|
|
#define C :
|
2013-03-05 14:21:38 +08:00
|
|
|
test1::A LC:B> c; // expected-error {{class template 'test1::A' requires template arguments}} expected-error 2{{}}
|
2011-04-15 05:45:45 +08:00
|
|
|
(void)static_cast LC:c>(&x); // expected-error {{expected '<' after 'static_cast'}} expected-error 2{{}} expected-note{{}}
|
2013-03-05 14:21:38 +08:00
|
|
|
test1::A<:C B> d; // expected-error {{class template 'test1::A' requires template arguments}} expected-error 2{{}}
|
2011-04-15 05:45:45 +08:00
|
|
|
(void)static_cast<:C c>(&x); // expected-error {{expected '<' after 'static_cast'}} expected-error 2{{}} expected-note{{}}
|
|
|
|
|
|
|
|
#define LCC <::
|
2015-12-10 09:07:17 +08:00
|
|
|
test1::A LCC B> e;
|
|
|
|
#if __cplusplus <= 199711L
|
|
|
|
// expected-error@-2 {{found '<::' after a template name which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
(void)static_cast LCC c>(&x);
|
|
|
|
#if __cplusplus <= 199711L
|
|
|
|
// expected-error@-2 {{found '<::' after a static_cast which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}}
|
|
|
|
#endif
|
2011-04-15 05:45:45 +08:00
|
|
|
}
|
2011-09-20 03:01:00 +08:00
|
|
|
|
2011-09-21 04:03:50 +08:00
|
|
|
// This note comes from "::D[:F> A5;"
|
|
|
|
template <class T> class D {}; // expected-note{{template is declared here}}
|
2011-09-20 03:01:00 +08:00
|
|
|
template <class T> void E() {};
|
|
|
|
class F {};
|
|
|
|
|
|
|
|
void test3() {
|
2015-12-10 09:07:17 +08:00
|
|
|
::D<::F> A1;
|
|
|
|
#if __cplusplus <= 199711L
|
|
|
|
// expected-error@-2 {{found '<::' after a template name which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
D<::F> A2;
|
|
|
|
#if __cplusplus <= 199711L
|
|
|
|
// expected-error@-2 {{found '<::' after a template name which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
::E<::F>();
|
|
|
|
#if __cplusplus <= 199711L
|
|
|
|
// expected-error@-2 {{found '<::' after a template name which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
E<::F>();
|
|
|
|
#if __cplusplus <= 199711L
|
|
|
|
// expected-error@-2 {{found '<::' after a template name which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}}
|
|
|
|
#endif
|
2011-09-20 03:01:00 +08:00
|
|
|
|
|
|
|
::D< ::F> A3;
|
|
|
|
D< ::F> A4;
|
|
|
|
::E< ::F>();
|
|
|
|
E< ::F>();
|
2011-09-21 04:03:50 +08:00
|
|
|
|
|
|
|
// Make sure that parser doesn't expand '[:' to '< ::'
|
2013-03-05 14:21:38 +08:00
|
|
|
::D[:F> A5; // expected-error {{class template '::D' requires template arguments}} \
|
2011-09-21 04:03:50 +08:00
|
|
|
// expected-error {{expected expression}} \
|
2012-08-18 08:55:03 +08:00
|
|
|
// expected-error {{expected unqualified-id}}
|
2011-09-20 03:01:00 +08:00
|
|
|
}
|
2012-08-21 01:37:52 +08:00
|
|
|
|
2014-05-15 10:43:47 +08:00
|
|
|
// Ensure that a C-style cast doesn't turn off colon protection.
|
|
|
|
void PR19748() {
|
|
|
|
struct A {};
|
|
|
|
int A = 0, b;
|
|
|
|
int test1 = true ? (int)A : b;
|
|
|
|
|
|
|
|
struct f {};
|
|
|
|
extern B f(), (*p)();
|
|
|
|
(true ? (B(*)())f : p)();
|
|
|
|
}
|
|
|
|
|
2014-07-15 08:11:48 +08:00
|
|
|
void PR19751(int n) {
|
|
|
|
struct T { void operator++(int); };
|
|
|
|
(T())++; // ok, not an ill-formed cast to function type
|
|
|
|
(T())++n; // expected-error {{C-style cast from 'int' to 'T ()' is not allowed}}
|
|
|
|
}
|
|
|
|
|
2012-08-21 01:37:52 +08:00
|
|
|
// PR13619. Must be at end of file.
|
|
|
|
int n = reinterpret_cast // expected-error {{expected '<'}} expected-error {{expected ';'}}
|