diff options
Diffstat (limited to 'test/Parser')
33 files changed, 578 insertions, 71 deletions
diff --git a/test/Parser/DelayedTemplateParsing.cpp b/test/Parser/DelayedTemplateParsing.cpp index 9737c731bd17..77b47239f4c8 100644 --- a/test/Parser/DelayedTemplateParsing.cpp +++ b/test/Parser/DelayedTemplateParsing.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fms-extensions -fdelayed-template-parsing -fsyntax-only -verify %s +// RUN: %clang_cc1 -fms-extensions -fdelayed-template-parsing -fsyntax-only -verify -std=c++11 %s template <class T> class A { @@ -90,3 +90,14 @@ Callback Bind() { } } + +namespace rdar11700604 { + template<typename T> void foo() = delete; + + struct X { + X() = default; + + template<typename T> void foo() = delete; + }; +} + diff --git a/test/Parser/MicrosoftExtensions.c b/test/Parser/MicrosoftExtensions.c index 1ef326aaf5d3..7703999d67ce 100644 --- a/test/Parser/MicrosoftExtensions.c +++ b/test/Parser/MicrosoftExtensions.c @@ -3,24 +3,24 @@ __stdcall int func0(); int __stdcall func(); typedef int (__cdecl *tptr)(); void (*__fastcall fastpfunc)(); -struct __declspec(uuid("00000000-0000-0000-C000-000000000046")) __declspec(novtable) IUnknown {}; +struct __declspec(uuid("00000000-0000-0000-C000-000000000046")) __declspec(novtable) IUnknown {}; /* expected-warning{{__declspec attribute 'novtable' is not supported}} */ extern __declspec(dllimport) void __stdcall VarR4FromDec(); __declspec(deprecated) __declspec(deprecated) char * __cdecl ltoa( long _Val, char * _DstBuf, int _Radix); -__declspec(noalias) __declspec(restrict) void * __cdecl xxx( void * _Memory ); +__declspec(noalias) __declspec(restrict) void * __cdecl xxx( void * _Memory ); /* expected-warning{{__declspec attribute 'noalias' is not supported}} expected-warning{{__declspec attribute 'restrict' is not supported}} */ typedef __w64 unsigned long ULONG_PTR, *PULONG_PTR; void * __ptr64 PtrToPtr64(const void *p) { - return((void * __ptr64) (unsigned __int64) (ULONG_PTR)p ); // expected-warning {{unknown attribute '__ptr64' ignored}} + return((void * __ptr64) (unsigned __int64) (ULONG_PTR)p ); } void * __ptr32 PtrToPtr32(const void *p) { - return((void * __ptr32) (unsigned __int32) (ULONG_PTR)p ); // expected-warning {{unknown attribute '__ptr32' ignored}} + return((void * __ptr32) (unsigned __int32) (ULONG_PTR)p ); } void __forceinline InterlockedBitTestAndSet (long *Base, long Bit) { - __asm { + __asm { // expected-warning {{MS-style inline assembly is not supported}} mov eax, Bit mov ecx, Base lock bts [ecx], eax @@ -29,6 +29,11 @@ void __forceinline InterlockedBitTestAndSet (long *Base, long Bit) } _inline int foo99() { return 99; } +void test_ms_alignof_alias() { + unsigned int s = _alignof(int); + s = __builtin_alignof(int); +} + void *_alloca(int); void foo() { @@ -49,8 +54,8 @@ char x = FOO(a); typedef enum E { e1 }; -enum __declspec(deprecated) E2 { i, j, k }; -__declspec(deprecated) enum E3 { a, b, c } e; +enum __declspec(deprecated) E2 { i, j, k }; // expected-note {{declared here}} +__declspec(deprecated) enum E3 { a, b, c } e; // expected-note {{declared here}} void deprecated_enum_test(void) { @@ -64,7 +69,7 @@ void deprecated_enum_test(void) [repeatable][source_annotation_attribute( Parameter|ReturnValue )] struct SA_Post{ SA_Post(); int attr; }; -[returnvalue:SA_Post( attr=1)] +[returnvalue:SA_Post( attr=1)] int foo1([SA_Post(attr=1)] void *param); @@ -75,3 +80,25 @@ void ms_intrinsics(int a) __assume(a); __debugbreak(); } + +struct __declspec(frobble) S1 {}; /* expected-warning {{unknown __declspec attribute 'frobble' ignored}} */ +struct __declspec(12) S2 {}; /* expected-error {{__declspec attributes must be an identifier or string literal}} */ +struct __declspec("testing") S3 {}; /* expected-warning {{__declspec attribute '"testing"' is not supported}} */ + +/* Ensure multiple declspec attributes are supported */ +struct __declspec(align(8) deprecated) S4 {}; + +/* But multiple declspecs must still be legal */ +struct __declspec(deprecated frobble "testing") S5 {}; /* expected-warning {{unknown __declspec attribute 'frobble' ignored}} expected-warning {{__declspec attribute '"testing"' is not supported}} */ +struct __declspec(unknown(12) deprecated) S6 {}; /* expected-warning {{unknown __declspec attribute 'unknown' ignored}}*/ + +struct S7 { + int foo() { return 12; } + __declspec(property(get=foo) deprecated) int t; // expected-note {{declared here}} +}; + +/* Technically, this is legal (though it does nothing) */ +__declspec() void quux( void ) { + struct S7 s; + int i = s.t; /* expected-warning {{'t' is deprecated}} */ +} diff --git a/test/Parser/MicrosoftExtensions.cpp b/test/Parser/MicrosoftExtensions.cpp index 3a1ffea453ca..6219e29f597a 100644 --- a/test/Parser/MicrosoftExtensions.cpp +++ b/test/Parser/MicrosoftExtensions.cpp @@ -151,11 +151,24 @@ void missing_template_keyword(){ class AAAA { }; +template <typename T> +class SimpleTemplate {}; + template <class T> void redundant_typename() { typename T t;// expected-warning {{expected a qualified name after 'typename'}} typename AAAA a;// expected-warning {{expected a qualified name after 'typename'}} + t = 3; + + typedef typename T* pointerT;// expected-warning {{expected a qualified name after 'typename'}} + typedef typename SimpleTemplate<int> templateT;// expected-warning {{expected a qualified name after 'typename'}} + + pointerT pT = &t; + *pT = 4; + + int var; + int k = typename var;// expected-error {{expected a qualified name after 'typename'}} } @@ -284,28 +297,29 @@ int main () { missing_template_keyword<int>(); } +namespace access_protected_PTM { + class A { + protected: + void f(); // expected-note {{must name member using the type of the current context 'access_protected_PTM::B'}} + }; + class B : public A{ + public: + void test_access(); + static void test_access_static(); + }; -
-namespace access_protected_PTM {
-
-class A {
-protected:
- void f(); // expected-note {{must name member using the type of the current context 'access_protected_PTM::B'}}
-};
-
-class B : public A{
-public:
- void test_access();
- static void test_access_static();
-};
-
-void B::test_access() {
- &A::f; // expected-error {{'f' is a protected member of 'access_protected_PTM::A'}}
-}
-
-void B::test_access_static() {
- &A::f;
-}
-
-}
\ No newline at end of file + void B::test_access() { + &A::f; // expected-error {{'f' is a protected member of 'access_protected_PTM::A'}} + } + + void B::test_access_static() { + &A::f; + } +} + +namespace Inheritance { + class __single_inheritance A; + class __multiple_inheritance B; + class __virtual_inheritance C; +} diff --git a/test/Parser/altivec.c b/test/Parser/altivec.c index d1e655213761..0bdc3dcffe2a 100644 --- a/test/Parser/altivec.c +++ b/test/Parser/altivec.c @@ -76,6 +76,16 @@ vector bool unsigned int v_bsc2; // expected-error {{cannot use 'unsigned' w vector bool long v_bl; // expected-error {{cannot use 'long' with '__vector bool'}} vector bool long long v_bll; // expected-error {{cannot use 'long long' with '__vector bool'}} +typedef char i8; +typedef short i16; +typedef int i32; +struct S { + // i8, i16, i32 here are field names, not type names. + vector bool i8; // expected-error {{requires a specifier or qualifier}} + vector pixel i16; + vector long i32; // expected-warning {{deprecated}} +}; + void f() { __vector unsigned int v = {0,0,0,0}; __vector int v__cast = (__vector int)v; diff --git a/test/Parser/c1x-alignas.c b/test/Parser/c1x-alignas.c index 5dccc99035ad..81cd6816307f 100644 --- a/test/Parser/c1x-alignas.c +++ b/test/Parser/c1x-alignas.c @@ -1,7 +1,13 @@ -// RUN: %clang_cc1 -std=c1x -fsyntax-only -verify %s +// RUN: %clang_cc1 -std=c11 -fsyntax-only -verify %s +// RUN: not %clang_cc1 -pedantic -fsyntax-only %s 2>&1 | FileCheck -check-prefix=CHECK-EXT %s _Alignas(4) char c1; unsigned _Alignas(long) char c2; char _Alignas(16) c3; char c4 _Alignas(32); // expected-error {{expected ';' after top level declarator}} + +char _Alignas(_Alignof(int)) c5; + +// CHECK-EXT: _Alignas is a C11-specific feature +// CHECK-EXT: _Alignof is a C11-specific feature diff --git a/test/Parser/completely-empty-header-file.h b/test/Parser/completely-empty-header-file.h new file mode 100644 index 000000000000..e69de29bb2d1 --- /dev/null +++ b/test/Parser/completely-empty-header-file.h diff --git a/test/Parser/cuda-kernel-call.cu b/test/Parser/cuda-kernel-call.cu index f95ae9e6195f..92e46e3acaf5 100644 --- a/test/Parser/cuda-kernel-call.cu +++ b/test/Parser/cuda-kernel-call.cu @@ -1,9 +1,16 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +template<typename> struct S {}; +template<typename> void f(); + void foo(void) { foo<<<1; // expected-error {{expected '>>>'}} expected-note {{to match this '<<<'}} foo<<<1,1>>>; // expected-error {{expected '('}} foo<<<>>>(); // expected-error {{expected expression}} + + S<S<S<int>>> s; // expected-error 2{{use '> >'}} + + (void)(&f<S<S<int>>>==0); // expected-error 2{{use '> >'}} } diff --git a/test/Parser/cxx-class.cpp b/test/Parser/cxx-class.cpp index 1b3dd41ee829..feccba85cf00 100644 --- a/test/Parser/cxx-class.cpp +++ b/test/Parser/cxx-class.cpp @@ -12,11 +12,15 @@ protected: int : 1, : 2; public: + void m0() {}; // ok, one extra ';' is permitted + void m1() {} + ; // ok, one extra ';' is permitted void m() { int l = 2; - }; + };; // expected-warning{{extra ';' after member function definition}} - template<typename T> void mt(T) { }; + template<typename T> void mt(T) { } + ; ; // expected-warning{{extra ';' inside a class}} virtual int vf() const volatile = 0; diff --git a/test/Parser/cxx-decl.cpp b/test/Parser/cxx-decl.cpp index 57f33d826fff..951cd3dfd1e1 100644 --- a/test/Parser/cxx-decl.cpp +++ b/test/Parser/cxx-decl.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -verify -fsyntax-only -triple i386-linux %s +// RUN: %clang_cc1 -verify -fsyntax-only -triple i386-linux -pedantic %s int x(*g); // expected-error {{use of undeclared identifier 'g'}} @@ -44,7 +44,7 @@ class asm_class_test { void foo() __asm__("baz"); }; -enum { fooenum = 1 }; +enum { fooenum = 1, }; // expected-warning {{commas at the end of enumerator lists are a C++11 extension}} struct a { int Type : fooenum; @@ -125,5 +125,3 @@ test6a { ;// expected-error {{C++ requires a type specifier for all declarations // expected-error {{expected ';' after top level declarator}} int test6b; - - diff --git a/test/Parser/cxx-extra-semi.cpp b/test/Parser/cxx-extra-semi.cpp new file mode 100644 index 000000000000..2aa18dfcc0e4 --- /dev/null +++ b/test/Parser/cxx-extra-semi.cpp @@ -0,0 +1,41 @@ +// RUN: %clang_cc1 -fsyntax-only -pedantic -verify -DPEDANTIC %s +// RUN: %clang_cc1 -fsyntax-only -Wextra-semi -verify %s +// RUN: %clang_cc1 -fsyntax-only -Wextra-semi -verify -std=c++11 %s +// RUN: cp %s %t +// RUN: %clang_cc1 -x c++ -Wextra-semi -fixit %t +// RUN: %clang_cc1 -x c++ -Wextra-semi -Werror %t + +class A { + void A1(); + void A2() { }; +#ifndef PEDANTIC + // This warning is only produced if we specify -Wextra-semi, and not if only + // -pedantic is specified, since one semicolon is technically permitted. + // expected-warning@-4{{extra ';' after member function definition}} +#endif + void A2b() { };; // expected-warning{{extra ';' after member function definition}} + ; // expected-warning{{extra ';' inside a class}} + void A2c() { } + ; +#ifndef PEDANTIC + // expected-warning@-2{{extra ';' after member function definition}} +#endif + void A3() { }; ;; // expected-warning{{extra ';' after member function definition}} + ;;;;;;; // expected-warning{{extra ';' inside a class}} + ; // expected-warning{{extra ';' inside a class}} + ; ;; ; ;;; // expected-warning{{extra ';' inside a class}} + ; ; ; ; ;; // expected-warning{{extra ';' inside a class}} + void A4(); +}; + +union B { + int a1; + int a2;; // expected-warning{{extra ';' inside a union}} +}; + +; +; ;; +#if __cplusplus < 201103L +// expected-warning@-3{{extra ';' outside of a function is a C++11 extension}} +// expected-warning@-3{{extra ';' outside of a function is a C++11 extension}} +#endif diff --git a/test/Parser/cxx-template-argument.cpp b/test/Parser/cxx-template-argument.cpp index c85b1c928111..5479961d563d 100644 --- a/test/Parser/cxx-template-argument.cpp +++ b/test/Parser/cxx-template-argument.cpp @@ -10,3 +10,18 @@ A<int x; // expected-error {{expected '>'}} // PR8912 template <bool> struct S {}; S<bool(2 > 1)> s; + +// Test behavior when a template-id is ended by a token which starts with '>'. +namespace greatergreater { + template<typename T> struct S { S(); S(T); }; + void f(S<int>=0); // expected-error {{a space is required between a right angle bracket and an equals sign (use '> =')}} + void f(S<S<int>>=S<int>()); // expected-error {{use '> >'}} expected-error {{use '> ='}} + template<typename T> void t(); + void g() { + void (*p)() = &t<int>; + (void)(&t<int>==p); // expected-error {{use '> ='}} + (void)(&t<int>>=p); // expected-error {{use '> >'}} + (void)(&t<S<int>>>=p); // expected-error {{use '> >'}} + (void)(&t<S<int>>==p); // expected-error {{use '> >'}} expected-error {{use '> ='}} + } +} diff --git a/test/Parser/cxx-throw.cpp b/test/Parser/cxx-throw.cpp index d63b6d4cae6c..a1be710fb5c0 100644 --- a/test/Parser/cxx-throw.cpp +++ b/test/Parser/cxx-throw.cpp @@ -13,3 +13,5 @@ void foo() { __extension__ throw 1; // expected-error {{expected expression}} (void)throw; // expected-error {{expected expression}} } + +void f() throw(static); // expected-error {{expected a type}} expected-error {{does not allow storage class}} diff --git a/test/Parser/cxx-undeclared-identifier.cpp b/test/Parser/cxx-undeclared-identifier.cpp index f15deabc6da5..6ea2965913a9 100644 --- a/test/Parser/cxx-undeclared-identifier.cpp +++ b/test/Parser/cxx-undeclared-identifier.cpp @@ -1,5 +1,17 @@ // RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s +namespace ImplicitInt { + static a(4); // expected-error {{requires a type specifier}} + b(int n); // expected-error {{requires a type specifier}} + c (*p)[]; // expected-error {{unknown type name 'c'}} + itn f(char *p, *q); // expected-error {{unknown type name 'itn'}} expected-error {{requires a type specifier}} + + struct S { + void f(); + }; + S::f() {} // expected-error {{requires a type specifier}} +} + // PR7180 int f(a::b::c); // expected-error {{use of undeclared identifier 'a'}} diff --git a/test/Parser/cxx-using-declaration.cpp b/test/Parser/cxx-using-declaration.cpp index 2b2a69d1a421..320fd09e55a1 100644 --- a/test/Parser/cxx-using-declaration.cpp +++ b/test/Parser/cxx-using-declaration.cpp @@ -43,3 +43,19 @@ using F::X; // Should have some errors here. Waiting for implementation. void X(int); struct X *x; + + +namespace ShadowedTagNotes { + +namespace foo { + class Bar {}; +} + +void Bar(int); // expected-note{{class 'Bar' is hidden by a non-type declaration of 'Bar' here}} +using foo::Bar; + +void ambiguity() { + const Bar *x; // expected-error{{must use 'class' tag to refer to type 'Bar' in this scope}} +} + +} // namespace ShadowedTagNotes diff --git a/test/Parser/cxx-using-directive.cpp b/test/Parser/cxx-using-directive.cpp index 1d781fbdcf64..9a1a6de89267 100644 --- a/test/Parser/cxx-using-directive.cpp +++ b/test/Parser/cxx-using-directive.cpp @@ -3,7 +3,8 @@ class A {}; namespace B { - namespace A {} // expected-note{{namespace '::B::A' defined here}} + namespace A {} // expected-note{{namespace '::B::A' defined here}} \ + // expected-note{{namespace 'B::A' defined here}} using namespace A ; } @@ -25,7 +26,7 @@ namespace D { } using namespace ! ; // expected-error{{expected namespace name}} -using namespace A ; // expected-error{{expected namespace name}} +using namespace A ; // expected-error{{no namespace named 'A'; did you mean 'B::A'?}} using namespace ::A // expected-error{{expected namespace name}} \ // expected-error{{expected ';' after namespace name}} B ; diff --git a/test/Parser/cxx0x-ambig.cpp b/test/Parser/cxx0x-ambig.cpp index 98757b48c716..96e200642b56 100644 --- a/test/Parser/cxx0x-ambig.cpp +++ b/test/Parser/cxx0x-ambig.cpp @@ -57,7 +57,7 @@ namespace bitfield { // This could be a bit-field, but would be ill-formed due to the anonymous // member being initialized. struct S5 { - enum E : int { a = 1 } { b = 2 }; // expected-error {{expected member name}} + enum E : int { a = 1 } { b = 2 }; // expected-error {{expected ';' after enum}} expected-error {{expected member name}} }; // This could be a bit-field. struct S6 { @@ -85,7 +85,7 @@ namespace trailing_return { struct S { S(int); - S *operator()() const; + S *operator()(...) const; int n; }; @@ -94,7 +94,9 @@ namespace trailing_return { // This parses as a function declaration, but DR1223 makes the presence of // 'auto' be used for disambiguation. S(a)()->n; // ok, expression; expected-warning{{expression result unused}} + S(a)(int())->n; // ok, expression; expected-warning{{expression result unused}} auto(a)()->n; // ok, function declaration + auto(b)(int())->n; // ok, function declaration using T = decltype(a); using T = auto() -> n; } diff --git a/test/Parser/cxx0x-attributes.cpp b/test/Parser/cxx0x-attributes.cpp index f97995e975c8..a0b8467bcca3 100644 --- a/test/Parser/cxx0x-attributes.cpp +++ b/test/Parser/cxx0x-attributes.cpp @@ -1,15 +1,50 @@ // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++11 %s +// Need std::initializer_list +namespace std { + typedef decltype(sizeof(int)) size_t; + + // libc++'s implementation + template <class _E> + class initializer_list + { + const _E* __begin_; + size_t __size_; + + initializer_list(const _E* __b, size_t __s) + : __begin_(__b), + __size_(__s) + {} + + public: + typedef _E value_type; + typedef const _E& reference; + typedef const _E& const_reference; + typedef size_t size_type; + + typedef const _E* iterator; + typedef const _E* const_iterator; + + initializer_list() : __begin_(nullptr), __size_(0) {} + + size_t size() const {return __size_;} + const _E* begin() const {return __begin_;} + const _E* end() const {return __begin_ + __size_;} + }; +} + + // Declaration syntax checks [[]] int before_attr; int [[]] between_attr; +const [[]] int between_attr_2 = 0; // expected-error {{an attribute list cannot appear here}} int after_attr [[]]; int * [[]] ptr_attr; int & [[]] ref_attr = after_attr; int && [[]] rref_attr = 0; int array_attr [1] [[]]; alignas(8) int aligned_attr; -[[test::valid(for 42 [very] **** '+' symbols went on a trip; the end.)]] +[[test::valid(for 42 [very] **** '+' symbols went on a trip and had a "good"_time; the end.)]] int garbage_attr; [[,,,static, class, namespace,, inline, constexpr, mutable,, bi\ tand, bitor::compl(!.*_ Cx.!U^*R),,,]] int more_garbage_attr; @@ -19,7 +54,18 @@ void noexcept_fn_attr () noexcept [[]]; struct MemberFnOrder { virtual void f() const volatile && noexcept [[]] final = 0; }; +struct [[]] struct_attr; class [[]] class_attr {}; +union [[]] union_attr; +[[]] struct with_init_declarators {} init_declarator; +[[]] struct no_init_declarators; // expected-error {{an attribute list cannot appear here}} +[[]]; +struct ctordtor { + [[]] ctordtor(); + [[]] ~ctordtor(); +}; +[[]] ctordtor::ctordtor() {} +[[]] ctordtor::~ctordtor() {} extern "C++" [[]] int extern_attr; template <typename T> [[]] void template_attr (); [[]] [[]] int [[]] [[]] multi_attr [[]] [[]]; @@ -27,7 +73,8 @@ template <typename T> [[]] void template_attr (); int comma_attr [[,]]; int scope_attr [[foo::]]; // expected-error {{expected identifier}} int (paren_attr) [[]]; // expected-error {{an attribute list cannot appear here}} -unsigned [[]] int attr_in_decl_spec; // expected-error {{expected unqualified-id}} +unsigned [[]] int attr_in_decl_spec; // expected-error {{an attribute list cannot appear here}} +unsigned [[]] int [[]] const double_decl_spec = 0; // expected-error 2{{an attribute list cannot appear here}} class foo { void const_after_attr () [[]] const; // expected-error {{expected ';'}} }; @@ -40,6 +87,52 @@ extern "C++" [[]] { } // expected-error {{an attribute list cannot appear here}} [[]] using ns::i; // expected-error {{an attribute list cannot appear here}} [[]] using namespace ns; +[[]] using T = int; // expected-error {{an attribute list cannot appear here}} +using T [[]] = int; // ok +template<typename T> using U [[]] = T; +using ns::i [[]]; // expected-error {{an attribute list cannot appear here}} +using [[]] ns::i; // expected-error {{an attribute list cannot appear here}} + +auto trailing() -> [[]] const int; // expected-error {{an attribute list cannot appear here}} +auto trailing() -> const [[]] int; // expected-error {{an attribute list cannot appear here}} +auto trailing() -> const int [[]]; +auto trailing_2() -> struct struct_attr [[]]; + +namespace N { + struct S {}; +}; +template<typename> struct Template {}; + +// FIXME: Improve this diagnostic +struct [[]] N::S s; // expected-error {{an attribute list cannot appear here}} +struct [[]] Template<int> t; // expected-error {{an attribute list cannot appear here}} +struct [[]] ::template Template<int> u; // expected-error {{an attribute list cannot appear here}} +template struct [[]] Template<char>; // expected-error {{an attribute list cannot appear here}} +template <> struct [[]] Template<void>; + +enum [[]] E1 {}; +enum [[]] E2; // expected-error {{forbids forward references}} +enum [[]] E1; +enum [[]] E3 : int; +enum [[]] { + k_123 [[]] = 123 // expected-error {{an attribute list cannot appear here}} +}; +enum [[]] E1 e; // expected-error {{an attribute list cannot appear here}} +enum [[]] class E4 { }; // expected-error {{an attribute list cannot appear here}} +enum struct [[]] E5; + +struct S { + friend int f [[]] (); // expected-FIXME{{an attribute list cannot appear here}} + [[]] friend int g(); // expected-FIXME{{an attribute list cannot appear here}} + [[]] friend int h() { + } + friend class [[]] C; // expected-error{{an attribute list cannot appear here}} +}; +template<typename T> void tmpl(T) {} +template void tmpl [[]] (int); // expected-FIXME {{an attribute list cannot appear here}} +template [[]] void tmpl(char); // expected-error {{an attribute list cannot appear here}} +template void [[]] tmpl(short); + // Argument tests alignas int aligned_no_params; // expected-error {{expected '('}} alignas(i) int aligned_nonconst; // expected-error {{'aligned' attribute requires integer constant}} expected-note {{read of non-const variable 'i'}} @@ -81,3 +174,41 @@ void foo () { template<typename...Ts> void variadic() { void bar [[noreturn...]] (); // expected-error {{attribute 'noreturn' cannot be used as an attribute pack}} } + +// Expression tests +void bar () { + [] () [[noreturn]] { return; } (); // expected-error {{should not return}} + [] () [[noreturn]] { throw; } (); + new int[42][[]][5][[]]{}; +} + +// Condition tests +void baz () { + if ([[]] bool b = true) { + switch ([[]] int n { 42 }) { + default: + for ([[]] int n = 0; [[]] char b = n < 5; ++b) { + } + } + } + int x; + // An attribute can be applied to an expression-statement, such as the first + // statement in a for. But it can't be applied to a condition which is an + // expression. + for ([[]] x = 0; ; ) {} // expected-error {{an attribute list cannot appear here}} + for (; [[]] x < 5; ) {} // expected-error {{an attribute list cannot appear here}} + while ([[]] bool k { false }) { + } + while ([[]] true) { // expected-error {{an attribute list cannot appear here}} + } + do { + } while ([[]] false); // expected-error {{an attribute list cannot appear here}} + + for ([[]] int n : { 1, 2, 3 }) { + } +} + +enum class __attribute__((visibility("hidden"))) SecretKeepers { + one, /* rest are deprecated */ two, three +}; +enum class [[]] EvenMoreSecrets {}; diff --git a/test/Parser/cxx0x-decl.cpp b/test/Parser/cxx0x-decl.cpp index b9f5141a531e..a6fc49cb9e9d 100644 --- a/test/Parser/cxx0x-decl.cpp +++ b/test/Parser/cxx0x-decl.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -verify -fsyntax-only -std=c++0x %s +// RUN: %clang_cc1 -verify -fsyntax-only -std=c++11 -pedantic %s // Make sure we know these are legitimate commas and not typos for ';'. namespace Commas { @@ -8,7 +8,7 @@ namespace Commas { } struct S {}; -enum E { e }; +enum E { e, }; auto f() -> struct S { return S(); @@ -16,3 +16,15 @@ auto f() -> struct S { auto g() -> enum E { return E(); } + +class ExtraSemiAfterMemFn { + // Due to a peculiarity in the C++11 grammar, a deleted or defaulted function + // is permitted to be followed by either one or two semicolons. + void f() = delete // expected-error {{expected ';' after delete}} + void g() = delete; // ok + void h() = delete;; // ok + void i() = delete;;; // expected-warning {{extra ';' after member function definition}} +}; + +int *const const p = 0; // ok +const const int *q = 0; // expected-warning {{duplicate 'const' declaration specifier}} diff --git a/test/Parser/cxx0x-lambda-expressions.cpp b/test/Parser/cxx0x-lambda-expressions.cpp index 9c7194142128..7e9d4751e6ef 100644 --- a/test/Parser/cxx0x-lambda-expressions.cpp +++ b/test/Parser/cxx0x-lambda-expressions.cpp @@ -40,4 +40,11 @@ class C { int a5[3] = { []{return 0;}() }; int a6[1] = {[this] = 1 }; // expected-error{{integral constant expression must have integral or unscoped enumeration type, not 'C *'}} } + + void delete_lambda(int *p) { + delete [] p; + delete [] (int*) { new int }; // ok, compound-literal, not lambda + delete [] { return new int; } (); // expected-error{{expected expression}} + delete [&] { return new int; } (); // ok, lambda + } }; diff --git a/test/Parser/cxx11-type-specifier.cpp b/test/Parser/cxx11-type-specifier.cpp index 2e629f3ab564..c66462a84f01 100644 --- a/test/Parser/cxx11-type-specifier.cpp +++ b/test/Parser/cxx11-type-specifier.cpp @@ -18,3 +18,7 @@ void f() { (void) new struct S {}; // expected-error{{'S' can not be defined in a type specifier}} (void) new enum E { e }; // expected-error{{'E' can not be defined in a type specifier}} } + +// And for trailing-type-specifier-seq + +auto f() -> unknown; // expected-error{{unknown type name 'unknown'}} diff --git a/test/Parser/declarators.c b/test/Parser/declarators.c index a7a01d8b4e83..f63b59f7caa6 100644 --- a/test/Parser/declarators.c +++ b/test/Parser/declarators.c @@ -100,3 +100,15 @@ long struct X { int x; } test15(); // expected-error {{'long struct' is invalid} void test16(i) int i j; { } // expected-error {{expected ';' at end of declaration}} void test17(i, j) int i, j k; { } // expected-error {{expected ';' at end of declaration}} + + +// PR12595 +void test18() { + int x = 4+(5-12)); // expected-error {{extraneous ')' before ';'}} +} + +enum E1 { e1 }: // expected-error {{expected ';'}} +struct EnumBitfield { + enum E2 { e2 } : 4; // ok + struct S { int n; }: // expected-error {{expected ';'}} +}; diff --git a/test/Parser/empty-translation-unit.c b/test/Parser/empty-translation-unit.c new file mode 100644 index 000000000000..0dbf37e447c3 --- /dev/null +++ b/test/Parser/empty-translation-unit.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -fsyntax-only -std=c99 -pedantic -W -verify %s +// RUN: %clang_cc1 -fsyntax-only -x c++ -std=c++03 -pedantic-errors -W %s + +#include "completely-empty-header-file.h" +// no-warning -- an empty file is OK + +#define A_MACRO_IS_NOT_GOOD_ENOUGH 1 + +// In C we should get this warning, but in C++ we shouldn't. +// expected-warning{{ISO C requires a translation unit to contain at least one declaration.}} diff --git a/test/Parser/missing-selector-name.mm b/test/Parser/missing-selector-name.mm new file mode 100644 index 000000000000..d5554c5e6545 --- /dev/null +++ b/test/Parser/missing-selector-name.mm @@ -0,0 +1,52 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s +// rdar://11939584 + +@interface PodiumWalkerController +@property (assign) id PROP; +- (void) // expected-error {{expected ';' after method prototype}} +@end // expected-error {{expected selector for Objective-C method}} + + +id GVAR; + +id StopProgressAnimation() +{ + + PodiumWalkerController *controller; + return controller.PROP; +} + +@interface P1 +@property (assign) id PROP; +- (void); // expected-error {{expected selector for Objective-C method}} +@end + +id GG=0; + +id Stop1() +{ + + PodiumWalkerController *controller; + return controller.PROP; +} + +@interface P2 +@property (assign) id PROP; +- (void)Meth {} // expected-error {{expected ';' after method prototype}} +@end + +@interface P3 +@property (assign) id PROP; +- (void) +- (void)Meth {} // expected-error {{expected selector for Objective-C method}} \ + // expected-error {{expected ';' after method prototype}} +@end + +id HH=0; + +id Stop2() +{ + + PodiumWalkerController *controller; + return controller.PROP; +} diff --git a/test/Parser/ms-inline-asm.c b/test/Parser/ms-inline-asm.c index b1af23e47280..2d181958857b 100644 --- a/test/Parser/ms-inline-asm.c +++ b/test/Parser/ms-inline-asm.c @@ -3,23 +3,36 @@ #define M __asm int 0x2c #define M2 int -void t1(void) { M } -void t2(void) { __asm int 0x2c } -void t3(void) { __asm M2 0x2c } -void* t4(void) { __asm mov eax, fs:[0x10] } +void t1(void) { M } // expected-warning {{MS-style inline assembly is not supported}} +void t2(void) { __asm int 0x2c } // expected-warning {{MS-style inline assembly is not supported}} +void t3(void) { __asm M2 0x2c } // expected-warning {{MS-style inline assembly is not supported}} +void* t4(void) { __asm mov eax, fs:[0x10] } // expected-warning {{MS-style inline assembly is not supported}} void t5() { - __asm { + __asm { // expected-warning {{MS-style inline assembly is not supported}} int 0x2c ; } asm comments are fun! }{ } - __asm {} + __asm {} // no warning as this gets merged with the previous inline asm } int t6() { - __asm int 3 ; } comments for single-line asm - __asm {} + __asm int 3 ; } comments for single-line asm // expected-warning {{MS-style inline assembly is not supported}} + __asm {} // no warning as this gets merged with the previous inline asm - __asm int 4 + __asm int 4 // no warning as this gets merged with the previous inline asm return 10; } -int t7() { // expected-note {{to match this}} +int t7() { + __asm { // expected-warning {{MS-style inline assembly is not supported}} + push ebx + mov ebx, 0x07 + pop ebx + } +} +void t8() { + __asm nop __asm nop __asm nop // expected-warning {{MS-style inline assembly is not supported}} +} +void t9() { + __asm nop __asm nop ; __asm nop // expected-warning {{MS-style inline assembly is not supported}} +} +int t_fail() { // expected-note {{to match this}} __asm __asm { // expected-error 3 {{expected}} expected-note {{to match this}} diff --git a/test/Parser/objc-boxing.m b/test/Parser/objc-boxing.m new file mode 100644 index 000000000000..a16a137b8f65 --- /dev/null +++ b/test/Parser/objc-boxing.m @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +@interface NSString @end + +@interface NSString (NSStringExtensionMethods) ++ (id)stringWithUTF8String:(const char *)nullTerminatedCString; +@end + +extern char *strdup(const char *str); + +id constant_string() { + return @("boxed constant string."); +} + +id dynamic_string() { + return @(strdup("boxed dynamic string")); +} + +id const_char_pointer() { + return @((const char *)"constant character pointer"); +} + +id missing_parentheses() { + return @(5; // expected-error {{expected ')'}} \ + // expected-note {{to match this '('}} +} diff --git a/test/Parser/objc-diag-width.mm b/test/Parser/objc-diag-width.mm new file mode 100644 index 000000000000..3929ba2b090e --- /dev/null +++ b/test/Parser/objc-diag-width.mm @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 %s 2>&1 | FileCheck %s + +// Just shouldn't crash. -verify suppresses the crash, so don't use it. +// PR13417 +// CHECK-NOT: Assertion failed +@interface ExtensionActionContextMenu @end +@implementation ExtensionActionContextMenu +namespace { diff --git a/test/Parser/objc-forcollection-neg.m b/test/Parser/objc-forcollection-neg.m index 1a989a14464c..9e5400c5f2ed 100644 --- a/test/Parser/objc-forcollection-neg.m +++ b/test/Parser/objc-forcollection-neg.m @@ -26,12 +26,12 @@ typedef struct objc_object { int i=0; for (int * elem in elem) // expected-error {{selector element type 'int *' is not a valid object}} \ - expected-error {{collection expression type 'int *' is not a valid object}} + expected-error {{the type 'int *' is not a pointer to a fast-enumerable object}} ++i; for (i in elem) // expected-error {{use of undeclared identifier 'elem'}} \ expected-error {{selector element type 'int' is not a valid object}} ++i; - for (id se in i) // expected-error {{collection expression type 'int' is not a valid object}} + for (id se in i) // expected-error {{the type 'int' is not a pointer to a fast-enumerable object}} ++i; } @end diff --git a/test/Parser/objc-init.m b/test/Parser/objc-init.m index efa1266e7b8e..c9d7d5d301ea 100644 --- a/test/Parser/objc-init.m +++ b/test/Parser/objc-init.m @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -fsyntax-only -fobjc-fragile-abi -verify -pedantic -Wno-objc-root-class %s -// RUN: %clang_cc1 -fsyntax-only -fobjc-fragile-abi -verify -x objective-c++ -Wno-objc-root-class %s +// RUN: %clang_cc1 -fsyntax-only -fobjc-runtime=macosx-fragile -verify -pedantic -Wno-objc-root-class %s +// RUN: %clang_cc1 -fsyntax-only -fobjc-runtime=macosx-fragile -verify -x objective-c++ -Wno-objc-root-class %s // rdar://5707001 @interface NSNumber; diff --git a/test/Parser/objc-recover.mm b/test/Parser/objc-recover.mm new file mode 100644 index 000000000000..61444c7178d0 --- /dev/null +++ b/test/Parser/objc-recover.mm @@ -0,0 +1,64 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s + +@interface StopAtAtEnd +// This used to eat the @end +int 123 // expected-error{{expected unqualified-id}} +@end + +@implementation StopAtAtEnd // no-warning +int 123 // expected-error{{expected unqualified-id}} +@end + + +@interface StopAtMethodDecls +// This used to eat the method declarations +int 123 // expected-error{{expected unqualified-id}} +- (void)foo; // expected-note{{here}} +int 456 // expected-error{{expected unqualified-id}} ++ (void)bar; // expected-note{{here}} +@end + +@implementation StopAtMethodDecls +int 123 // expected-error{{expected unqualified-id}} +- (id)foo {} // expected-warning{{conflicting return type}} +int 456 // expected-error{{expected unqualified-id}} ++ (id)bar {} // expected-warning{{conflicting return type}} +@end + + +@interface EmbeddedNamespace +// This used to cause an infinite loop. +namespace NS { // expected-error{{expected unqualified-id}} +} +- (id)test; // expected-note{{here}} +@end + +@implementation EmbeddedNamespace +int 123 // expected-error{{expected unqualified-id}} +// We should still stop here and parse this namespace. +namespace NS { + void foo(); +} + +// Make sure the declaration of -test was recognized. +- (void)test { // expected-warning{{conflicting return type}} + // Make sure the declaration of NS::foo was recognized. + NS::foo(); +} + +@end + + +@protocol ProtocolWithEmbeddedNamespace +namespace NS { // expected-error{{expected unqualified-id}} + +} +- (void)PWEN_foo; // expected-note{{here}} +@end + +@interface ImplementPWEN <ProtocolWithEmbeddedNamespace> +@end + +@implementation ImplementPWEN +- (id)PWEN_foo {} // expected-warning{{conflicting return type}} +@end diff --git a/test/Parser/objcxx11-attributes.mm b/test/Parser/objcxx11-attributes.mm index 0c91392978af..1b9bf66fad9a 100644 --- a/test/Parser/objcxx11-attributes.mm +++ b/test/Parser/objcxx11-attributes.mm @@ -35,7 +35,8 @@ void f(X *noreturn) { [[class, test(foo 'x' bar),,,]]; [[bitand, noreturn]]; // expected-warning {{attribute noreturn cannot be specified on a statement}} - [[noreturn]]int(e)(); + // FIXME: Suppress vexing parse warning + [[noreturn]]int(e)(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}} int e2(); // expected-warning {{interpreted as a function declaration}} expected-note{{}} // A function taking a noreturn function. diff --git a/test/Parser/opencl-pragma.cl b/test/Parser/opencl-pragma.cl index 19460771137b..4c48b2a496f7 100644 --- a/test/Parser/opencl-pragma.cl +++ b/test/Parser/opencl-pragma.cl @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only +// RUN: %clang_cc1 %s -verify -pedantic -Wno-empty-translation-unit -fsyntax-only #pragma OPENCL EXTENSION cl_khr_fp16 : enable diff --git a/test/Parser/recovery.c b/test/Parser/recovery.c index 3916acfda1e0..178427e4b3c2 100644 --- a/test/Parser/recovery.c +++ b/test/Parser/recovery.c @@ -37,8 +37,9 @@ void test(int a) { test(0); else ; - - if (x.i == 0)) // expected-error {{expected expression}} + + // PR12595 + if (x.i == 0)) // expected-error {{extraneous ')' after condition, expected a statement}} test(0); else ; diff --git a/test/Parser/recovery.cpp b/test/Parser/recovery.cpp index ffa1bab55a44..ff687583c253 100644 --- a/test/Parser/recovery.cpp +++ b/test/Parser/recovery.cpp @@ -12,13 +12,12 @@ inline namespace Std { // expected-error {{cannot be reopened as inline}} int x; Std::Important y; -// FIXME: Recover as if the typo correction were applied. -extenr "C" { // expected-error {{did you mean 'extern'}} expected-error {{unqualified-id}} +extenr "C" { // expected-error {{did you mean the keyword 'extern'}} void f(); } void g() { z = 1; // expected-error {{undeclared}} - f(); // expected-error {{undeclared}} + f(); } struct S { @@ -37,6 +36,7 @@ namespace N { int } // expected-error {{unqualified-id}} -// FIXME: Recover as if the typo correction were applied. -strcut U { // expected-error {{did you mean 'struct'}} -} *u[3]; // expected-error {{expected ';'}} +strcut Uuuu { // expected-error {{did you mean the keyword 'struct'}} \ + // expected-note {{'Uuuu' declared here}} +} *u[3]; +uuuu v; // expected-error {{did you mean 'Uuuu'}} |