diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2011-04-14 21:45:45 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2011-04-14 21:45:45 +0000 |
commit | ea698b3f6cad84f7f583282dce3e03e24fe80e98 (patch) | |
tree | 851f460d8d231911fafd2df0fac4422a57fcc22d /test/Parser/cxx-casting.cpp | |
parent | 06d9b1ad0bca7230cbae57e3e3207dda77a9eac0 (diff) |
Detect when the string "<::" is found in code after a cast or template name and is interpreted as "[:" because of the digraph "<:". When found, give an error with a fix-it to add whitespace between the "<" and "::".
Patch by Richard Trieu! Plus a small tweak from me to deal with one of the tokens coming from a macro.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@129540 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Parser/cxx-casting.cpp')
-rw-r--r-- | test/Parser/cxx-casting.cpp | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/test/Parser/cxx-casting.cpp b/test/Parser/cxx-casting.cpp index 98d962ad09..4a0bb4d1e4 100644 --- a/test/Parser/cxx-casting.cpp +++ b/test/Parser/cxx-casting.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only %s +// RUN: %clang_cc1 -fsyntax-only -verify %s char *const_cast_test(const char *var) { @@ -34,6 +34,36 @@ char postfix_expr_test() // This was being incorrectly tentatively parsed. namespace test1 { - template <class T> class A {}; + template <class T> class A {}; // expected-note 2{{here}} void foo() { A<int>(*(A<int>*)0); } } + +typedef char* c; +typedef A* a; +void test2(char x, struct B * b) { + (void)const_cast<::c>(&x); // expected-error{{found '<::' after a const_cast which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}} + (void)dynamic_cast<::a>(b); // expected-error{{found '<::' after a dynamic_cast which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}} + (void)reinterpret_cast<::c>(x); // expected-error{{found '<::' after a reinterpret_cast which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}} + (void)static_cast<::c>(&x); // expected-error{{found '<::' after a static_cast which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}} + + // 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 : + test1::A LC:B> c; // expected-error {{cannot refer to class template 'A' without a template argument list}} expected-error 2{{}} expected-note{{}} + (void)static_cast LC:c>(&x); // expected-error {{expected '<' after 'static_cast'}} expected-error 2{{}} expected-note{{}} + test1::A<:C B> d; // expected-error {{cannot refer to class template 'A' without a template argument list}} expected-error 2{{}} expected-note{{}} + (void)static_cast<:C c>(&x); // expected-error {{expected '<' after 'static_cast'}} expected-error 2{{}} expected-note{{}} + +#define LCC <:: + test1::A LCC B> e; // expected-error{{found '<::' after a template name which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}} + (void)static_cast LCC c>(&x); // expected-error{{found '<::' after a static_cast which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}} +} |