diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2012-04-14 14:01:31 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2012-04-14 14:01:31 +0000 |
commit | dbe13110f59f48b4dbb7552b3ac2935acdeece7f (patch) | |
tree | be1815eb79b42ff482a8562b13c2dcbf0c5dcbee /test/Parser | |
parent | 9da628931ebf2609493570f87824ca22402cc65f (diff) |
Notes
Diffstat (limited to 'test/Parser')
54 files changed, 942 insertions, 101 deletions
diff --git a/test/Parser/DelayedTemplateParsing.cpp b/test/Parser/DelayedTemplateParsing.cpp index b02c4026c048e..9737c731bd170 100644 --- a/test/Parser/DelayedTemplateParsing.cpp +++ b/test/Parser/DelayedTemplateParsing.cpp @@ -12,6 +12,10 @@ template <class T> class B { void foo4() { } // expected-note {{previous definition is here}} expected-note {{previous definition is here}} void foo4() { } // expected-error {{class member cannot be redeclared}} expected-error {{redefinition of 'foo4'}} expected-note {{previous definition is here}} + + friend void foo3() { + undeclared(); + } }; @@ -59,3 +63,30 @@ public: } + +namespace PR11931 { + +template <typename RunType> +struct BindState; + + template<> +struct BindState<void(void*)> { + static void Run() { } +}; + +class Callback { +public: + typedef void RunType(); + + template <typename RunType> + Callback(BindState<RunType> bind_state) { + BindState<RunType>::Run(); + } +}; + + +Callback Bind() { + return Callback(BindState<void(void*)>()); +} + +} diff --git a/test/Parser/MicrosoftExtensions.c b/test/Parser/MicrosoftExtensions.c index a0f15e9d86347..1ef326aaf5d35 100644 --- a/test/Parser/MicrosoftExtensions.c +++ b/test/Parser/MicrosoftExtensions.c @@ -49,9 +49,16 @@ char x = FOO(a); typedef enum E { e1 }; +enum __declspec(deprecated) E2 { i, j, k }; +__declspec(deprecated) enum E3 { a, b, c } e; - - +void deprecated_enum_test(void) +{ + // Test to make sure the deprecated warning follows the right thing + enum E2 e1; // expected-warning {{'E2' is deprecated}} + enum E3 e2; // No warning expected, the deprecation follows the variable + enum E3 e3 = e; // expected-warning {{'e' is deprecated}} +} /* Microsoft attribute tests */ [repeatable][source_annotation_attribute( Parameter|ReturnValue )] diff --git a/test/Parser/MicrosoftExtensions.cpp b/test/Parser/MicrosoftExtensions.cpp index 3a72ea0234c92..89394c303ca81 100644 --- a/test/Parser/MicrosoftExtensions.cpp +++ b/test/Parser/MicrosoftExtensions.cpp @@ -165,6 +165,11 @@ __interface MicrosoftInterface { virtual void foo2() = 0; }; +void interface_test() { + MicrosoftInterface* a; + a->foo1(); +} + __int64 x7 = __int64(0); @@ -210,6 +215,35 @@ __if_not_exists(IF_EXISTS::Type_not) { int var244; } +int __if_exists_init_list() { + + int array1[] = {
+ 0,
+ __if_exists(IF_EXISTS::Type) {2, }
+ 3
+ };
+ + int array2[] = {
+ 0,
+ __if_exists(IF_EXISTS::Type_not) { this wont compile }
+ 3
+ };
+
+ int array3[] = {
+ 0,
+ __if_not_exists(IF_EXISTS::Type_not) {2, }
+ 3
+ };
+ + int array4[] = {
+ 0,
+ __if_not_exists(IF_EXISTS::Type) { this wont compile }
+ 3
+ };
+ +} + + class IF_EXISTS_CLASS_TEST { __if_exists(IF_EXISTS::Type) { // __if_exists, __if_not_exists can nest diff --git a/test/Parser/asm.c b/test/Parser/asm.c index 90818261513fe..23052c389eb29 100644 --- a/test/Parser/asm.c +++ b/test/Parser/asm.c @@ -14,3 +14,6 @@ void f2() { // rdar://5952468 __asm ; // expected-error {{expected '(' after 'asm'}} +// <rdar://problem/10465079> - Don't crash on wide string literals in 'asm'. +int foo asm (L"bar"); // expected-error {{cannot use wide string literal in 'asm'}} + diff --git a/test/Parser/asm.cpp b/test/Parser/asm.cpp new file mode 100644 index 0000000000000..35a497c83a1e8 --- /dev/null +++ b/test/Parser/asm.cpp @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s + +int foo1 asm ("bar1"); +int foo2 asm (L"bar2"); // expected-error {{cannot use wide string literal in 'asm'}} +int foo3 asm (u8"bar3"); // expected-error {{cannot use unicode string literal in 'asm'}} +int foo4 asm (u"bar4"); // expected-error {{cannot use unicode string literal in 'asm'}} +int foo5 asm (U"bar5"); // expected-error {{cannot use unicode string literal in 'asm'}} +int foo6 asm ("bar6"_x); // expected-error {{string literal with user-defined suffix cannot be used here}} diff --git a/test/Parser/attr-availability.c b/test/Parser/attr-availability.c index 269f90847d660..b9ff31c811c56 100644 --- a/test/Parser/attr-availability.c +++ b/test/Parser/attr-availability.c @@ -16,5 +16,13 @@ void f4() __attribute__((availability(macosx,introduced=10.5), availability(ios, void f5() __attribute__((availability(macosx,introduced=10.5), availability(ios,unavailable, unavailable))); // expected-error{{redundant 'unavailable' availability change; only the last specified change will be used}} -void f6() __attribute__((availability(macosx,unavailable,introduced=10.5))); // expected-warning{{warning: 'unavailable' availability overrides all other availability information}} +void f6() __attribute__((availability(macosx,unavailable,introduced=10.5))); // expected-warning{{'unavailable' availability overrides all other availability information}} +// rdar://10095131 +enum E{ + gorf __attribute__((availability(macosx,introduced=8.5, message = 10.0))), // expected-error {{expected string literal}} + garf __attribute__((availability(macosx,introduced=8.5, message))), // expected-error {{expected '=' after 'message'}} + + foo __attribute__((availability(macosx,introduced=8.5,deprecated=9.0, message="Use CTFontCopyPostScriptName()", deprecated=10.0))) // expected-error {{expected ')'}} \ + // expected-note {{to match this '('}} +}; diff --git a/test/Parser/attributes.c b/test/Parser/attributes.c index b2873638cdba8..347cb9c1bfbf3 100644 --- a/test/Parser/attributes.c +++ b/test/Parser/attributes.c @@ -56,3 +56,43 @@ void d2(void) __attribute__((noreturn)), d3(void) __attribute__((noreturn)); // PR6287 void __attribute__((returns_twice)) returns_twice_test(); + +int aligned(int); +int __attribute__((vec_type_hint(char, aligned(16) )) missing_rparen_1; // expected-error {{expected ')'}} +int __attribute__((mode(x aligned(16) )) missing_rparen_2; // expected-error {{expected ')'}} +int __attribute__((format(printf, 0 aligned(16) )) missing_rparen_3; // expected-error {{expected ')'}} + + + +int testFundef1(int *a) __attribute__((nonnull(1))) { // \ + // expected-warning {{GCC does not allow nonnull attribute in this position on a function definition}} + return *a; +} + +// noreturn is lifted to type qualifier +void testFundef2() __attribute__((noreturn)) { // \ + // expected-warning {{GCC does not allow noreturn attribute in this position on a function definition}} + testFundef2(); +} + +int testFundef3(int *a) __attribute__((nonnull(1), // \ + // expected-warning {{GCC does not allow nonnull attribute in this position on a function definition}} + pure)) { // \ + // expected-warning {{GCC does not allow pure attribute in this position on a function definition}} + return *a; +} + +int testFundef4(int *a) __attribute__((nonnull(1))) // \ + // expected-warning {{GCC does not allow nonnull attribute in this position on a function definition}} + __attribute((pure)) { // \ + // expected-warning {{GCC does not allow pure attribute in this position on a function definition}} + return *a; +} + +// GCC allows these +void testFundef5() __attribute__(()) { } + +__attribute__((pure)) int testFundef6(int a) { return a; } + + + diff --git a/test/Parser/bracket-crash.cpp b/test/Parser/bracket-crash.cpp index fd18e0e25fefd..bcc6eabc6e99c 100644 --- a/test/Parser/bracket-crash.cpp +++ b/test/Parser/bracket-crash.cpp @@ -1,6 +1,6 @@ -// RUN: not %clang_cc1 -fsyntax-only %s +// RUN: not %clang_cc1 -fsyntax-only -std=c++11 %s // PR7481 +decltype(; struct{ a } - diff --git a/test/Parser/check-syntax-1.m b/test/Parser/check-syntax-1.m index db37793c560f2..0ae0c5dc2934d 100644 --- a/test/Parser/check-syntax-1.m +++ b/test/Parser/check-syntax-1.m @@ -6,7 +6,7 @@ int @interface bla ; // expected-error {{cannot combine with previous 'int' dec typedef float CGFloat; @interface XNSNumber + (XNSNumber *) numberWithCGFloat : (CGFloat) float; // expected-error {{expected identifier}} \ - // expected-error {{ expected ';' after method prototype}} + // expected-error {{expected ';' after method prototype}} @end // rdar: // 7822196 diff --git a/test/Parser/cxx-altivec.cpp b/test/Parser/cxx-altivec.cpp index 4d924503bbb91..9b2b1af22f6e5 100644 --- a/test/Parser/cxx-altivec.cpp +++ b/test/Parser/cxx-altivec.cpp @@ -67,7 +67,7 @@ __vector double vv_d1; // expected-error {{cannot use 'double' wit vector double v_d2; // expected-error {{cannot use 'double' with '__vector'}} __vector long double vv_ld3; // expected-warning {{Use of 'long' with '__vector' is deprecated}} expected-error {{cannot use 'double' with '__vector'}} vector long double v_ld4; // expected-warning {{Use of 'long' with '__vector' is deprecated}} expected-error {{cannot use 'double' with '__vector'}} -vector bool v_b; // expected-error {{error: C++ requires a type specifier for all declarations}} +vector bool v_b; // expected-error {{C++ requires a type specifier for all declarations}} vector bool float v_bf; // expected-error {{cannot use 'float' with '__vector bool'}} vector bool double v_bd; // expected-error {{cannot use 'double' with '__vector bool'}} vector bool pixel v_bp; // expected-error {{cannot use '__pixel' with '__vector bool'}} diff --git a/test/Parser/cxx-class.cpp b/test/Parser/cxx-class.cpp index 1c0d862b3096a..1b3dd41ee829e 100644 --- a/test/Parser/cxx-class.cpp +++ b/test/Parser/cxx-class.cpp @@ -54,6 +54,36 @@ public; // expected-error{{expected ':'}} int i; }; +class F { + int F1 { return 1; } // expected-error{{function definition does not declare parameters}} + void F2 {} // expected-error{{function definition does not declare parameters}} + typedef int F3() { return 0; } // expected-error{{function definition declared 'typedef'}} + typedef void F4() {} // expected-error{{function definition declared 'typedef'}} +}; + +namespace ctor_error { + class Foo {}; + // By [class.qual]p2, this is a constructor declaration. + Foo::Foo (F) = F(); // expected-error{{does not match any declaration in 'ctor_error::Foo'}} + + class Ctor { // expected-note{{not complete until the closing '}'}} + Ctor(f)(int); // ok + Ctor(g(int)); // ok + Ctor(x[5]); // expected-error{{incomplete type}} + + Ctor(UnknownType *); // expected-error{{unknown type name 'UnknownType'}} + void operator+(UnknownType*); // expected-error{{unknown type name 'UnknownType'}} + }; + + Ctor::Ctor (x) = { 0 }; // \ + // expected-error{{qualified reference to 'Ctor' is a constructor name}} + + Ctor::Ctor(UnknownType *) {} // \ + // expected-error{{unknown type name 'UnknownType'}} + void Ctor::operator+(UnknownType*) {} // \ + // expected-error{{unknown type name 'UnknownType'}} +} + // PR11109 must appear at the end of the source file class pr11109r3 { // expected-note{{to match this '{'}} public // expected-error{{expected ':'}} expected-error{{expected '}'}} expected-error{{expected ';' after class}} diff --git a/test/Parser/cxx-condition.cpp b/test/Parser/cxx-condition.cpp index 552d82362461e..5672eea72bcf7 100644 --- a/test/Parser/cxx-condition.cpp +++ b/test/Parser/cxx-condition.cpp @@ -1,11 +1,15 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +struct S { S(int); operator bool(); }; + void f() { int a; while (a) ; - while (int x) ; // expected-error {{expected '=' after declarator}} + while (int x) ; // expected-error {{variable declaration in condition must have an initializer}} while (float x = 0) ; - if (const int x = a) ; // expected-warning{{empty body}} + if (const int x = a) ; // expected-warning{{empty body}} expected-note{{put the semicolon on a separate line to silence this warning}} switch (int x = a+10) {} for (; int x = ++a; ) ; + + if (S a(42)) {} // expected-error {{variable declaration in condition cannot have a parenthesized initializer}} } diff --git a/test/Parser/cxx-decl.cpp b/test/Parser/cxx-decl.cpp index 70eff973e0e1b..57f33d826fff5 100644 --- a/test/Parser/cxx-decl.cpp +++ b/test/Parser/cxx-decl.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -verify -fsyntax-only %s +// RUN: %clang_cc1 -verify -fsyntax-only -triple i386-linux %s int x(*g); // expected-error {{use of undeclared identifier 'g'}} @@ -66,6 +66,36 @@ struct test4 { int z // expected-error {{expected ';' at end of declaration list}} }; +// Make sure we know these are legitimate commas and not typos for ';'. +namespace Commas { + struct S { + static int a; + int c, + operator()(); + }; + + int global1, + __attribute__(()) global2, + (global5), + *global6, + &global7 = global1, + &&global8 = static_cast<int&&>(global1), // expected-warning 2{{rvalue reference}} + S::a, + global9, + global10 = 0, + global11 == 0, // expected-error {{did you mean '='}} + global12 __attribute__(()), + global13(0), + global14[2], + global15; + + void g() { + static int a, + b __asm__("ebx"), // expected-error {{expected ';' at end of declaration}} + Statics:return; + } +} + // PR5825 struct test5 {}; ::new(static_cast<void*>(0)) test5; // expected-error {{expected unqualified-id}} diff --git a/test/Parser/cxx-default-delete.cpp b/test/Parser/cxx-default-delete.cpp index f34f6fb014f2b..df24b3d0075a9 100644 --- a/test/Parser/cxx-default-delete.cpp +++ b/test/Parser/cxx-default-delete.cpp @@ -3,8 +3,12 @@ int i = delete; // expected-error{{only functions}} int j = default; // expected-error{{special member functions}} -int f() = delete, g; // expected-error{{standalone}} -int o, p() = delete; // expected-error{{standalone}} +int f() = delete, g; // expected-error{{'= delete' is a function definition}} +int o, p() = delete; // expected-error{{'= delete' is a function definition}} + +int q() = default, r; // expected-error{{only special member functions}} \ + // expected-error{{'= default' is a function definition}} +int s, t() = default; // expected-error{{'= default' is a function definition}} struct foo { foo() = default; @@ -13,3 +17,7 @@ struct foo { }; void baz() = delete; + +struct quux { + int quux() = default; // expected-error{{constructor cannot have a return type}} expected-error {{member 'quux' has the same name as its class}} +}; diff --git a/test/Parser/cxx-ext-delete-default.cpp b/test/Parser/cxx-ext-delete-default.cpp index be6efee241639..af8b6d6d34711 100644 --- a/test/Parser/cxx-ext-delete-default.cpp +++ b/test/Parser/cxx-ext-delete-default.cpp @@ -1,11 +1,11 @@ // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s struct A { - A(const A&) = delete; // expected-warning {{accepted as a C++11 extension}} - A& operator=(const A&) = delete; // expected-warning {{accepted as a C++11 extension}} - A() = default; // expected-warning {{accepted as a C++11 extension}} + A(const A&) = delete; // expected-warning {{C++11 extension}} + A& operator=(const A&) = delete; // expected-warning {{C++11 extension}} + A() = default; // expected-warning {{C++11 extension}} ~A(); }; -void f() = delete; // expected-warning {{accepted as a C++11 extension}} -A::~A() = default; //expected-warning {{accepted as a C++11 extension}} +void f() = delete; // expected-warning {{C++11 extension}} +A::~A() = default; //expected-warning {{C++11 extension}} diff --git a/test/Parser/cxx-template-decl.cpp b/test/Parser/cxx-template-decl.cpp index 4717dbb7dc2d3..7e931a31fa2d5 100644 --- a/test/Parser/cxx-template-decl.cpp +++ b/test/Parser/cxx-template-decl.cpp @@ -6,15 +6,20 @@ template x; // expected-error {{C++ requires a type specifier for al // expected-error {{does not refer}} export template x; // expected-error {{expected '<' after 'template'}} export template<class T> class x0; // expected-warning {{exported templates are unsupported}} -template < ; // expected-error {{parse error}} \ +template < ; // expected-error {{expected template parameter}} \ // expected-error{{expected ',' or '>' in template-parameter-list}} \ // expected-warning {{declaration does not declare anything}} +template <int +> struct x1; // expected-error {{expected ',' or '>' in template-parameter-list}} + +// verifies that we only walk to the ',' & still produce errors on the rest of the template parameters +template <int +, T> struct x2; // expected-error {{expected ',' or '>' in template-parameter-list}} \ + expected-error {{expected unqualified-id}} +template<template<int+>> struct x3; // expected-error {{expected ',' or '>' in template-parameter-list}} \ + expected-error {{template template parameter requires 'class' after the parameter list}} template <template X> struct Err1; // expected-error {{expected '<' after 'template'}} \ // expected-error{{extraneous}} -template <template <typename> > struct Err2; // expected-error {{expected 'class' before '>'}} \ -// expected-error{{extraneous}} -template <template <typename> Foo> struct Err3; // expected-error {{expected 'class' before 'Foo'}} \ -// expected-error{{extraneous}} +template <template <typename> > struct Err2; // expected-error {{template template parameter requires 'class' after the parameter list}} +template <template <typename> Foo> struct Err3; // expected-error {{template template parameter requires 'class' after the parameter list}} // Template function declarations template <typename T> void foo(); diff --git a/test/Parser/cxx-typeid.cpp b/test/Parser/cxx-typeid.cpp index a825dc3cc7a56..e726665a36d05 100644 --- a/test/Parser/cxx-typeid.cpp +++ b/test/Parser/cxx-typeid.cpp @@ -9,5 +9,5 @@ void f() { (void)typeid(int); (void)typeid(0); - (void)typeid 1; // expected-error {{error: expected '(' after 'typeid'}} + (void)typeid 1; // expected-error {{expected '(' after 'typeid'}} } diff --git a/test/Parser/cxx-typeof.cpp b/test/Parser/cxx-typeof.cpp index 4c598e9517ed5..1ec6e29b1311f 100644 --- a/test/Parser/cxx-typeof.cpp +++ b/test/Parser/cxx-typeof.cpp @@ -9,5 +9,5 @@ static void test() { // Part of rdar://problem/8347416; from the gcc test suite. struct S { int i; - __typeof(S::i) foo(); // expected-error {{invalid use of nonstatic data member 'i'}} + __typeof(S::i) foo(); // expected-error {{invalid use of non-static data member 'i'}} }; diff --git a/test/Parser/cxx-using-directive.cpp b/test/Parser/cxx-using-directive.cpp index 1e918996d1470..1d781fbdcf644 100644 --- a/test/Parser/cxx-using-directive.cpp +++ b/test/Parser/cxx-using-directive.cpp @@ -3,7 +3,7 @@ class A {}; namespace B { - namespace A {} + namespace A {} // expected-note{{namespace '::B::A' defined here}} using namespace A ; } @@ -19,8 +19,7 @@ namespace D { namespace B {} using namespace C ; - using namespace B::A ; // expected-error{{expected namespace name}} - //FIXME: would be nice to note, that A is not member of D::B + using namespace B::A ; // expected-error{{no namespace named 'A' in namespace 'D::B'; did you mean '::B::A'?}} using namespace ::B::A ; using namespace ::D::C ; // expected-error{{expected namespace name}} } @@ -37,4 +36,3 @@ void test_nslookup() { using namespace B; using namespace C; } - diff --git a/test/Parser/cxx0x-ambig.cpp b/test/Parser/cxx0x-ambig.cpp new file mode 100644 index 0000000000000..98757b48c7162 --- /dev/null +++ b/test/Parser/cxx0x-ambig.cpp @@ -0,0 +1,127 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s + +// New exciting ambiguities in C++11 + +// final 'context sensitive' mess. +namespace final { + struct S { int n; }; + struct T { int n; }; + namespace N { + int n; + // These declare variables named final.. + extern struct S final; + extern struct S final [[]]; + extern struct S final, foo; + struct S final = S(); + + // This defines a class, not a variable, even though it would successfully + // parse as a variable but not as a class. DR1318's wording suggests that + // this disambiguation is only performed on an ambiguity, but that was not + // the intent. + struct S final { // expected-note {{here}} + int(n) // expected-error {{expected ';'}} + }; + // This too. + struct T final : S {}; // expected-error {{base 'S' is marked 'final'}} + struct T bar : S {}; // expected-error {{expected ';' after top level declarator}} expected-error {{expected unqualified-id}} + } +} + +// enum versus bitfield mess. +namespace bitfield { + enum E {}; + + struct T { + constexpr T() {} + constexpr T(int) {} + constexpr T(T, T, T, T) {} + constexpr T operator=(T) { return *this; } + constexpr operator int() { return 4; } + }; + constexpr T a, b, c, d; + + struct S1 { + enum E : T ( a = 1, b = 2, c = 3, 4 ); // ok, declares a bitfield + }; + // This could be a bit-field. + struct S2 { + enum E : T { a = 1, b = 2, c = 3, 4 }; // expected-error {{non-integral type}} expected-error {{expected '}'}} expected-note {{to match}} + }; + struct S3 { + enum E : int { a = 1, b = 2, c = 3, d }; // ok, defines an enum + }; + // Ambiguous. + struct S4 { + enum E : int { a = 1 }; // ok, defines an enum + }; + // 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}} + }; + // This could be a bit-field. + struct S6 { + enum E : int { 1 }; // expected-error {{expected '}'}} expected-note {{to match}} + }; + + struct U { + constexpr operator T() { return T(); } // expected-note 2{{candidate}} + }; + // This could be a bit-field. + struct S7 { + enum E : int { a = U() }; // expected-error {{no viable conversion}} + }; + // This could be a bit-field, and does not conform to the grammar of an + // enum definition, because 'id(U())' is not a constant-expression. + constexpr const U &id(const U &u) { return u; } + struct S8 { + enum E : int { a = id(U()) }; // expected-error {{no viable conversion}} + }; +} + +namespace trailing_return { + typedef int n; + int a; + + struct S { + S(int); + S *operator()() const; + int n; + }; + + namespace N { + void f() { + // 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}} + auto(a)()->n; // ok, function declaration + using T = decltype(a); + using T = auto() -> n; + } + } +} + +namespace ellipsis { + template<typename...T> + struct S { + void e(S::S()); + void f(S(...args[sizeof(T)])); // expected-note {{here}} + void f(S(...args)[sizeof(T)]); // expected-error {{redeclared}} expected-note {{here}} + void f(S ...args[sizeof(T)]); // expected-error {{redeclared}} + void g(S(...[sizeof(T)])); // expected-note {{here}} + void g(S(...)[sizeof(T)]); // expected-error {{function cannot return array type}} + void g(S ...[sizeof(T)]); // expected-error {{redeclared}} + void h(T(...)); // function type, expected-error {{unexpanded parameter pack}} + void h(T...); // pack expansion, ok + void i(int(T...)); // expected-note {{here}} + void i(int(T...a)); // expected-error {{redeclared}} + void i(int(T, ...)); // function type, expected-error {{unexpanded parameter pack}} + void i(int(T, ...a)); // expected-error {{expected ')'}} expected-note {{to match}} expected-error {{unexpanded parameter pack}} + void j(int(int...)); // function type, ok + void j(int(int...a)); // expected-error {{does not contain any unexpanded parameter packs}} + void j(T(int...)); // expected-error {{unexpanded parameter pack}} + void j(T(T...)); // expected-error {{unexpanded parameter pack}} + void k(int(...)(T)); // expected-error {{cannot return function type}} + void k(int ...(T)); + }; +} diff --git a/test/Parser/cxx0x-attributes.cpp b/test/Parser/cxx0x-attributes.cpp index e762b57a93d62..f97995e975c8a 100644 --- a/test/Parser/cxx0x-attributes.cpp +++ b/test/Parser/cxx0x-attributes.cpp @@ -5,26 +5,35 @@ int [[]] between_attr; 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.)]] int garbage_attr; +[[,,,static, class, namespace,, inline, constexpr, mutable,, bi\ +tand, bitor::compl(!.*_ Cx.!U^*R),,,]] int more_garbage_attr; +[[u8"invalid!"]] int invalid_string_attr; // expected-error {{expected ']'}} void fn_attr () [[]]; +void noexcept_fn_attr () noexcept [[]]; +struct MemberFnOrder { + virtual void f() const volatile && noexcept [[]] final = 0; +}; class [[]] class_attr {}; extern "C++" [[]] int extern_attr; template <typename T> [[]] void template_attr (); [[]] [[]] int [[]] [[]] multi_attr [[]] [[]]; -int comma_attr [[,]]; // expected-error {{expected identifier}} +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}} -int & [[]] ref_attr = after_attr; // expected-error {{an attribute list cannot appear here}} class foo { - void after_const_attr () const [[]]; // expected-error {{expected body of lambda expression}} expected-error {{array has incomplete element type 'void'}} + void const_after_attr () [[]] const; // expected-error {{expected ';'}} }; extern "C++" [[]] { } // expected-error {{an attribute list cannot appear here}} [[]] template <typename T> void before_template_attr (); // expected-error {{an attribute list cannot appear here}} -[[]] namespace ns { int i; } // expected-error {{an attribute list cannot appear here}} +[[]] namespace ns { int i; } // expected-error {{an attribute list cannot appear here}} expected-note {{declared here}} [[]] static_assert(true, ""); //expected-error {{an attribute list cannot appear here}} [[]] asm(""); // expected-error {{an attribute list cannot appear here}} @@ -33,7 +42,7 @@ extern "C++" [[]] { } // expected-error {{an attribute list cannot appear here}} // Argument tests alignas int aligned_no_params; // expected-error {{expected '('}} -alignas(i) int aligned_nonconst; // expected-error {{'aligned' attribute requires integer constant}} +alignas(i) int aligned_nonconst; // expected-error {{'aligned' attribute requires integer constant}} expected-note {{read of non-const variable 'i'}} // Statement tests void foo () { @@ -58,6 +67,17 @@ void foo () { [[]] try { } [[]] catch (...) { // expected-error {{an attribute list cannot appear here}} } - + struct S { int arr[2]; } s; + (void)s.arr[ [] { return 0; }() ]; // expected-error {{C++11 only allows consecutive left square brackets when introducing an attribute}} + int n = __builtin_offsetof(S, arr[ [] { return 0; }() ]); // expected-error {{C++11 only allows consecutive left square brackets when introducing an attribute}} + + void bar [[noreturn]] ([[]] int i, [[]] int j); + using FuncType = void ([[]] int); + void baz([[]]...); // expected-error {{expected parameter declarator}} + [[]] return; } + +template<typename...Ts> void variadic() { + void bar [[noreturn...]] (); // expected-error {{attribute 'noreturn' cannot be used as an attribute pack}} +} diff --git a/test/Parser/cxx0x-condition.cpp b/test/Parser/cxx0x-condition.cpp new file mode 100644 index 0000000000000..e45cd866ff21d --- /dev/null +++ b/test/Parser/cxx0x-condition.cpp @@ -0,0 +1,37 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s + +struct S { S(int); operator bool(); }; + +void f() { + int a; + typedef int n; + + while (a) ; + while (int x) ; // expected-error {{variable declaration in condition must have an initializer}} + while (float x = 0) ; + if (const int x = a) ; // expected-warning{{empty body}} expected-note{{put the semicolon on a separate line to silence this warning}} + switch (int x = a+10) {} + for (; int x = ++a; ) ; + + if (S(a)) {} // ok + if (S(a) = 0) {} // ok + if (S(a) == 0) {} // ok + + if (S(n)) {} // expected-error {{unexpected type name 'n': expected expression}} + if (S(n) = 0) {} // ok + if (S(n) == 0) {} // expected-error {{unexpected type name 'n': expected expression}} + + if (S b(a)) {} // expected-error {{variable declaration in condition cannot have a parenthesized initializer}} + + if (S b(n)) {} // expected-error {{a function type is not allowed here}} expected-error {{must have an initializer}} + if (S b(n) = 0) {} // expected-error {{a function type is not allowed here}} + if (S b(n) == 0) {} // expected-error {{a function type is not allowed here}} expected-error {{did you mean '='?}} + + if (S{a}) {} // ok + if (S a{a}) {} // ok + if (S a = {a}) {} // ok + if (S a == {a}) {} // expected-error {{did you mean '='?}} + + if (S(b){a}) {} // ok + if (S(b) = {a}) {} // ok +} diff --git a/test/Parser/cxx0x-decl.cpp b/test/Parser/cxx0x-decl.cpp new file mode 100644 index 0000000000000..b9f5141a531ed --- /dev/null +++ b/test/Parser/cxx0x-decl.cpp @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -verify -fsyntax-only -std=c++0x %s + +// Make sure we know these are legitimate commas and not typos for ';'. +namespace Commas { + int a, + b [[ ]], + c alignas(double); +} + +struct S {}; +enum E { e }; + +auto f() -> struct S { + return S(); +} +auto g() -> enum E { + return E(); +} diff --git a/test/Parser/cxx0x-for-range.cpp b/test/Parser/cxx0x-for-range.cpp new file mode 100644 index 0000000000000..f920ef9085b16 --- /dev/null +++ b/test/Parser/cxx0x-for-range.cpp @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s + +template<typename T, typename U> +struct pair {}; + +template<typename T, typename U> +struct map { + typedef pair<T,U> *iterator; + iterator begin(); + iterator end(); +}; + +template<typename T, typename U> +pair<T,U> &tie(T &, U &); + +int foo(map<char*,int> &m) { + char *p; + int n; + + for (pair<char*,int> x : m) { + (void)x; + } + + for (tie(p, n) : m) { // expected-error {{for range declaration must declare a variable}} + (void)p; + (void)n; + } + + return n; +} diff --git a/test/Parser/cxx0x-in-cxx98.cpp b/test/Parser/cxx0x-in-cxx98.cpp index 9e41a700a982e..b4bda89d2781c 100644 --- a/test/Parser/cxx0x-in-cxx98.cpp +++ b/test/Parser/cxx0x-in-cxx98.cpp @@ -8,3 +8,16 @@ struct X { }; } +struct B { + virtual void f(); + virtual void g(); +}; +struct D final : B { // expected-warning {{'final' keyword is a C++11 extension}} + virtual void f() override; // expected-warning {{'override' keyword is a C++11 extension}} + virtual void g() final; // expected-warning {{'final' keyword is a C++11 extension}} +}; + +void NewBracedInitList() { + // A warning on this would be sufficient once we can handle it correctly. + new int {}; // expected-error {{}} +} diff --git a/test/Parser/cxx0x-lambda-expressions.cpp b/test/Parser/cxx0x-lambda-expressions.cpp index b4fe4cca7d116..9c7194142128e 100644 --- a/test/Parser/cxx0x-lambda-expressions.cpp +++ b/test/Parser/cxx0x-lambda-expressions.cpp @@ -1,4 +1,6 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s +// RUN: %clang_cc1 -fsyntax-only -Wno-unused-value -verify -std=c++11 %s + +enum E { e }; class C { @@ -10,18 +12,32 @@ class C { [foo+] {}; // expected-error {{expected ',' or ']' in lambda capture list}} [foo,&this] {}; // expected-error {{'this' cannot be captured by reference}} [&this] {}; // expected-error {{'this' cannot be captured by reference}} - [&,] {}; // expected-error {{ expected variable name or 'this' in lambda capture list}} - [=,] {}; // expected-error {{ expected variable name or 'this' in lambda capture list}} - [] {}; - [=] (int i) {}; - [&] (int) mutable -> void {}; - [foo,bar] () { return 3; }; - [=,&foo] () {}; - [&,foo] () {}; - [this] () {}; + [&,] {}; // expected-error {{expected variable name or 'this' in lambda capture list}} + [=,] {}; // expected-error {{expected variable name or 'this' in lambda capture list}} + [] {}; + [=] (int i) {}; + [&] (int) mutable -> void {}; + [foo,bar] () { return 3; }; + [=,&foo] () {}; + [&,foo] () {}; + [this] () {}; + [] () -> class C { return C(); }; + [] () -> enum E { return e; }; + [] -> int { return 0; }; // expected-error{{lambda requires '()' before return type}} + [] mutable -> int { return 0; }; // expected-error{{lambda requires '()' before 'mutable'}} return 1; } + void designator_or_lambda() { + typedef int T; + const int b = 0; + const int c = 1; + int a1[1] = {[b] (T()) {}}; // expected-error{{no viable conversion from 'C::<lambda}} + int a2[1] = {[b] = 1 }; + int a3[1] = {[b,c] = 1 }; // expected-error{{expected body of lambda expression}} + int a4[1] = {[&b] = 1 }; // expected-error{{integral constant expression must have integral or unscoped enumeration type, not 'const int *'}} + int a5[3] = { []{return 0;}() }; + int a6[1] = {[this] = 1 }; // expected-error{{integral constant expression must have integral or unscoped enumeration type, not 'C *'}} + } }; - diff --git a/test/Parser/cxx0x-literal-operators.cpp b/test/Parser/cxx0x-literal-operators.cpp index 4fcbad490d387..1881fcb7f0990 100644 --- a/test/Parser/cxx0x-literal-operators.cpp +++ b/test/Parser/cxx0x-literal-operators.cpp @@ -1,6 +1,8 @@ // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s void operator "" (const char *); // expected-error {{expected identifier}} -void operator "k" foo(const char *); // expected-error {{string literal after 'operator' must be '""'}} \ -// expected-warning{{user-defined literal with suffix 'foo' is preempted by C99 hexfloat extension}} -void operator "" tester (const char *); // expected-warning{{user-defined literal with suffix 'tester' is preempted by C99 hexfloat extension}} +void operator "k" foo(const char *); // \ + expected-error {{string literal after 'operator' must be '""'}} \ + expected-warning{{user-defined literal suffixes not starting with '_' are reserved}} +void operator "" tester (const char *); // \ + expected-warning{{user-defined literal suffixes not starting with '_' are reserved}} diff --git a/test/Parser/cxx11-type-specifier.cpp b/test/Parser/cxx11-type-specifier.cpp new file mode 100644 index 0000000000000..2e629f3ab5640 --- /dev/null +++ b/test/Parser/cxx11-type-specifier.cpp @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -verify %s -std=c++11 -fcxx-exceptions + +// Tests for parsing of type-specifier-seq + +struct S { + operator constexpr int(); // expected-error{{type name does not allow constexpr}} +}; +enum E { e }; + +void f() { + try { + (void) new constexpr int; // expected-error{{type name does not allow constexpr}} + } catch (constexpr int) { // expected-error{{type name does not allow constexpr}} + } + + // These parse as type definitions, not as type references with braced + // initializers. Sad but true... + (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}} +} diff --git a/test/Parser/cxx11-user-defined-literals.cpp b/test/Parser/cxx11-user-defined-literals.cpp new file mode 100644 index 0000000000000..49fea01eefe98 --- /dev/null +++ b/test/Parser/cxx11-user-defined-literals.cpp @@ -0,0 +1,112 @@ +// RUN: %clang_cc1 -std=c++11 -verify %s -fms-extensions -triple x86_64-apple-darwin9.0.0 + +// A ud-suffix cannot be used on string literals in a whole bunch of contexts: + +#include "foo"_bar // expected-error {{expected "FILENAME" or <FILENAME>}} +#line 1 "foo"_bar // expected-error {{user-defined suffix cannot be used here}} +# 1 "foo"_bar 1 // expected-error {{user-defined suffix cannot be used here}} +#ident "foo"_bar // expected-error {{user-defined suffix cannot be used here}} +_Pragma("foo"_bar) // expected-error {{user-defined suffix cannot be used here}} +#pragma comment(lib, "foo"_bar) // expected-error {{user-defined suffix cannot be used here}} +_Pragma("comment(lib, \"foo\"_bar)") // expected-error {{user-defined suffix cannot be used here}} +#pragma message "hi"_there // expected-error {{user-defined suffix cannot be used here}} expected-warning {{hi}} +#pragma push_macro("foo"_bar) // expected-error {{user-defined suffix cannot be used here}} +#if __has_warning("-Wan-island-to-discover"_bar) // expected-error {{user-defined suffix cannot be used here}} +#elif __has_include("foo"_bar) // expected-error {{expected "FILENAME" or <FILENAME>}} +#endif + +extern "C++"_x {} // expected-error {{user-defined suffix cannot be used here}} expected-error {{unknown linkage language}} + +int f() { + asm("mov %eax, %rdx"_foo); // expected-error {{user-defined suffix cannot be used here}} +} + +static_assert(true, "foo"_bar); // expected-error {{user-defined suffix cannot be used here}} + +int cake() __attribute__((availability(macosx, unavailable, message = "is a lie"_x))); // expected-error {{user-defined suffix cannot be used here}} + +// A ud-suffix cannot be used on character literals in preprocessor constant +// expressions: +#if 'x'_y - u'x'_z // expected-error 2{{character literal with user-defined suffix cannot be used in preprocessor constant expression}} +#error error +#endif + +// A ud-suffix cannot be used on integer literals in preprocessor constant +// expressions: +#if 0_foo // expected-error {{integer literal with user-defined suffix cannot be used in preprocessor constant expression}} +#error error +#endif + +// But they can appear in expressions. +constexpr char operator"" _id(char c) { return c; } +constexpr wchar_t operator"" _id(wchar_t c) { return c; } +constexpr char16_t operator"" _id(char16_t c) { return c; } +constexpr char32_t operator"" _id(char32_t c) { return c; } + +using size_t = decltype(sizeof(int)); +constexpr const char operator"" _id(const char *p, size_t n) { return *p; } +constexpr const wchar_t operator"" _id(const wchar_t *p, size_t n) { return *p; } +constexpr const char16_t operator"" _id(const char16_t *p, size_t n) { return *p; } +constexpr const char32_t operator"" _id(const char32_t *p, size_t n) { return *p; } + +constexpr unsigned long long operator"" _id(unsigned long long n) { return n; } +constexpr long double operator"" _id(long double d) { return d; } + +template<int n> struct S {}; +S<"a"_id> sa; +S<L"b"_id> sb; +S<u8"c"_id> sc; +S<u"d"_id> sd; +S<U"e"_id> se; + +S<'w'_id> sw; +S<L'x'_id> sx; +S<u'y'_id> sy; +S<U'z'_id> sz; + +S<100_id> sn; +S<(int)1.3_id> sf; + +void h() { + (void)"test"_id "test" L"test"; +} + +// Test source location for suffix is known +const char *p = + "foo\nbar" R"x( + erk + flux + )x" "eep\x1f"\ +_no_such_suffix // expected-error {{'operator "" _no_such_suffix'}} +"and a bit more" +"and another suffix"_no_such_suffix; + +char c = + '\x14'\ +_no_such_suffix; // expected-error {{'operator "" _no_such_suffix'}} + +int &r = +1234567\ +_no_such_suffix; // expected-error {{'operator "" _no_such_suffix'}} + +int k = +1234567.89\ +_no_such_suffix; // expected-error {{'operator "" _no_such_suffix'}} + +// Make sure we handle more interesting ways of writing a string literal which +// is "" in translation phase 7. +void operator "\ +" _foo(unsigned long long); // ok + +void operator R"xyzzy()xyzzy" _foo(long double); // ok + +void operator"" "" R"()" "" _foo(const char *); // ok + +// Ensure we diagnose the bad cases. +void operator "\0" _non_empty(const char *); // expected-error {{must be '""'}} +void operator ""_no_space(const char *); // expected-error {{C++11 requires a space}} +void operator L"" _not_char(const char *); // expected-error {{cannot have an encoding prefix}} +void operator "" "" +U"" // expected-error {{cannot have an encoding prefix}} +"" _also_not_char(const char *); +void operator "" u8"" "\u0123" "hello"_all_of_the_things ""(const char*); // expected-error {{must be '""'}} diff --git a/test/Parser/declarators.c b/test/Parser/declarators.c index e245adb7cded0..a7a01d8b4e838 100644 --- a/test/Parser/declarators.c +++ b/test/Parser/declarators.c @@ -97,3 +97,6 @@ void *test14b = (void*)test14a; // Make sure test14a didn't get skipped. // rdar://problem/8358508 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}} diff --git a/test/Parser/enhanced-proto-1.m b/test/Parser/enhanced-proto-1.m index a3819f3a19589..fa6e4138f1c1e 100644 --- a/test/Parser/enhanced-proto-1.m +++ b/test/Parser/enhanced-proto-1.m @@ -4,7 +4,7 @@ @optional - (void) FOO; @optional -- (void) FOO; +- (void) FOO1; @required - (void) REQ; @optional diff --git a/test/Parser/method-def-in-class.m b/test/Parser/method-def-in-class.m index 490c0559d1083..476ab9ba20e8b 100644 --- a/test/Parser/method-def-in-class.m +++ b/test/Parser/method-def-in-class.m @@ -7,19 +7,8 @@ } @end -@interface B --(id) f0 { // expected-error {{expected ';' after method prototype}} - assert(0); -@end - @interface C - (id) f0 { // expected-error {{expected ';' after method prototype}} assert(0); }; @end - -@interface D -- (id) f0 { // expected-error {{expected ';' after method prototype}} - assert(0); -@property int P; -@end diff --git a/test/Parser/missing-end-2.m b/test/Parser/missing-end-2.m index 63dc96558361b..e89f28eb247b2 100644 --- a/test/Parser/missing-end-2.m +++ b/test/Parser/missing-end-2.m @@ -1,19 +1,19 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s // rdar: //7824372 -@interface A +@interface A // expected-note {{class started here}} -(void) im0; -@implementation A // expected-error {{missing @end}} +@implementation A // expected-error {{missing '@end'}} @end -@interface B { +@interface B { // expected-note {{class started here}} } -@implementation B // expected-error {{missing @end}} +@implementation B // expected-error {{missing '@end'}} @end -@interface C +@interface C // expected-note 2 {{class started here}} @property int P; -@implementation C // expected-error 2 {{missing @end}} +@implementation C // expected-error 2 {{missing '@end'}} diff --git a/test/Parser/missing-end-3.m b/test/Parser/missing-end-3.m index 3b226376dc583..4875ecdd625b7 100644 --- a/test/Parser/missing-end-3.m +++ b/test/Parser/missing-end-3.m @@ -1,10 +1,10 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s // rdar://8283484 -@interface blah { +@interface blah { // expected-note {{class started here}} @private } // since I forgot the @end here it should say something -@interface blah // expected-error {{missing @end}} +@interface blah // expected-error {{missing '@end'}} @end // and Unknown type name 'end' here diff --git a/test/Parser/missing-end-4.m b/test/Parser/missing-end-4.m new file mode 100644 index 0000000000000..8a96e64421c13 --- /dev/null +++ b/test/Parser/missing-end-4.m @@ -0,0 +1,51 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s + +@interface X1 +@end +@implementation X1 // expected-note {{implementation started here}} +@interface Y1 // expected-error {{missing '@end'}} +@end +@end // expected-error {{'@end' must appear in an Objective-C context}} + +@interface X2 +@end +@implementation X2 // expected-note {{implementation started here}} +@protocol Y2 // expected-error {{missing '@end'}} +@end +@end // expected-error {{'@end' must appear in an Objective-C context}} + +@interface X6 // expected-note {{class started here}} +@interface X7 // expected-error {{missing '@end'}} +@end +@end // expected-error {{'@end' must appear in an Objective-C context}} + +@protocol P1 // expected-note {{protocol started here}} +@interface P2 // expected-error {{missing '@end'}} +@end +@end // expected-error {{'@end' must appear in an Objective-C context}} + +@interface X4 // expected-note {{class started here}} +@implementation X4 // expected-error {{missing '@end'}} +@end +@end // expected-error {{'@end' must appear in an Objective-C context}} + +@interface I +@end +@implementation I +@protocol P; // forward declarations of protocols in @implementations is allowed +@class C; // forward declarations of classes in @implementations is allowed +- (C<P>*) MyMeth {} +@end + +@interface I2 {} +@protocol P2; // expected-error {{illegal interface qualifier}} +@class C2; // expected-error {{illegal interface qualifier}} +@end + +@interface I3 +@end +@implementation I3 +- Meth {} ++ Cls {} +@protocol P3; +@end diff --git a/test/Parser/missing-end.m b/test/Parser/missing-end.m index fb264610aecb5..d66ea6487a456 100644 --- a/test/Parser/missing-end.m +++ b/test/Parser/missing-end.m @@ -1,7 +1,7 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -@interface AAA +@interface AAA // expected-note {{class started here}} { } @ x// expected-error{{expected an Objective-C directive after '@'}} -// expected-error{{missing @end}} +// expected-error{{missing '@end'}} diff --git a/test/Parser/objc-category-neg-1.m b/test/Parser/objc-category-neg-1.m index 5799db0bd2e7f..4aa8bae8302f5 100644 --- a/test/Parser/objc-category-neg-1.m +++ b/test/Parser/objc-category-neg-1.m @@ -3,6 +3,6 @@ void __assert_rtn(const char *, const char *, int, const char *) __attribute__((__noreturn__)); static __inline__ int __inline_isfinitef (float ) __attribute__ ((always_inline)); -@interface NSATSTypesetter (NSPantherCompatibility) // expected-error {{ "cannot find interface declaration for 'NSATSTypesetter'" }} +@interface NSATSTypesetter (NSPantherCompatibility) // expected-error {{cannot find interface declaration for 'NSATSTypesetter'}} - (id)lineFragmentRectForProposedRect:(id)proposedRect remainingRect:(id)remainingRect __attribute__((deprecated)); @end diff --git a/test/Parser/objc-forcollection-neg-2.m b/test/Parser/objc-forcollection-neg-2.m index 6aa74c9c0b45d..f95dd1356bc3e 100644 --- a/test/Parser/objc-forcollection-neg-2.m +++ b/test/Parser/objc-forcollection-neg-2.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s typedef struct objc_class *Class; struct __objcFastEnumerationState; @@ -30,7 +30,7 @@ typedef struct objc_object { for (id el in self) ++i; MyList<P> ***p; - for (p in self) // expected-error {{selector element type 'MyList<P> ***' is not a valid object type}} + for (p in self) // expected-error {{selector element type 'MyList<P> ***' is not a valid object}} ++i; } diff --git a/test/Parser/objc-forcollection-neg.m b/test/Parser/objc-forcollection-neg.m index d896c35f3f69a..1a989a14464c7 100644 --- a/test/Parser/objc-forcollection-neg.m +++ b/test/Parser/objc-forcollection-neg.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s struct __objcFastEnumerationState; typedef struct objc_class *Class; diff --git a/test/Parser/objc-foreach-syntax.m b/test/Parser/objc-foreach-syntax.m index cc82725b17d76..5d83dc69fcd9c 100644 --- a/test/Parser/objc-foreach-syntax.m +++ b/test/Parser/objc-foreach-syntax.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s struct __objcFastEnumerationState; @implementation MyList // expected-warning {{cannot find interface declaration for 'MyList'}} diff --git a/test/Parser/objc-init.m b/test/Parser/objc-init.m index 074820526c939..efa1266e7b8e1 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 %s -pedantic -// RUN: %clang_cc1 -fsyntax-only -fobjc-fragile-abi -verify -x objective-c++ %s +// 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 // rdar://5707001 @interface NSNumber; @@ -15,7 +15,7 @@ void test1() { id objects[] = {[NSNumber METH]}; } -void test2(NSNumber x) { // expected-error {{Objective-C interface type 'NSNumber' cannot be passed by value; did you forget * in 'NSNumber'}} +void test2(NSNumber x) { // expected-error {{interface type 'NSNumber' cannot be passed by value; did you forget * in 'NSNumber'}} id objects[] = {[x METH]}; } diff --git a/test/Parser/objc-missing-impl.m b/test/Parser/objc-missing-impl.m index e9c37ab1b1587..791b9f800909b 100644 --- a/test/Parser/objc-missing-impl.m +++ b/test/Parser/objc-missing-impl.m @@ -1,2 +1,2 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -@end // expected-error {{@end must appear in an @implementation context}} +@end // expected-error {{'@end' must appear in an Objective-C context}} diff --git a/test/Parser/objc-property-syntax.m b/test/Parser/objc-property-syntax.m index 6ef2ad7c527d9..38d12d5905c33 100644 --- a/test/Parser/objc-property-syntax.m +++ b/test/Parser/objc-property-syntax.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @interface MyClass { int prop; diff --git a/test/Parser/objc-quirks.m b/test/Parser/objc-quirks.m index 591bca222a934..0bdeb464e7716 100644 --- a/test/Parser/objc-quirks.m +++ b/test/Parser/objc-quirks.m @@ -5,9 +5,9 @@ int @"s" = 5; // expected-error {{prefix attribute must be}} // rdar://6480479 -@interface A -}; // expected-error {{missing @end}} \ -// expected-error {{expected external declaration}} \ +@interface A // expected-note {{class started here}} +}; // expected-error {{missing '@end'}} \ +// expected-error {{extraneous closing brace ('}')}} \ // expected-warning{{extra ';' outside of a function}} diff --git a/test/Parser/objc-synthesized-recover.m b/test/Parser/objc-synthesized-recover.m index 3f04a8c21d392..c281c21000d02 100644 --- a/test/Parser/objc-synthesized-recover.m +++ b/test/Parser/objc-synthesized-recover.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @interface I1 { diff --git a/test/Parser/objcxx-lambda-expressions-neg.mm b/test/Parser/objcxx-lambda-expressions-neg.mm index 864cc6b8fbf56..7cdb1a292e409 100644 --- a/test/Parser/objcxx-lambda-expressions-neg.mm +++ b/test/Parser/objcxx-lambda-expressions-neg.mm @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -Wno-unused-value -verify %s int main() { []{}; // expected-error {{expected expression}} diff --git a/test/Parser/objcxx0x-lambda-expressions.mm b/test/Parser/objcxx0x-lambda-expressions.mm index 937464918b6ae..1eab15bee98e1 100644 --- a/test/Parser/objcxx0x-lambda-expressions.mm +++ b/test/Parser/objcxx0x-lambda-expressions.mm @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-unused-value -std=c++11 %s class C { @@ -11,15 +11,12 @@ class C { []; // expected-error {{expected body of lambda expression}} [=,foo+] {}; // expected-error {{expected ',' or ']' in lambda capture list}} [&this] {}; // expected-error {{address expression must be an lvalue}} - [] {}; - [=] (int i) {}; - [&] (int) mutable -> void {}; - // FIXME: this error occurs because we do not yet handle lambda scopes - // properly. I did not anticipate it because I thought it was a semantic (not - // syntactic) check. - [foo,bar] () { return 3; }; // expected-error {{void function 'f' should not return a value}} - [=,&foo] () {}; - [this] () {}; + [] {}; + [=] (int i) {}; + [&] (int) mutable -> void {}; + [foo,bar] () { return 3; }; + [=,&foo] () {}; + [this] () {}; } }; diff --git a/test/Parser/objcxx11-attributes.mm b/test/Parser/objcxx11-attributes.mm new file mode 100644 index 0000000000000..0875b66e2132e --- /dev/null +++ b/test/Parser/objcxx11-attributes.mm @@ -0,0 +1,55 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s + +@interface X {} ++ (X*) alloc; +- (X*) init; +- (int) getSize; +- (void) setSize: (int) size; +- (X*) getSelf; +@end + +void f(X *noreturn) { + // An array size which is computed by a message send is OK. + int a[ [noreturn getSize] ]; + + // ... but is interpreted as an attribute where possible. + int b[ [noreturn] ]; // expected-warning {{'noreturn' only applies to function types}} + + int c[ [noreturn getSize] + 1 ]; + + // An array size which is computed by a lambda is not OK. + int d[ [noreturn] { return 3; } () ]; // expected-error {{expected ']'}} expected-warning {{'noreturn' only applies}} + + // A message send which contains a message send is OK. + [ [ X alloc ] init ]; + [ [ int(), noreturn getSelf ] getSize ]; // expected-warning {{unused}} + + // A message send which contains a lambda is OK. + [ [noreturn] { return noreturn; } () setSize: 4 ]; + [ [bitand] { return noreturn; } () setSize: 5 ]; + [[[[] { return [ X alloc ]; } () init] getSelf] getSize]; + + // An attribute is OK. + [[]]; + [[int(), noreturn]]; + [[class, test(foo 'x' bar),,,]]; + [[bitand, noreturn]]; + + [[noreturn]]int(e)(); + + // A function taking a noreturn function. + int(f)([[noreturn]] int()); + f(e); + + // Variables initialized by a message send. + int(g)([[noreturn getSelf] getSize]); + int(h)([[noreturn]{return noreturn;}() getSize]); + + int i = g + h; +} + +template<typename...Ts> void f(Ts ...x) { + [[test::foo(bar, baz)...]]; + [[used(x)...]]; + [[x...] { return [ X alloc ]; }() init]; +} diff --git a/test/Parser/objcxx11-user-defined-literal.mm b/test/Parser/objcxx11-user-defined-literal.mm new file mode 100644 index 0000000000000..a5f1397530fd2 --- /dev/null +++ b/test/Parser/objcxx11-user-defined-literal.mm @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s + +id x = @"foo"_bar; // expected-error{{user-defined suffix cannot be used here}} diff --git a/test/Parser/recovery.c b/test/Parser/recovery.c index 0747aecd6c049..3916acfda1e01 100644 --- a/test/Parser/recovery.c +++ b/test/Parser/recovery.c @@ -16,7 +16,7 @@ static void f (char * (*g) (char **, int), char **p, ...) { // PR3172 -} // expected-error {{expected external declaration}} +} // expected-error {{extraneous closing brace ('}')}} // rdar://6094870 @@ -49,7 +49,7 @@ void test(int a) { char (((( /* expected-note {{to match this '('}} */ *X x ] )))); /* expected-error {{expected ')'}} */ -; // expected-warning {{ISO C does not allow an extra ';' outside of a function}} +; // expected-warning {{extra ';' outside of a function}} diff --git a/test/Parser/recovery.cpp b/test/Parser/recovery.cpp new file mode 100644 index 0000000000000..ffa1bab55a44e --- /dev/null +++ b/test/Parser/recovery.cpp @@ -0,0 +1,42 @@ +// RUN: %clang -cc1 -verify -std=c++11 %s + +8gi///===--- recovery.cpp ---===// // expected-error {{unqualified-id}} +namespace Std { // expected-note {{here}} + typedef int Important; +} + +/ redeclare as an inline namespace // expected-error {{unqualified-id}} +inline namespace Std { // expected-error {{cannot be reopened as inline}} + Important n; +} / end namespace Std // expected-error {{unqualified-id}} +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}} + void f(); +} +void g() { + z = 1; // expected-error {{undeclared}} + f(); // expected-error {{undeclared}} +} + +struct S { + int a, b, c; + S(); +}; +8S::S() : a{ 5 }, b{ 6 }, c{ 2 } { // expected-error {{unqualified-id}} + return; +} +int k; +int l = k; + +5int m = { l }, n = m; // expected-error {{unqualified-id}} + +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 ';'}} diff --git a/test/Parser/skip-function-bodies.mm b/test/Parser/skip-function-bodies.mm new file mode 100644 index 0000000000000..8462f69f3ab74 --- /dev/null +++ b/test/Parser/skip-function-bodies.mm @@ -0,0 +1,45 @@ +// RUN: env CINDEXTEST_SKIP_FUNCTION_BODIES=1 c-index-test -test-load-source all %s | FileCheck %s + +class A { + class B {}; + +public: + A() { + struct C { + void d() {} + }; + } + + typedef B E; +}; + +@interface F +- (void) G; +@end +@implementation F +- (void) G { + typedef A H; + class I {}; +} +@end + +void J() { + class K {}; +} + +// CHECK: skip-function-bodies.mm:3:7: ClassDecl=A:3:7 (Definition) Extent=[3:1 - 14:2] +// CHECK: skip-function-bodies.mm:4:9: ClassDecl=B:4:9 (Definition) Extent=[4:3 - 4:13] +// CHECK: skip-function-bodies.mm:6:1: CXXAccessSpecifier=:6:1 (Definition) Extent=[6:1 - 6:8] +// CHECK: skip-function-bodies.mm:7:3: CXXConstructor=A:7:3 Extent=[7:3 - 7:6] +// CHECK-NOT: skip-function-bodies.mm:8:12: StructDecl=C:8:12 (Definition) Extent=[8:5 - 10:6] +// CHECK-NOT: skip-function-bodies.mm:9:12: CXXMethod=d:9:12 (Definition) Extent=[9:7 - 9:18] +// CHECK: skip-function-bodies.mm:13:13: TypedefDecl=E:13:13 (Definition) Extent=[13:3 - 13:14] +// CHECK: skip-function-bodies.mm:13:11: TypeRef=class A::B:4:9 Extent=[13:11 - 13:12] +// CHECK: skip-function-bodies.mm:16:12: ObjCInterfaceDecl=F:16:12 Extent=[16:1 - 18:5] +// CHECK: skip-function-bodies.mm:17:10: ObjCInstanceMethodDecl=G:17:10 Extent=[17:1 - 17:12] +// CHECK: skip-function-bodies.mm:19:17: ObjCImplementationDecl=F:19:17 (Definition) Extent=[19:1 - 24:2] +// CHECK: skip-function-bodies.mm:20:10: ObjCInstanceMethodDecl=G:20:10 Extent=[20:1 - 20:13] +// CHECK-NOT: skip-function-bodies.mm:21:13: TypedefDecl=H:21:13 (Definition) Extent=[21:3 - 21:14] +// CHECK-NOT: skip-function-bodies.mm:21:11: TypeRef=class A:3:7 Extent=[21:11 - 21:12] +// CHECK: skip-function-bodies.mm:26:6: FunctionDecl=J:26:6 Extent=[26:1 - 26:9] +// CHECK-NOT: skip-function-bodies.mm:27:9: ClassDecl=K:27:9 (Definition) Extent=[27:3 - 27:13] diff --git a/test/Parser/statements.c b/test/Parser/statements.c index bc7192a7b2b32..3a123d6001bde 100644 --- a/test/Parser/statements.c +++ b/test/Parser/statements.c @@ -31,20 +31,20 @@ void test3() { } void test4() { - if (0); // expected-warning {{if statement has empty body}} + if (0); // expected-warning {{if statement has empty body}} expected-note {{put the semicolon on a separate line to silence this warning}} int X; // declaration in a block. -foo: if (0); // expected-warning {{if statement has empty body}} +foo: if (0); // expected-warning {{if statement has empty body}} expected-note {{put the semicolon on a separate line to silence this warning}} } typedef int t; void test5() { - if (0); // expected-warning {{if statement has empty body}} + if (0); // expected-warning {{if statement has empty body}} expected-note {{put the semicolon on a separate line to silence this warning}} t x = 0; - if (0); // expected-warning {{if statement has empty body}} + if (0); // expected-warning {{if statement has empty body}} expected-note {{put the semicolon on a separate line to silence this warning}} } diff --git a/test/Parser/warn-dangling-else.cpp b/test/Parser/warn-dangling-else.cpp new file mode 100644 index 0000000000000..e91af9814ff97 --- /dev/null +++ b/test/Parser/warn-dangling-else.cpp @@ -0,0 +1,55 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Wdangling-else %s + +void f(int a, int b, int c, int d, int e) { + + // should warn + { if (a) if (b) d++; else e++; } // expected-warning {{add explicit braces to avoid dangling else}} + { if (a) while (b) if (c) d++; else e++; } // expected-warning {{add explicit braces to avoid dangling else}} + { if (a) switch (b) if (c) d++; else e++; } // expected-warning {{add explicit braces to avoid dangling else}} + { if (a) for (;;) if (c) d++; else e++; } // expected-warning {{add explicit braces to avoid dangling else}} + { if (a) if (b) if (d) d++; else e++; else d--; } // expected-warning {{add explicit braces to avoid dangling else}} + + if (a) + if (b) { + d++; + } else e++; // expected-warning {{add explicit braces to avoid dangling else}} + + // shouldn't + { if (a) if (b) d++; } + { if (a) if (b) if (c) d++; } + { if (a) if (b) d++; else e++; else d--; } + { if (a) if (b) if (d) d++; else e++; else d--; else e--; } + { if (a) do if (b) d++; else e++; while (c); } + + if (a) { + if (b) d++; + else e++; + } + + if (a) { + if (b) d++; + } else e++; +} + +// Somewhat more elaborate case that shouldn't warn. +class A { + public: + void operator<<(const char* s) {} +}; + +void HandleDisabledThing() {} +A GetThing() { return A(); } + +#define FOO(X) \ + switch (0) default: \ + if (!(X)) \ + HandleDisabledThing(); \ + else \ + GetThing() + +void f(bool cond) { + int x = 0; + if (cond) + FOO(x) << "hello"; // no warning +} + |