diff options
Diffstat (limited to 'test/Parser')
-rw-r--r-- | test/Parser/MicrosoftExtensions.cpp | 12 | ||||
-rw-r--r-- | test/Parser/attributes.mm | 9 | ||||
-rw-r--r-- | test/Parser/cxx-class.cpp | 11 | ||||
-rw-r--r-- | test/Parser/cxx2a-template-lambdas.cpp | 8 | ||||
-rw-r--r-- | test/Parser/editor-placeholder-recovery.cpp | 2 | ||||
-rw-r--r-- | test/Parser/objc-implementation-attrs.m | 53 | ||||
-rw-r--r-- | test/Parser/objc-static-assert.m | 54 | ||||
-rw-r--r-- | test/Parser/objc-static-assert.mm | 77 | ||||
-rw-r--r-- | test/Parser/opencl-cxx-keywords.cl | 32 | ||||
-rw-r--r-- | test/Parser/placeholder-recovery.m | 2 | ||||
-rw-r--r-- | test/Parser/pragma-attribute-context.cpp | 38 | ||||
-rw-r--r-- | test/Parser/using-template.cpp | 52 |
12 files changed, 329 insertions, 21 deletions
diff --git a/test/Parser/MicrosoftExtensions.cpp b/test/Parser/MicrosoftExtensions.cpp index 8799f49df6..63e8b60823 100644 --- a/test/Parser/MicrosoftExtensions.cpp +++ b/test/Parser/MicrosoftExtensions.cpp @@ -288,6 +288,18 @@ struct pure_virtual_dtor_inline { virtual ~pure_virtual_dtor_inline() = 0 { }// expected-warning {{function definition with pure-specifier is a Microsoft extension}} }; +template<typename T> struct pure_virtual_dtor_template { + virtual ~pure_virtual_dtor_template() = 0; +}; +template<typename T> pure_virtual_dtor_template<T>::~pure_virtual_dtor_template() {} +template struct pure_virtual_dtor_template<int>; + +template<typename T> struct pure_virtual_dtor_template_inline { + virtual ~pure_virtual_dtor_template_inline() = 0 {} + // expected-warning@-1 2{{function definition with pure-specifier is a Microsoft extension}} +}; +template struct pure_virtual_dtor_template_inline<int>; +// expected-note@-1 {{in instantiation of member function}} int main () { // Necessary to force instantiation in -fdelayed-template-parsing mode. diff --git a/test/Parser/attributes.mm b/test/Parser/attributes.mm index 024606bed3..e583df039f 100644 --- a/test/Parser/attributes.mm +++ b/test/Parser/attributes.mm @@ -1,6 +1,8 @@ // RUN: %clang_cc1 -verify -fsyntax-only -Wno-objc-root-class %s -__attribute__((deprecated)) @class B; // expected-error {{prefix attribute must be followed by an interface or protocol}} +// FIXME: Why isn't this supported? Seems useful for availability attributes at +// the very least. +__attribute__((deprecated)) @class B; // expected-error {{prefix attribute must be followed by an interface, protocol, or implementation}} __attribute__((deprecated)) @interface A @end __attribute__((deprecated)) @protocol P0; @@ -15,11 +17,10 @@ EXP class C2 {}; // expected-warning {{attribute 'visibility' is ignored, place EXP @interface I2 @end @implementation EXP I @end // expected-error-re {{postfix attributes are not allowed on Objective-C directives{{$}}}} -// FIXME: Prefix attribute recovery skips until ';' -EXP @implementation I2 @end; // expected-error {{prefix attribute must be followed by an interface or protocol}} +EXP @implementation I2 @end @class EXP OC; // expected-error-re {{postfix attributes are not allowed on Objective-C directives{{$}}}} -EXP @class OC2; // expected-error {{prefix attribute must be followed by an interface or protocol}} +EXP @class OC2; // expected-error {{prefix attribute must be followed by an interface, protocol, or implementation}} @protocol EXP P @end // expected-error {{postfix attributes are not allowed on Objective-C directives, place them in front of '@protocol'}} EXP @protocol P2 @end diff --git a/test/Parser/cxx-class.cpp b/test/Parser/cxx-class.cpp index 3cc006af23..fe9c1ac95b 100644 --- a/test/Parser/cxx-class.cpp +++ b/test/Parser/cxx-class.cpp @@ -272,6 +272,17 @@ class BadExceptionSpec { )); }; +namespace PR41192 { +extern struct A a; +struct A {} ::PR41192::a; // ok, no missing ';' here expected-warning {{extra qualification}} + +#if __cplusplus >= 201103L +struct C; +struct D { static C c; }; +struct C {} decltype(D())::c; // expected-error {{'decltype' cannot be used to name a declaration}} +#endif +} + // 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/cxx2a-template-lambdas.cpp b/test/Parser/cxx2a-template-lambdas.cpp new file mode 100644 index 0000000000..034a3b157d --- /dev/null +++ b/test/Parser/cxx2a-template-lambdas.cpp @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -std=c++2a %s -verify + +auto L0 = []<> { }; //expected-error {{cannot be empty}} + +auto L1 = []<typename T1, typename T2> { }; +auto L2 = []<typename T1, typename T2>(T1 arg1, T2 arg2) -> T1 { }; +auto L3 = []<typename T>(auto arg) { T t; }; +auto L4 = []<int I>() { }; diff --git a/test/Parser/editor-placeholder-recovery.cpp b/test/Parser/editor-placeholder-recovery.cpp index d68e087d6f..62f5529906 100644 --- a/test/Parser/editor-placeholder-recovery.cpp +++ b/test/Parser/editor-placeholder-recovery.cpp @@ -64,7 +64,7 @@ void avoidPlaceholderErrors(Struct &obj) { } } -void Struct::method(<#Struct &x#>, noSupressionHere) { // expected-error {{unknown type name 'noSupressionHere'}} expected-error {{C++ requires a type specifier for all declarations}} +void Struct::method(<#Struct &x#>, noSupressionHere) { // expected-error {{unknown type name 'noSupressionHere'}} #ifndef SUPPRESS // expected-error@-2 {{editor placeholder in source file}} #endif diff --git a/test/Parser/objc-implementation-attrs.m b/test/Parser/objc-implementation-attrs.m new file mode 100644 index 0000000000..76d9714140 --- /dev/null +++ b/test/Parser/objc-implementation-attrs.m @@ -0,0 +1,53 @@ +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.14.0 -fsyntax-only -Wno-objc-root-class -verify %s + +@interface I1 @end + +// expected-warning@+1 {{'always_inline' attribute only applies to functions}} +__attribute__((always_inline)) +@implementation I1 @end + +// expected-warning@+1 {{'always_inline' attribute only applies to functions}} +__attribute__((always_inline)) +@implementation I1 (MyCat) @end + +// expected-warning@+1 {{'always_inline' attribute only applies to functions}} +__attribute__((always_inline)) +// expected-warning@+1 {{cannot find interface declaration for 'I2'}} +@implementation I2 @end + +// expected-error@+1 {{only applies to Objective-C interfaces}} +__attribute__((objc_root_class)) +// expected-warning@+1 {{cannot find interface declaration for 'I3'}} +@implementation I3 @end + +#define AVAIL_ATTR __attribute__((availability(macos, introduced=1000))) + +typedef int AVAIL_ATTR unavail_int; // expected-note {{marked as being introduced}} + +@interface I4 @end // expected-note {{annotate}} +@implementation I4 { + unavail_int x; // expected-warning {{'unavail_int' is only available on macOS 1000 or newer}} +} +@end + +@interface I5 @end + +#pragma clang attribute push (AVAIL_ATTR, apply_to=objc_implementation) +@implementation I5 { + unavail_int x; +} +@end +#pragma clang attribute pop + +I5 *i5; + +// expected-error@+1 2 {{'annotate' attribute takes one argument}} +#pragma clang attribute push (__attribute__((annotate)), apply_to=objc_implementation) +@interface I6 @end +@interface I6 (MyCat) @end +@interface I6 () @end + +@implementation I6 @end // expected-note {{when applied to this declaration}} +@implementation I6 (MyCat) @end // expected-note {{when applied to this declaration}} + +#pragma clang attribute pop diff --git a/test/Parser/objc-static-assert.m b/test/Parser/objc-static-assert.m new file mode 100644 index 0000000000..138b4fce20 --- /dev/null +++ b/test/Parser/objc-static-assert.m @@ -0,0 +1,54 @@ +// RUN: %clang_cc1 -fobjc-runtime=macosx-fragile -fsyntax-only -verify -Wno-objc-root-class %s +// RUN: %clang_cc1 -std=c89 -fobjc-runtime=macosx-fragile -fsyntax-only -verify -Wno-objc-root-class %s + + +#if __STDC_VERSION__ >= 201112L + +#if !__has_feature(objc_c_static_assert) +#error failed +#endif + +#if !__has_extension(objc_c_static_assert) +#error failed +#endif + +@interface A { + int a; + _Static_assert(1, ""); + _Static_assert(0, ""); // expected-error {{static_assert failed}} + + _Static_assert(a, ""); // expected-error {{use of undeclared identifier 'a'}} + _Static_assert(sizeof(a), ""); // expected-error {{use of undeclared identifier 'a'}} +} + +_Static_assert(1, ""); + +@end + +struct S { + @defs(A); +}; + +#else + +// _Static_assert is available before C11 as an extension, but -pedantic +// warns on it. +#if __has_feature(objc_c_static_assert) +#error failed +#endif + +#if !__has_extension(objc_c_static_assert) +#error failed +#endif + +@interface A { + int a; + _Static_assert(1, ""); + _Static_assert(0, ""); // expected-error {{static_assert failed}} +} + +_Static_assert(1, ""); + +@end + +#endif diff --git a/test/Parser/objc-static-assert.mm b/test/Parser/objc-static-assert.mm new file mode 100644 index 0000000000..125dd4856a --- /dev/null +++ b/test/Parser/objc-static-assert.mm @@ -0,0 +1,77 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s +// RUN: %clang_cc1 -std=c++98 -fsyntax-only -verify -Wno-objc-root-class %s + +#if __has_feature(objc_c_static_assert) +#error failed +#endif +#if !__has_extension(objc_c_static_assert) +#error failed +#endif + +#if __cplusplus >= 201103L + +#if !__has_feature(objc_cxx_static_assert) +#error failed +#endif + +// C++11 + +@interface A { + int a; + static_assert(1, ""); + _Static_assert(1, ""); + + static_assert(0, ""); // expected-error {{static_assert failed}} + _Static_assert(0, ""); // expected-error {{static_assert failed}} + + static_assert(a, ""); // expected-error {{static_assert expression is not an integral constant expression}} + static_assert(sizeof(a) == 4, ""); + static_assert(sizeof(a) == 3, ""); // expected-error {{static_assert failed}} +} + +static_assert(1, ""); +_Static_assert(1, ""); + +- (void)f; +@end + +@implementation A { + int b; + static_assert(1, ""); + _Static_assert(1, ""); + static_assert(sizeof(b) == 4, ""); + static_assert(sizeof(b) == 3, ""); // expected-error {{static_assert failed}} +} + +static_assert(1, ""); + +- (void)f { + static_assert(1, ""); +} +@end + +@interface B +@end + +@interface B () { + int b; + static_assert(sizeof(b) == 4, ""); + static_assert(sizeof(b) == 3, ""); // expected-error {{static_assert failed}} +} +@end + +#else + +#if __has_feature(objc_cxx_static_assert) +#error failed +#endif + +// C++98 +@interface A { + int a; + static_assert(1, ""); // expected-error {{type name requires a specifier or qualifier}} expected-error{{expected parameter declarator}} expected-error {{expected ')'}} expected-note {{to match this '('}} + _Static_assert(1, ""); + _Static_assert(0, ""); // expected-error {{static_assert failed}} +} +@end +#endif diff --git a/test/Parser/opencl-cxx-keywords.cl b/test/Parser/opencl-cxx-keywords.cl index 791da9361d..beae6f4b08 100644 --- a/test/Parser/opencl-cxx-keywords.cl +++ b/test/Parser/opencl-cxx-keywords.cl @@ -19,32 +19,34 @@ kernel void test_exceptions() { // Test that only __-prefixed address space qualifiers are accepted. struct test_address_space_qualifiers { global int *g; - // expected-error@-1 {{unknown type name 'global'}} - // expected-error@-2 {{expected member name or ';' after declaration specifiers}} __global int *uug; - int global; // should be fine in OpenCL C++ + int global; // expected-warning{{declaration does not declare anything}} local int *l; - // expected-error@-1 {{unknown type name 'local'}} - // expected-error@-2 {{expected member name or ';' after declaration specifiers}} __local int *uul; - int local; // should be fine in OpenCL C++ + int local; // expected-warning{{declaration does not declare anything}} private int *p; - // expected-error@-1 {{expected ':'}} __private int *uup; - int private; // 'private' is a keyword in C++14 and thus in OpenCL C++ - // expected-error@-1 {{expected member name or ';' after declaration specifiers}} + int private; // expected-warning{{declaration does not declare anything}} constant int *c; - // expected-error@-1 {{unknown type name 'constant'}} - // expected-error@-2 {{expected member name or ';' after declaration specifiers}} __constant int *uuc; - int constant; // should be fine in OpenCL C++ + int constant; // expected-warning{{declaration does not declare anything}} generic int *ge; - // expected-error@-1 {{unknown type name 'generic'}} - // expected-error@-2 {{expected member name or ';' after declaration specifiers}} __generic int *uuge; - int generic; // should be fine in OpenCL C++ + int generic; // expected-warning{{declaration does not declare anything}} }; + +// Test that 'private' can be parsed as an access qualifier and an address space too. +class A{ + private: + private int i; //expected-error{{field may not be qualified with an address space}} +}; + +private ::A i; //expected-error{{program scope variable must reside in global or constant address space}} + +void foo(private int i); + +private int bar(); //expected-error{{return value cannot be qualified with address space}} diff --git a/test/Parser/placeholder-recovery.m b/test/Parser/placeholder-recovery.m index 4f22ea770d..d49c8efb78 100644 --- a/test/Parser/placeholder-recovery.m +++ b/test/Parser/placeholder-recovery.m @@ -11,4 +11,4 @@ // bogus 'archaic' warnings with bad location info. <#methods#> // expected-error {{editor placeholder in source file}} -@end // expected-error {{prefix attribute must be followed by an interface or protocol}} expected-error {{missing '@end'}} +@end // expected-error {{prefix attribute must be followed by an interface, protocol, or implementation}} expected-error {{missing '@end'}} diff --git a/test/Parser/pragma-attribute-context.cpp b/test/Parser/pragma-attribute-context.cpp new file mode 100644 index 0000000000..d893f18335 --- /dev/null +++ b/test/Parser/pragma-attribute-context.cpp @@ -0,0 +1,38 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin9.0.0 -verify -std=c++11 %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin9.0.0 -xobjective-c++ -verify -std=c++11 %s + +#if !__has_extension(pragma_clang_attribute_external_declaration) +#error +#endif + +#define BEGIN_PRAGMA _Pragma("clang attribute push (__attribute__((availability(macos, introduced=1000))), apply_to=function)") +#define END_PRAGMA _Pragma("clang attribute pop") + +extern "C" { +BEGIN_PRAGMA +int f(); // expected-note{{'f' has been marked as being introduced in macOS 1000 here}} +END_PRAGMA +} + +namespace my_ns { +BEGIN_PRAGMA +int g(); // expected-note{{'g' has been marked as being introduced in macOS 1000 here}} +END_PRAGMA +namespace nested { +BEGIN_PRAGMA +int h(); // expected-note{{'h' has been marked as being introduced in macOS 1000 here}} +END_PRAGMA +} +} + +int a = f(); // expected-warning{{'f' is only available on macOS 1000 or newer}} expected-note{{annotate 'a'}} +int b = my_ns::g(); // expected-warning{{'g' is only available on macOS 1000 or newer}} expected-note{{annotate 'b'}} +int c = my_ns::nested::h(); // expected-warning{{'h' is only available on macOS 1000 or newer}} expected-note{{annotate 'c'}} + +struct InStruct { + // FIXME: This asserts in Objective-C++! + // FIXME: This is a horrible diagnostic! +#ifndef __OBJC__ + BEGIN_PRAGMA // expected-error {{expected member name or ';' after declaration specifiers}} +#endif +}; diff --git a/test/Parser/using-template.cpp b/test/Parser/using-template.cpp new file mode 100644 index 0000000000..686873d60b --- /dev/null +++ b/test/Parser/using-template.cpp @@ -0,0 +1,52 @@ +// RUN: %clang_cc1 %s -verify + +namespace N1 { +template <typename... Ts> +struct Foo { + template <typename T> + struct Bar { + static constexpr bool is_present = false; + }; +}; + +template <typename T, typename... Ts> +struct Foo<T, Ts...> : public Foo<Ts...> { + using template Foo<Ts...>::Bar; + // expected-error@-1 {{'template' keyword not permitted after 'using' keyword}} +}; +} + +namespace N2 { +namespace foo { + using I = int; +} +using template namespace foo; +// expected-error@-1 {{'template' keyword not permitted after 'using' keyword}} +using template template namespace foo; +// expected-error@-1 2{{'template' keyword not permitted after 'using' keyword}} +I i; +} + +namespace N3 { +namespace foo { + using I = int; +} +using template foo::I; +// expected-error@-1 {{'template' keyword not permitted after 'using' keyword}} +I i; +} + +namespace N4 { +template <typename T> +class A {}; + +template <typename T> +using B = A<T>; +B<int> b; + +using template <typename T> C = A<T>; +// expected-error@-1 {{'template' keyword not permitted after 'using' keyword}} +// expected-error@-2 {{expected unqualified-id}} +C<int> c; +// expected-error@-1 {{no template named 'C'}} +} |