diff options
Diffstat (limited to 'test/Parser')
35 files changed, 478 insertions, 60 deletions
diff --git a/test/Parser/MicrosoftExtensions.c b/test/Parser/MicrosoftExtensions.c index e58a7455c083f..39ab51f31fa67 100644 --- a/test/Parser/MicrosoftExtensions.c +++ b/test/Parser/MicrosoftExtensions.c @@ -35,6 +35,9 @@ void test_ms_alignof_alias(void) { /* Charify extension. */ #define FOO(x) #@x char x = FOO(a); +#define HASHAT #@ +#define MISSING_ARG(x) #@ +/* expected-error@-1 {{'#@' is not followed by a macro parameter}} */ typedef enum E { e1 }; diff --git a/test/Parser/cxx-altivec.cpp b/test/Parser/cxx-altivec.cpp index ac20de288f172..5b0da6c5e6fd9 100644 --- a/test/Parser/cxx-altivec.cpp +++ b/test/Parser/cxx-altivec.cpp @@ -1,6 +1,7 @@ // RUN: %clang_cc1 -triple=powerpc-apple-darwin8 -faltivec -fsyntax-only -verify -std=c++11 %s // RUN: %clang_cc1 -triple=powerpc64-unknown-linux-gnu -faltivec -fsyntax-only -verify -std=c++11 %s // RUN: %clang_cc1 -triple=powerpc64le-unknown-linux-gnu -faltivec -fsyntax-only -verify -std=c++11 %s +#include <altivec.h> __vector char vv_c; __vector signed char vv_sc; diff --git a/test/Parser/cxx-ambig-paren-expr-asan.cpp b/test/Parser/cxx-ambig-paren-expr-asan.cpp new file mode 100644 index 0000000000000..ec9d6b9da39d0 --- /dev/null +++ b/test/Parser/cxx-ambig-paren-expr-asan.cpp @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s + +// This syntax error used to cause use-after free due to token local buffer +// in ParseCXXAmbiguousParenExpression. +int H((int()[)]); +// expected-error@-1 {{expected expression}} +// expected-error@-2 {{expected ']'}} +// expected-note@-3 {{to match this '['}} +// expected-error@-4 {{expected ';' after top level declarator}} diff --git a/test/Parser/cxx-ambig-paren-expr.cpp b/test/Parser/cxx-ambig-paren-expr.cpp index 398820567237d..cc509f7b059f3 100644 --- a/test/Parser/cxx-ambig-paren-expr.cpp +++ b/test/Parser/cxx-ambig-paren-expr.cpp @@ -21,8 +21,14 @@ void f() { struct S{int operator()();}; (S())(); - // FIXME: Special case: "++" is postfix here, not prefix - // (S())++; + // Special case: "++" is postfix here, not prefix + (S())++; // expected-error {{cannot increment value of type 'S'}} + + struct X { int &operator++(int); X operator[](int); int &operator++(); }; + int &postfix_incr = (X()[3])++; + (X())++ ++; // ok, not a C-style cast + (X())++ ++X(); // expected-error {{C-style cast from 'int' to 'X ()'}} + int q = (int)++(x); } // Make sure we do tentative parsing correctly in conditions. diff --git a/test/Parser/cxx-casting.cpp b/test/Parser/cxx-casting.cpp index 43885bff27a5f..b1ae591865eb1 100644 --- a/test/Parser/cxx-casting.cpp +++ b/test/Parser/cxx-casting.cpp @@ -37,7 +37,7 @@ char postfix_expr_test() // This was being incorrectly tentatively parsed. namespace test1 { template <class T> class A {}; // expected-note 2{{here}} - void foo() { A<int>(*(A<int>*)0); } + void foo() { A<int>(*(A<int>*)0); } // expected-warning {{binding dereferenced null pointer to reference has undefined behavior}} } typedef char* c; diff --git a/test/Parser/cxx-class.cpp b/test/Parser/cxx-class.cpp index 9e907f1b1c12f..3cc006af23dc0 100644 --- a/test/Parser/cxx-class.cpp +++ b/test/Parser/cxx-class.cpp @@ -1,4 +1,7 @@ // RUN: %clang_cc1 -fsyntax-only -verify -pedantic -fcxx-exceptions %s +// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -fcxx-exceptions -std=c++98 %s +// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -fcxx-exceptions -std=c++11 %s + class C; class C { public: @@ -69,11 +72,30 @@ public; // expected-error{{expected ':'}} }; class F { - int F1 { return 1; } // expected-error{{function definition does not declare parameters}} - void F2 {} // expected-error{{function definition does not declare parameters}} + int F1 { return 1; } +#if __cplusplus <= 199711L + // expected-error@-2 {{function definition does not declare parameters}} +#else + // expected-error@-4 {{expected expression}} + // expected-error@-5 {{expected}} + // expected-note@-6 {{to match this '{'}} + // expected-error@-7 {{expected ';' after class}} +#endif + + void F2 {} +#if __cplusplus <= 199711L + // expected-error@-2 {{function definition does not declare parameters}} +#else + // expected-error@-4 {{variable has incomplete type 'void'}} + // expected-error@-5 {{expected ';' after top level declarator}} +#endif + typedef int F3() { return 0; } // expected-error{{function definition declared 'typedef'}} typedef void F4() {} // expected-error{{function definition declared 'typedef'}} }; +#if __cplusplus >= 201103L +// expected-error@-2 {{extraneous closing brace}} +#endif namespace ctor_error { class Foo {}; @@ -203,14 +225,38 @@ namespace BadFriend { } class PR20760_a { - int a = ); // expected-warning {{extension}} expected-error {{expected expression}} - int b = }; // expected-warning {{extension}} expected-error {{expected expression}} - int c = ]; // expected-warning {{extension}} expected-error {{expected expression}} + int a = ); // expected-error {{expected expression}} +#if __cplusplus <= 199711L + // expected-warning@-2 {{in-class initialization of non-static data member is a C++11 extension}} +#endif + + int b = }; // expected-error {{expected expression}} +#if __cplusplus <= 199711L + // expected-warning@-2 {{in-class initialization of non-static data member is a C++11 extension}} +#endif + + int c = ]; // expected-error {{expected expression}} +#if __cplusplus <= 199711L + // expected-warning@-2 {{in-class initialization of non-static data member is a C++11 extension}} +#endif + }; class PR20760_b { - int d = d); // expected-warning {{extension}} expected-error {{expected ';'}} - int e = d]; // expected-warning {{extension}} expected-error {{expected ';'}} - int f = d // expected-warning {{extension}} expected-error {{expected ';'}} + int d = d); // expected-error {{expected ';'}} +#if __cplusplus <= 199711L + // expected-warning@-2 {{in-class initialization of non-static data member is a C++11 extension}} +#endif + + int e = d]; // expected-error {{expected ';'}} +#if __cplusplus <= 199711L + // expected-warning@-2 {{in-class initialization of non-static data member is a C++11 extension}} +#endif + + int f = d // expected-error {{expected ';'}} +#if __cplusplus <= 199711L + // expected-warning@-2 {{in-class initialization of non-static data member is a C++11 extension}} +#endif + }; namespace PR20887 { diff --git a/test/Parser/cxx-decl.cpp b/test/Parser/cxx-decl.cpp index be79eb433fd03..8a7a388605392 100644 --- a/test/Parser/cxx-decl.cpp +++ b/test/Parser/cxx-decl.cpp @@ -1,4 +1,6 @@ // RUN: %clang_cc1 -verify -fsyntax-only -triple i386-linux -pedantic-errors -fcxx-exceptions -fexceptions %s +// RUN: %clang_cc1 -verify -fsyntax-only -triple i386-linux -pedantic-errors -fcxx-exceptions -fexceptions -std=c++98 %s +// RUN: %clang_cc1 -verify -fsyntax-only -triple i386-linux -pedantic-errors -fcxx-exceptions -fexceptions -std=c++11 %s const char const *x10; // expected-error {{duplicate 'const' declaration specifier}} @@ -46,7 +48,10 @@ class asm_class_test { void foo() __asm__("baz"); }; -enum { fooenum = 1, }; // expected-error {{commas at the end of enumerator lists are a C++11 extension}} +enum { fooenum = 1, }; +#if __cplusplus <= 199711L +// expected-error@-2 {{commas at the end of enumerator lists are a C++11 extension}} +#endif struct a { int Type : fooenum; @@ -81,7 +86,11 @@ namespace Commas { (global5), *global6, &global7 = global1, - &&global8 = static_cast<int&&>(global1), // expected-error 2{{rvalue reference}} + &&global8 = static_cast<int&&>(global1), +#if __cplusplus <= 199711L + // expected-error@-2 2{{rvalue references are a C++11 extension}} +#endif + S::a, global9, global10 = 0, @@ -185,7 +194,13 @@ namespace PR15017 { } // Ensure we produce at least some diagnostic for attributes in C++98. -[[]] struct S; // expected-error 2{{}} +[[]] struct S; +#if __cplusplus <= 199711L +// expected-error@-2 {{expected expression}} +// expected-error@-3 {{expected unqualified-id}} +#else +// expected-error@-5 {{an attribute list cannot appear here}} +#endif namespace test7 { struct Foo { @@ -212,14 +227,20 @@ namespace PR5066 { template<typename T> struct X {}; X<int N> x; // expected-error {{type-id cannot have a name}} - using T = int (*T)(); // expected-error {{type-id cannot have a name}} expected-error {{C++11}} + using T = int (*T)(); // expected-error {{type-id cannot have a name}} +#if __cplusplus <= 199711L + // expected-error@-2 {{alias declarations are a C++11 extensio}} +#endif + } namespace PR17255 { void foo() { - typename A::template B<>; // expected-error {{use of undeclared identifier 'A'}} \ - // expected-error {{expected a qualified name after 'typename'}} \ - // expected-error {{'template' keyword outside of a template}} + typename A::template B<>; // expected-error {{use of undeclared identifier 'A'}} +#if __cplusplus <= 199711L + // expected-error@-2 {{'template' keyword outside of a template}} +#endif + // expected-error@-4 {{expected a qualified name after 'typename'}} } } @@ -236,12 +257,25 @@ namespace DuplicateFriend { struct A { friend void friend f(); // expected-warning {{duplicate 'friend' declaration specifier}} friend struct B friend; // expected-warning {{duplicate 'friend' declaration specifier}} +#if __cplusplus >= 201103L + // expected-error@-2 {{'friend' must appear first in a non-function declaration}} +#endif }; } // PR8380 extern "" // expected-error {{unknown linkage language}} -test6a { ;// expected-error {{C++ requires a type specifier for all declarations}} \ - // expected-error {{expected ';' after top level declarator}} +test6a { ;// expected-error {{C++ requires a type specifier for all declarations}} +#if __cplusplus <= 199711L +// expected-error@-2 {{expected ';' after top level declarator}} +#else +// expected-error@-4 {{expected expression}} +// expected-note@-5 {{to match this}} +#endif int test6b; +#if __cplusplus >= 201103L +// expected-error@+3 {{expected}} +// expected-error@-3 {{expected ';' after top level declarator}} +#endif + diff --git a/test/Parser/cxx-friend.cpp b/test/Parser/cxx-friend.cpp index ace0ff26e2d9a..a4492ba1a7ab9 100644 --- a/test/Parser/cxx-friend.cpp +++ b/test/Parser/cxx-friend.cpp @@ -1,4 +1,6 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s class C { friend class D; @@ -21,9 +23,20 @@ class B { // 'A' here should refer to the declaration above. friend class A; - friend C; // expected-warning {{specify 'class' to befriend}} - friend U; // expected-warning {{specify 'union' to befriend}} - friend int; // expected-warning {{non-class friend type 'int'}} + friend C; +#if __cplusplus <= 199711L + // expected-warning@-2 {{unelaborated friend declaration is a C++11 extension; specify 'class' to befriend 'C'}} +#endif + + friend U; +#if __cplusplus <= 199711L + // expected-warning@-2 {{unelaborated friend declaration is a C++11 extension; specify 'union' to befriend 'U'}} +#endif + + friend int; +#if __cplusplus <= 199711L + // expected-warning@-2 {{non-class friend type 'int' is a C++11 extension}} +#endif friend void myfunc(); diff --git a/test/Parser/cxx-invalid-for-range.cpp b/test/Parser/cxx-invalid-for-range.cpp new file mode 100644 index 0000000000000..557c1da209a9a --- /dev/null +++ b/test/Parser/cxx-invalid-for-range.cpp @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s + +// From PR23057 comment #18 (https://llvm.org/bugs/show_bug.cgi?id=23057#c18). + +namespace N { + int X[10]; // expected-note{{declared here}}}} +} + +void f1() { + for (auto operator new : X); // expected-error{{'operator new' cannot be the name of a variable or data member}} + // expected-error@-1{{use of undeclared identifier 'X'; did you mean 'N::X'?}} +} + +void f2() { + for (a operator== :) // expected-error{{'operator==' cannot be the name of a variable or data member}} + // expected-error@-1{{expected expression}} + // expected-error@-2{{unknown type name 'a'}} +} // expected-error{{expected statement}} diff --git a/test/Parser/cxx-invalid-function-decl.cpp b/test/Parser/cxx-invalid-function-decl.cpp new file mode 100644 index 0000000000000..2db27516eefab --- /dev/null +++ b/test/Parser/cxx-invalid-function-decl.cpp @@ -0,0 +1,42 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// Check that "::new" and "::delete" in member initializer list are diagnosed +// correctly and don't lead to infinite loop on parsing. + +// Error: X() (initializer on non-constructor), "::new" is skipped. +void f1() : X() ::new{}; // expected-error{{only constructors take base initializers}} + +// Errors: first "::delete" and initializer on non-constructor, others skipped. +void f2() : ::delete, ::new, X() ::new ::delete{} // expected-error{{expected class member or base class name}} + // expected-error@-1{{only constructors take base initializers}} + +// Errors: the '::' token, "::delete" and initializer on non-constructor, others skipped. +void f3() : ::, ::delete X(), ::new {}; // expected-error2{{expected class member or base class name}} + // expected-error@-1{{only constructors take base initializers}} + +template <class T> +struct Base1 { + T x1; + Base1(T a1) : x1(a1) {} +}; + +template <class T> +struct Base2 { + T x2; + Base2(T a2) : x2(a2) {} +}; + +struct S : public Base1<int>, public Base2<float> { + int x; + + // 1-st initializer is correct (just missing ','), 2-nd incorrect, skip other. + S() : ::Base1<int>(0) ::new, ::Base2<float>(1.0) ::delete x(2) {} // expected-error{{expected class member or base class name}} + // expected-error@-1{{missing ',' between base or member initializers}} + + // 1-st and 2-nd are correct, errors: '::' and "::new", others skipped. + S(int a) : Base1<int>(a), ::Base2<float>(1.0), ::, // expected-error{{expected class member or base class name}} + ::new, ! ::delete, ::Base2<() x(3) {} // expected-error{{expected class member or base class name}} + + // All initializers are correct, nothing to skip, diagnose 2 missing commas. + S(const S &) : Base1<int>(0) ::Base2<float>(1.0) x(2) {} // expected-error2{{missing ',' between base or member initializers}} +}; diff --git a/test/Parser/cxx0x-attributes.cpp b/test/Parser/cxx0x-attributes.cpp index 7eec5761ea055..906d72b087cb5 100644 --- a/test/Parser/cxx0x-attributes.cpp +++ b/test/Parser/cxx0x-attributes.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++11 -Wc++14-compat %s +// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++11 -Wc++14-compat -Wc++14-extensions -Wc++1z-extensions %s // Need std::initializer_list namespace std { @@ -336,7 +336,6 @@ namespace { // expected-warning@-1 {{use of the 'deprecated' attribute is a C++14 extension}} [[deprecated()]] void foo(); // expected-error@-1 {{parentheses must be omitted if 'deprecated' attribute's argument list is empty}} - // expected-warning@-2 {{use of the 'deprecated' attribute is a C++14 extension}} [[gnu::deprecated()]] void quux(); } @@ -347,6 +346,18 @@ deprecated ]] void bad(); } +int fallthru(int n) { + switch (n) { + case 0: + n += 5; + [[fallthrough]]; // expected-warning {{use of the 'fallthrough' attribute is a C++1z extension}} + case 1: + n *= 2; + break; + } + return n; +} + #define attr_name bitand #define attr_name_2(x) x #define attr_name_3(x, y) x##y diff --git a/test/Parser/cxx0x-condition.cpp b/test/Parser/cxx0x-condition.cpp index 8b64bcf1273d5..071e09e4158f0 100644 --- a/test/Parser/cxx0x-condition.cpp +++ b/test/Parser/cxx0x-condition.cpp @@ -23,9 +23,9 @@ void f() { 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)) {} // expected-error {{a function type is not allowed here}} 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 b(n) == 0) {} // expected-error {{a function type is not allowed here}} S s(a); if (S{s}) {} // ok diff --git a/test/Parser/cxx0x-decl.cpp b/test/Parser/cxx0x-decl.cpp index 23f46a1847888..c4f03566029ad 100644 --- a/test/Parser/cxx0x-decl.cpp +++ b/test/Parser/cxx0x-decl.cpp @@ -17,6 +17,8 @@ auto g() -> enum E { return E(); } +int decltype(f())::*ptr_mem_decltype; + 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. diff --git a/test/Parser/cxx1z-constexpr-lambdas.cpp b/test/Parser/cxx1z-constexpr-lambdas.cpp new file mode 100644 index 0000000000000..ea000e361ccb6 --- /dev/null +++ b/test/Parser/cxx1z-constexpr-lambdas.cpp @@ -0,0 +1,31 @@ +// RUN: %clang_cc1 -std=c++1z %s -verify +// RUN: %clang_cc1 -std=c++14 %s -verify +// RUN: %clang_cc1 -std=c++11 %s -verify + + +auto XL0 = [] constexpr { }; //expected-error{{requires '()'}} expected-error{{expected body}} +auto XL1 = [] () mutable + mutable //expected-error{{cannot appear multiple times}} + mutable { }; //expected-error{{cannot appear multiple times}} + +#if __cplusplus > 201402L +auto XL2 = [] () constexpr mutable constexpr { }; //expected-error{{cannot appear multiple times}} +auto L = []() mutable constexpr { }; +auto L2 = []() constexpr { }; +auto L4 = []() constexpr mutable { }; +auto XL16 = [] () constexpr + mutable + constexpr //expected-error{{cannot appear multiple times}} + mutable //expected-error{{cannot appear multiple times}} + mutable //expected-error{{cannot appear multiple times}} + constexpr //expected-error{{cannot appear multiple times}} + constexpr //expected-error{{cannot appear multiple times}} + { }; + +#else +auto L = []() mutable constexpr {return 0; }; //expected-warning{{is a C++1z extension}} +auto L2 = []() constexpr { return 0;};//expected-warning{{is a C++1z extension}} +auto L4 = []() constexpr mutable { return 0; }; //expected-warning{{is a C++1z extension}} +#endif + + diff --git a/test/Parser/cxx1z-init-statement.cpp b/test/Parser/cxx1z-init-statement.cpp new file mode 100644 index 0000000000000..3d119ef8e709c --- /dev/null +++ b/test/Parser/cxx1z-init-statement.cpp @@ -0,0 +1,51 @@ +// RUN: %clang_cc1 -std=c++1z -verify %s -Wno-vexing-parse + +int g, h; +typedef int T; +int f() { + // init-statement declarations + if (T n = 0; n != 0) {} + if (T f(); f()) {} + if (T(f()); f()) {} + if (T(f()), g, h; f()) {} + if (T f(); f()) {} + if (T f(), g, h; f()) {} + if (T(n) = 0; n) {} + + // init-statement expressions + if (T{f()}; f()) {} + if (T{f()}, g, h; f()) {} // expected-warning 2{{unused}} + if (T(f()), g, h + 1; f()) {} // expected-warning 2{{unused}} + + // condition declarations + if (T(n){g}) {} + if (T f()) {} // expected-error {{function type}} + if (T f(), g, h) {} // expected-error {{function type}} + if (T(n) = 0) {} + + // condition expressions + if (T(f())) {} + if (T{f()}) {} + if (T(f()), g, h) {} // expected-warning 2{{unused}} + if (T{f()}, g, h) {} // expected-warning 2{{unused}} + + // none of the above, disambiguated as expression (can't be a declaration) + if (T(n)(g)) {} // expected-error {{undeclared identifier 'n'}} + if (T(n)(int())) {} // expected-error {{undeclared identifier 'n'}} + + // Likewise for 'switch' + switch (int n; n) {} + switch (g; int g = 5) {} + + if (int a, b; int c = a) { // expected-note 6{{previous}} + int a; // expected-error {{redefinition}} + int b; // expected-error {{redefinition}} + int c; // expected-error {{redefinition}} + } else { + int a; // expected-error {{redefinition}} + int b; // expected-error {{redefinition}} + int c; // expected-error {{redefinition}} + } + + return 0; +} diff --git a/test/Parser/extra-semi.cpp b/test/Parser/extra-semi.cpp index 1a44dae411e2e..7287f856d8c97 100644 --- a/test/Parser/extra-semi.cpp +++ b/test/Parser/extra-semi.cpp @@ -5,7 +5,6 @@ void test1(int a;) { // expected-error{{unexpected ';' before ')'}} while (a > 5;) {} // expected-error{{unexpected ';' before ')'}} - if (int b = 10;) {} // expected-error{{unexpected ';' before ')'}} for (int c = 0; c < 21; ++c;) {} // expected-error{{unexpected ';' before ')'}} int d = int(3 + 4;); // expected-error{{unexpected ';' before ')'}} int e[5;]; // expected-error{{unexpected ';' before ']'}} diff --git a/test/Parser/ms-anachronism.c b/test/Parser/ms-anachronism.c new file mode 100644 index 0000000000000..37676397873cc --- /dev/null +++ b/test/Parser/ms-anachronism.c @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 -triple i686-windows-msvc -fms-extensions -fsyntax-only -verify %s + +struct {} __cdecl s; // expected-warning {{'__cdecl' only applies to function types; type here is 'struct}} diff --git a/test/Parser/ms-inline-asm.c b/test/Parser/ms-inline-asm.c index 6dde5f5c0d69b..e3c392406957f 100644 --- a/test/Parser/ms-inline-asm.c +++ b/test/Parser/ms-inline-asm.c @@ -53,6 +53,10 @@ void t11() { void t12() { __asm jmp label // expected-error {{use of undeclared label 'label'}} } +void t13() { + __asm m{o}v eax, ebx // expected-error {{expected identifier}} expected-error {{use of undeclared label '{o}v eax, ebx'}} +} + int t_fail() { // expected-note {{to match this}} __asm - __asm { // expected-error 2 {{expected}} expected-note {{to match this}} + __asm { // expected-error 3 {{expected}} expected-note {{to match this}} diff --git a/test/Parser/objc-available.m b/test/Parser/objc-available.m new file mode 100644 index 0000000000000..ca30753144359 --- /dev/null +++ b/test/Parser/objc-available.m @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -fsyntax-only -Wunguarded-availability -triple x86_64-apple-macosx10.10.0 -verify %s + +void f() { + + if (@available(macos 10.12, *)) {} + else if (@available(macos 10.11, *)) {} + else {} + + (void)__builtin_available(ios 8, macos 10.10, *); + + (void)@available(macos 10.11); // expected-error{{must handle potential future platforms with '*'}} + (void)@available(macos 10.11, macos 10.11, *); // expected-error{{version for 'macos' already specified}} + + (void)@available(erik_os 10.11, *); // expected-error{{unrecognized platform name erik_os}} + + (void)@available(erik_os 10.10, hat_os 1.0, *); // expected-error 2 {{unrecognized platform name}} + + (void)@available(ios 8, *); // expected-warning{{using '*' case here, platform macos is not accounted for}} + + (void)@available(); // expected-error{{expected a platform name here}} + (void)@available(macos 10.10,); // expected-error{{expected a platform name here}} + (void)@available(macos); // expected-error{{expected a version}} + (void)@available; // expected-error{{expected '('}} +} diff --git a/test/Parser/objc-class-property.m b/test/Parser/objc-class-property.m new file mode 100644 index 0000000000000..e4c3b0766b4a9 --- /dev/null +++ b/test/Parser/objc-class-property.m @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// expected-no-diagnostics + +@interface Root +-(id) alloc; +-(id) init; +@end + +@interface A : Root { + int x; + int z; +} +@property int x; +@property int y; +@property int z; +@property(readonly) int ro, ro2; +@property (class) int c; +@end + +@implementation A +@dynamic x; +@synthesize z; +@dynamic c; +@end + +int test() { + A *a = [[A alloc] init]; + return a.x; +} diff --git a/test/Parser/objc-default-ctor-init.mm b/test/Parser/objc-default-ctor-init.mm new file mode 100644 index 0000000000000..ea4c064d77914 --- /dev/null +++ b/test/Parser/objc-default-ctor-init.mm @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.10 -std=c++11 -ast-dump %s | FileCheck %s +// CHECK: CXXCtorInitializer Field {{.*}} 'ptr' 'void *' +// CHECK: CXXCtorInitializer Field {{.*}} 'q' 'struct Q' + +@interface NSObject +@end + +@interface I : NSObject +@end + +struct Q { Q(); }; + +struct S { + S(); + void *ptr = nullptr; + Q q; +}; + +@implementation I +S::S() {} +@end diff --git a/test/Parser/objcxx11-messaging-and-lambda.mm b/test/Parser/objcxx11-messaging-and-lambda.mm new file mode 100644 index 0000000000000..002f3e9c710aa --- /dev/null +++ b/test/Parser/objcxx11-messaging-and-lambda.mm @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s + +#define OBJCLASS(name) // expected-note {{macro 'OBJCLASS' defined here}} + +class NSMutableData; + +NSMutableData *test() { // expected-note {{to match this '{'}} + NSMutableData *data = [[[OBJCLASS(NSMutableDataOBJCLASS( alloc] init] autorelease]; // expected-error {{unterminated function-like macro invocation}} \ + // expected-error {{expected ';' at end of declaration}} + return data; +} // expected-error {{expected expression}} expected-error {{expected '}'}} diff --git a/test/Parser/objcxx11-protocol-in-template.mm b/test/Parser/objcxx11-protocol-in-template.mm index c5c3b6c75a473..5c80ae9759791 100644 --- a/test/Parser/objcxx11-protocol-in-template.mm +++ b/test/Parser/objcxx11-protocol-in-template.mm @@ -8,3 +8,11 @@ template<class T> class vector {}; vector<id<P>> v; vector<vector<id<P>>> v2; + +@protocol PA; +@protocol PB; + +@class NSArray<ObjectType>; +typedef int some_t; + +id<PA> FA(NSArray<id<PB>> *h, some_t group); diff --git a/test/Parser/objcxx14-protocol-in-template.mm b/test/Parser/objcxx14-protocol-in-template.mm new file mode 100644 index 0000000000000..36da92e251f4c --- /dev/null +++ b/test/Parser/objcxx14-protocol-in-template.mm @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++14 %s + +template<class T> class vector {}; +@protocol P @end + +// expected-no-diagnostics + +template <typename Functor> void F(Functor functor) {} + +// Test protocol in template within lambda capture initializer context. +void z() { + id<P> x = 0; + (void)x; + F( [ x = vector<id<P>>{} ] {} ); +} diff --git a/test/Parser/opencl-astype.cl b/test/Parser/opencl-astype.cl index 72f98a4ace9ff..903c42ee8c14b 100644 --- a/test/Parser/opencl-astype.cl +++ b/test/Parser/opencl-astype.cl @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify %s -triple spir-unknown-unknown #pragma OPENCL EXTENSION cl_khr_fp64 : enable void test_astype() { diff --git a/test/Parser/opencl-atomics-cl20.cl b/test/Parser/opencl-atomics-cl20.cl index cb2f59721acc0..cd37757b97f68 100644 --- a/test/Parser/opencl-atomics-cl20.cl +++ b/test/Parser/opencl-atomics-cl20.cl @@ -1,11 +1,14 @@ -// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -// RUN: %clang_cc1 %s -verify -fsyntax-only -cl-std=CL2.0 -DCL20 -// RUN: %clang_cc1 %s -verify -fsyntax-only -cl-std=CL2.0 -DCL20 -DEXT +// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only +// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -fsyntax-only -cl-std=CL2.0 -DCL20 +// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -fsyntax-only -cl-std=CL2.0 -DCL20 -DEXT -Wpedantic-core-features #ifdef EXT #pragma OPENCL EXTENSION cl_khr_int64_base_atomics:enable #pragma OPENCL EXTENSION cl_khr_int64_extended_atomics:enable #pragma OPENCL EXTENSION cl_khr_fp64:enable +#if __OPENCL_C_VERSION__ >= CL_VERSION_1_2 +// expected-warning@-2{{OpenCL extension 'cl_khr_fp64' is core feature or supported optional core feature - ignoring}} +#endif #endif void atomic_types_test() { @@ -44,15 +47,14 @@ void atomic_types_test() { // expected-error@-28 {{use of type 'atomic_ulong' (aka '_Atomic(unsigned long)') requires cl_khr_int64_extended_atomics extension to be enabled}} // expected-error@-27 {{use of type 'atomic_double' (aka '_Atomic(double)') requires cl_khr_int64_base_atomics extension to be enabled}} // expected-error@-28 {{use of type 'atomic_double' (aka '_Atomic(double)') requires cl_khr_int64_extended_atomics extension to be enabled}} -// expected-error@-29 {{use of type 'atomic_double' (aka '_Atomic(double)') requires cl_khr_fp64 extension to be enabled}} -// expected-error-re@-28 {{use of type 'atomic_intptr_t' (aka '_Atomic({{.+}})') requires cl_khr_int64_base_atomics extension to be enabled}} -// expected-error-re@-29 {{use of type 'atomic_intptr_t' (aka '_Atomic({{.+}})') requires cl_khr_int64_extended_atomics extension to be enabled}} -// expected-error-re@-29 {{use of type 'atomic_uintptr_t' (aka '_Atomic({{.+}})') requires cl_khr_int64_base_atomics extension to be enabled}} -// expected-error-re@-30 {{use of type 'atomic_uintptr_t' (aka '_Atomic({{.+}})') requires cl_khr_int64_extended_atomics extension to be enabled}} -// expected-error-re@-30 {{use of type 'atomic_size_t' (aka '_Atomic({{.+}})') requires cl_khr_int64_base_atomics extension to be enabled}} -// expected-error-re@-31 {{use of type 'atomic_size_t' (aka '_Atomic({{.+}})') requires cl_khr_int64_extended_atomics extension to be enabled}} -// expected-error-re@-31 {{use of type 'atomic_ptrdiff_t' (aka '_Atomic({{.+}})') requires cl_khr_int64_base_atomics extension to be enabled}} -// expected-error-re@-32 {{use of type 'atomic_ptrdiff_t' (aka '_Atomic({{.+}})') requires cl_khr_int64_extended_atomics extension to be enabled}} +// expected-error-re@-27 {{use of type 'atomic_intptr_t' (aka '_Atomic({{.+}})') requires cl_khr_int64_base_atomics extension to be enabled}} +// expected-error-re@-28 {{use of type 'atomic_intptr_t' (aka '_Atomic({{.+}})') requires cl_khr_int64_extended_atomics extension to be enabled}} +// expected-error-re@-28 {{use of type 'atomic_uintptr_t' (aka '_Atomic({{.+}})') requires cl_khr_int64_base_atomics extension to be enabled}} +// expected-error-re@-29 {{use of type 'atomic_uintptr_t' (aka '_Atomic({{.+}})') requires cl_khr_int64_extended_atomics extension to be enabled}} +// expected-error-re@-29 {{use of type 'atomic_size_t' (aka '_Atomic({{.+}})') requires cl_khr_int64_base_atomics extension to be enabled}} +// expected-error-re@-30 {{use of type 'atomic_size_t' (aka '_Atomic({{.+}})') requires cl_khr_int64_extended_atomics extension to be enabled}} +// expected-error-re@-30 {{use of type 'atomic_ptrdiff_t' (aka '_Atomic({{.+}})') requires cl_khr_int64_base_atomics extension to be enabled}} +// expected-error-re@-31 {{use of type 'atomic_ptrdiff_t' (aka '_Atomic({{.+}})') requires cl_khr_int64_extended_atomics extension to be enabled}} #endif #ifdef CL20 diff --git a/test/Parser/opencl-cl20.cl b/test/Parser/opencl-cl20.cl index b71869919ba9d..b14ad10153df7 100644 --- a/test/Parser/opencl-cl20.cl +++ b/test/Parser/opencl-cl20.cl @@ -10,9 +10,9 @@ __generic int * __generic_test(__generic int *arg) { return var; } #ifndef CL20 -// expected-error@-5 {{OpenCL does not support the '__generic' type qualifier}} -// expected-error@-6 {{OpenCL does not support the '__generic' type qualifier}} -// expected-error@-6 {{OpenCL does not support the '__generic' type qualifier}} +// expected-error@-5 {{OpenCL version 1.0 does not support the '__generic' type qualifier}} +// expected-error@-6 {{OpenCL version 1.0 does not support the '__generic' type qualifier}} +// expected-error@-6 {{OpenCL version 1.0 does not support the '__generic' type qualifier}} #endif generic int * generic_test(generic int *arg) { @@ -20,7 +20,7 @@ generic int * generic_test(generic int *arg) { return var; } #ifndef CL20 -// expected-error@-5 {{OpenCL does not support the 'generic' type qualifier}} -// expected-error@-6 {{OpenCL does not support the 'generic' type qualifier}} -// expected-error@-6 {{OpenCL does not support the 'generic' type qualifier}} +// expected-error@-5 {{OpenCL version 1.0 does not support the 'generic' type qualifier}} +// expected-error@-6 {{OpenCL version 1.0 does not support the 'generic' type qualifier}} +// expected-error@-6 {{OpenCL version 1.0 does not support the 'generic' type qualifier}} #endif diff --git a/test/Parser/opencl-image-access.cl b/test/Parser/opencl-image-access.cl index e08d129214397..99ced8e32bb73 100644 --- a/test/Parser/opencl-image-access.cl +++ b/test/Parser/opencl-image-access.cl @@ -1,14 +1,19 @@ -// RUN: %clang_cc1 %s -fsyntax-only +// RUN: %clang_cc1 %s -fsyntax-only -verify +// RUN: %clang_cc1 %s -fsyntax-only -verify -cl-std=CL2.0 -DCL20 +// expected-no-diagnostics __kernel void f__ro(__read_only image2d_t a) { } __kernel void f__wo(__write_only image2d_t a) { } +#if CL20 __kernel void f__rw(__read_write image2d_t a) { } - +#endif __kernel void fro(read_only image2d_t a) { } __kernel void fwo(write_only image2d_t a) { } +#if CL20 __kernel void frw(read_write image2d_t a) { } +#endif diff --git a/test/Parser/opencl-pragma.cl b/test/Parser/opencl-pragma.cl index 4c48b2a496f78..b002b0854a4d0 100644 --- a/test/Parser/opencl-pragma.cl +++ b/test/Parser/opencl-pragma.cl @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 %s -verify -pedantic -Wno-empty-translation-unit -fsyntax-only +// RUN: %clang_cc1 %s -verify -pedantic -Wno-empty-translation-unit -fsyntax-only -triple spir-unknown-unknown #pragma OPENCL EXTENSION cl_khr_fp16 : enable diff --git a/test/Parser/opencl-storage-class.cl b/test/Parser/opencl-storage-class.cl index 3d9aef59f0bbc..a8ebc1af39993 100644 --- a/test/Parser/opencl-storage-class.cl +++ b/test/Parser/opencl-storage-class.cl @@ -1,15 +1,15 @@ -// RUN: %clang_cc1 %s -verify -fsyntax-only +// RUN: %clang_cc1 %s -verify -fsyntax-only -triple spir-unknown-unknown void test_storage_class_specs() { - static int a; // expected-error {{OpenCL does not support the 'static' storage class specifier}} - register int b; // expected-error {{OpenCL does not support the 'register' storage class specifier}} - extern int c; // expected-error {{OpenCL does not support the 'extern' storage class specifier}} - auto int d; // expected-error {{OpenCL does not support the 'auto' storage class specifier}} + static int a; // expected-error {{OpenCL version 1.0 does not support the 'static' storage class specifier}} + register int b; // expected-error {{OpenCL version 1.0 does not support the 'register' storage class specifier}} + extern int c; // expected-error {{OpenCL version 1.0 does not support the 'extern' storage class specifier}} + auto int d; // expected-error {{OpenCL version 1.0 does not support the 'auto' storage class specifier}} #pragma OPENCL EXTENSION cl_clang_storage_class_specifiers : enable - static int e; // expected-error {{program scope variable must reside in constant address space}} + static int e; // expected-error {{static local variable must reside in constant address space}} register int f; - extern int g; + extern int g; // expected-error {{extern variable must reside in constant address space}} auto int h; } diff --git a/test/Parser/opencl-unroll-hint.cl b/test/Parser/opencl-unroll-hint.cl new file mode 100644 index 0000000000000..5742dcde2195b --- /dev/null +++ b/test/Parser/opencl-unroll-hint.cl @@ -0,0 +1,8 @@ +//RUN: %clang_cc1 -O0 -cl-std=CL2.0 -fsyntax-only -verify %s + +kernel void B (global int *x) { + __attribute__((opencl_unroll_hint(42))) + if (x[0]) // expected-error {{OpenCL only supports 'opencl_unroll_hint' attribute on for, while, and do statements}} + x[0] = 15; +} + diff --git a/test/Parser/pragma-loop-safety.cpp b/test/Parser/pragma-loop-safety.cpp index 0776000e51219..ab87dcdcb63e6 100644 --- a/test/Parser/pragma-loop-safety.cpp +++ b/test/Parser/pragma-loop-safety.cpp @@ -16,6 +16,7 @@ void test(int *List, int Length) { /* expected-error {{expected ')'}} */ #pragma clang loop interleave(assume_safety /* expected-error {{invalid argument; expected 'enable', 'full' or 'disable'}} */ #pragma clang loop unroll(assume_safety) +/* expected-error {{invalid argument; expected 'enable' or 'disable'}} */ #pragma clang loop distribute(assume_safety) /* expected-error {{invalid argument; expected 'enable', 'assume_safety' or 'disable'}} */ #pragma clang loop vectorize(badidentifier) /* expected-error {{invalid argument; expected 'enable', 'assume_safety' or 'disable'}} */ #pragma clang loop interleave(badidentifier) diff --git a/test/Parser/pragma-loop.cpp b/test/Parser/pragma-loop.cpp index b9b5b41efbad7..f42d196ce8bd3 100644 --- a/test/Parser/pragma-loop.cpp +++ b/test/Parser/pragma-loop.cpp @@ -116,15 +116,27 @@ void test(int *List, int Length) { VList[j] = List[j]; } +#pragma clang loop distribute(enable) + for (int j : VList) { + VList[j] = List[j]; + } + +#pragma clang loop distribute(disable) + for (int j : VList) { + VList[j] = List[j]; + } + test_nontype_template_param<4, 8>(List, Length); /* expected-error {{expected '('}} */ #pragma clang loop vectorize /* expected-error {{expected '('}} */ #pragma clang loop interleave /* expected-error {{expected '('}} */ #pragma clang loop unroll +/* expected-error {{expected '('}} */ #pragma clang loop distribute /* expected-error {{expected ')'}} */ #pragma clang loop vectorize(enable /* expected-error {{expected ')'}} */ #pragma clang loop interleave(enable /* expected-error {{expected ')'}} */ #pragma clang loop unroll(full +/* expected-error {{expected ')'}} */ #pragma clang loop distribute(enable /* expected-error {{expected ')'}} */ #pragma clang loop vectorize_width(4 /* expected-error {{expected ')'}} */ #pragma clang loop interleave_count(4 @@ -133,8 +145,9 @@ void test(int *List, int Length) { /* expected-error {{missing argument; expected 'enable', 'assume_safety' or 'disable'}} */ #pragma clang loop vectorize() /* expected-error {{missing argument; expected an integer value}} */ #pragma clang loop interleave_count() /* expected-error {{missing argument; expected 'enable', 'full' or 'disable'}} */ #pragma clang loop unroll() +/* expected-error {{missing argument; expected 'enable' or 'disable'}} */ #pragma clang loop distribute() -/* expected-error {{missing option; expected vectorize, vectorize_width, interleave, interleave_count, unroll, or unroll_count}} */ #pragma clang loop +/* expected-error {{missing option; expected vectorize, vectorize_width, interleave, interleave_count, unroll, unroll_count, or distribute}} */ #pragma clang loop /* expected-error {{invalid option 'badkeyword'}} */ #pragma clang loop badkeyword /* expected-error {{invalid option 'badkeyword'}} */ #pragma clang loop badkeyword(enable) /* expected-error {{invalid option 'badkeyword'}} */ #pragma clang loop vectorize(enable) badkeyword(4) @@ -187,6 +200,7 @@ const int VV = 4; /* expected-error {{invalid argument; expected 'enable', 'assume_safety' or 'disable'}} */ #pragma clang loop vectorize(badidentifier) /* expected-error {{invalid argument; expected 'enable', 'assume_safety' or 'disable'}} */ #pragma clang loop interleave(badidentifier) /* expected-error {{invalid argument; expected 'enable', 'full' or 'disable'}} */ #pragma clang loop unroll(badidentifier) +/* expected-error {{invalid argument; expected 'enable' or 'disable'}} */ #pragma clang loop distribute(badidentifier) while (i-7 < Length) { List[i] = i; } @@ -196,6 +210,7 @@ const int VV = 4; /* expected-error {{expected ')'}} */ #pragma clang loop vectorize(() /* expected-error {{invalid argument; expected 'enable', 'assume_safety' or 'disable'}} */ #pragma clang loop interleave(*) /* expected-error {{invalid argument; expected 'enable', 'full' or 'disable'}} */ #pragma clang loop unroll(=) +/* expected-error {{invalid argument; expected 'enable' or 'disable'}} */ #pragma clang loop distribute(+) /* expected-error {{type name requires a specifier or qualifier}} expected-error {{expected expression}} */ #pragma clang loop vectorize_width(^) /* expected-error {{expected expression}} expected-error {{expected expression}} */ #pragma clang loop interleave_count(/) /* expected-error {{expected expression}} expected-error {{expected expression}} */ #pragma clang loop unroll_count(==) @@ -232,6 +247,8 @@ const int VV = 4; #pragma clang loop interleave(disable) /* expected-error {{duplicate directives 'unroll(disable)' and 'unroll(full)'}} */ #pragma clang loop unroll(full) #pragma clang loop unroll(disable) +/* expected-error {{duplicate directives 'distribute(disable)' and 'distribute(enable)'}} */ #pragma clang loop distribute(enable) +#pragma clang loop distribute(disable) while (i-9 < Length) { List[i] = i; } diff --git a/test/Parser/pragma-pack.c b/test/Parser/pragma-pack.c index 172a332510a7e..0859f4157ce3b 100644 --- a/test/Parser/pragma-pack.c +++ b/test/Parser/pragma-pack.c @@ -44,3 +44,7 @@ struct S #pragma pack() int e; }; + +_Pragma("pack(push, 1)") struct PR28094 { + int a; +} _Pragma("pack(pop)"); diff --git a/test/Parser/skip-function-bodies.mm b/test/Parser/skip-function-bodies.mm index 8462f69f3ab74..e5b7b2adf8389 100644 --- a/test/Parser/skip-function-bodies.mm +++ b/test/Parser/skip-function-bodies.mm @@ -30,7 +30,7 @@ void J() { // 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: skip-function-bodies.mm:7:3: CXXConstructor=A:7:3 (default constructor) 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] |