diff options
Diffstat (limited to 'test/Parser')
-rw-r--r-- | test/Parser/editor-placeholder-recovery.cpp | 71 | ||||
-rw-r--r-- | test/Parser/placeholder-recovery.m | 13 | ||||
-rw-r--r-- | test/Parser/pragma-attribute-declspec.cpp | 13 | ||||
-rw-r--r-- | test/Parser/pragma-attribute.cpp | 181 |
4 files changed, 273 insertions, 5 deletions
diff --git a/test/Parser/editor-placeholder-recovery.cpp b/test/Parser/editor-placeholder-recovery.cpp new file mode 100644 index 000000000000..48c290ee9a14 --- /dev/null +++ b/test/Parser/editor-placeholder-recovery.cpp @@ -0,0 +1,71 @@ +// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s +// RUN: %clang_cc1 -fsyntax-only -std=c++11 -fallow-editor-placeholders -DSUPPRESS -verify %s + +struct Struct { +public: + void method(Struct &x); +}; + +struct <#struct name#> { + int <#field-name#>; +#ifndef SUPPRESS + // expected-error@-3 {{editor placeholder in source file}} + // expected-error@-3 {{editor placeholder in source file}} +#endif +}; + +typename <#typename#>::<#name#>; +decltype(<#expression#>) foobar; +typedef <#type#> <#name#>; +#ifndef SUPPRESS + // expected-error@-4 2 {{editor placeholder in source file}} + // expected-error@-4 {{editor placeholder in source file}} + // expected-error@-4 2 {{editor placeholder in source file}} +#endif + +namespace <#identifier#> { + <#declarations#> +#ifndef SUPPRESS + // expected-error@-3 {{editor placeholder in source file}} + // expected-error@-3 {{editor placeholder in source file}} +#endif + +} + +using <#qualifier#>::<#name#>; +#ifndef SUPPRESS + // expected-error@-2 2 {{editor placeholder in source file}} +#endif + +void avoidPlaceholderErrors(Struct &obj) { + static_cast< <#type#> >(<#expression#>); + while (<#condition#>) { + <#statements#> + } + obj.method(<#Struct &x#>); +#ifndef SUPPRESS + // expected-error@-6 2 {{editor placeholder in source file}} + // expected-error@-6 {{editor placeholder in source file}} + // expected-error@-6 {{editor placeholder in source file}} + // expected-error@-5 {{editor placeholder in source file}} +#endif + switch (<#expression#>) { + case <#constant#>: + <#statements#> +#ifndef SUPPRESS + // expected-error@-4 {{editor placeholder in source file}} + // expected-error@-4 {{editor placeholder in source file}} + // expected-error@-4 {{editor placeholder in source file}} +#endif + break; + + default: + break; + } +} + +void Struct::method(<#Struct &x#>, noSupressionHere) { // expected-error {{unknown type name 'noSupressionHere'}} expected-error {{C++ requires a type specifier for all declarations}} +#ifndef SUPPRESS + // expected-error@-2 {{editor placeholder in source file}} +#endif +} diff --git a/test/Parser/placeholder-recovery.m b/test/Parser/placeholder-recovery.m index b43b0e4a57cb..4f22ea770da9 100644 --- a/test/Parser/placeholder-recovery.m +++ b/test/Parser/placeholder-recovery.m @@ -1,11 +1,14 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +@protocol NSObject +@end + +@protocol <#protocol name#> <NSObject> // expected-error {{editor placeholder in source file}} +// expected-note@-1 {{protocol started here}} + // FIXME: We could do much better with this, if we recognized // placeholders somehow. However, we're content with not generating // bogus 'archaic' warnings with bad location info. -@protocol <#protocol name#> <NSObject> // expected-error {{expected identifier or '('}} \ -// expected-error 2{{expected identifier}} \ -// expected-warning{{protocol has no object type specified; defaults to qualified 'id'}} -<#methods#> +<#methods#> // expected-error {{editor placeholder in source file}} -@end +@end // expected-error {{prefix attribute must be followed by an interface or protocol}} expected-error {{missing '@end'}} diff --git a/test/Parser/pragma-attribute-declspec.cpp b/test/Parser/pragma-attribute-declspec.cpp new file mode 100644 index 000000000000..28785ba90063 --- /dev/null +++ b/test/Parser/pragma-attribute-declspec.cpp @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -triple i386-pc-win32 -std=c++11 -verify -Wno-pragma-clang-attribute -fms-extensions -fms-compatibility %s + +#pragma clang attribute push(__declspec(dllexport), apply_to = function) + +void function(); + +#pragma clang attribute pop + +#pragma clang attribute push(__declspec(dllexport, dllimport), apply_to = function) // expected-error {{more than one attribute specified in '#pragma clang attribute push'}} + +#pragma clang attribute push(__declspec(align), apply_to = variable) // expected-error {{attribute 'align' is not supported by '#pragma clang attribute'}} + +#pragma clang attribute push(__declspec(), apply_to = variable) // A noop diff --git a/test/Parser/pragma-attribute.cpp b/test/Parser/pragma-attribute.cpp new file mode 100644 index 000000000000..f0ebca2c5313 --- /dev/null +++ b/test/Parser/pragma-attribute.cpp @@ -0,0 +1,181 @@ +// RUN: %clang_cc1 -Wno-pragma-clang-attribute -verify -std=c++11 %s + +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = function) + +void function(); + +#pragma clang attribute pop + +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any(variable(is_parameter), function)) +#pragma clang attribute pop + +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = variable(unless(is_parameter))) +#pragma clang attribute pop + +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any(variable(unless(is_parameter)))) +#pragma clang attribute pop + +#pragma clang attribute push (__attribute__((abi_tag("a")))) // expected-error {{expected ','}} +#pragma clang attribute push (__attribute__((abi_tag("a"))) apply_to=function) // expected-error {{expected ','}} +#pragma clang attribute push (__attribute__((abi_tag("a"))) = function) // expected-error {{expected ','}} +#pragma clang attribute push (__attribute__((abi_tag("a"))) any(function)) // expected-error {{expected ','}} + +#pragma clang attribute push (__attribute__((abi_tag("a"))) 22) // expected-error {{expected ','}} +#pragma clang attribute push (__attribute__((abi_tag("a"))) function) // expected-error {{expected ','}} +#pragma clang attribute push (__attribute__((abi_tag("a"))) (function)) // expected-error {{expected ','}} + +#pragma clang attribute push(__attribute__((annotate("test"))), ) // expected-error {{expected attribute subject set specifier 'apply_to'}} +#pragma clang attribute push(__attribute__((annotate("test"))), = any(function)) // expected-error {{expected attribute subject set specifier 'apply_to'}} +#pragma clang attribute push(__attribute__((annotate("test"))), = function) // expected-error {{expected attribute subject set specifier 'apply_to'}} +#pragma clang attribute push(__attribute__((annotate("test"))), any(function)) // expected-error {{expected attribute subject set specifier 'apply_to'}} +#pragma clang attribute push(__attribute__((annotate("test"))), function) // expected-error {{expected attribute subject set specifier 'apply_to'}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply = any(function )) // expected-error {{expected attribute subject set specifier 'apply_to'}} +#pragma clang attribute push(__attribute__((annotate("test"))), to = function) // expected-error {{expected attribute subject set specifier 'apply_to'}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_only_to = function) // expected-error {{expected attribute subject set specifier 'apply_to'}} + +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to any(function)) // expected-error {{expected '='}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to function) // expected-error {{expected '='}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to) // expected-error {{expected '='}} +#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to 41 (22)) // expected-error {{expected '='}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any) // expected-error {{expected '('}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any {) // expected-error {{expected '('}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any function) // expected-error {{expected '('}} + +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = { function, enum }) // expected-error {{expected an identifier that corresponds to an attribute subject rule}} + +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any(function ) // expected-error {{expected ')'}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any(function, )) // expected-error {{expected an identifier that corresponds to an attribute subject rule}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( function, enum ) // expected-error {{expected ')'}} + +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = () ) // expected-error {{expected an identifier that corresponds to an attribute subject rule}} + +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( + ) ) // expected-error {{expected an identifier that corresponds to an attribute subject rule}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any()) // expected-error {{expected an identifier that corresponds to an attribute subject rule}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( function, 42 )) // expected-error {{expected an identifier that corresponds to an attribute subject rule}} + +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( diag )) // expected-error {{unknown attribute subject rule 'diag'}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( a )) // expected-error {{unknown attribute subject rule 'a'}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( function, for)) // expected-error {{unknown attribute subject rule 'for'}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( function42, for )) // expected-error {{unknown attribute subject rule 'function42'}} + +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any(hasType)) // expected-error {{expected '('}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = hasType) // expected-error {{expected '('}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = hasType(functionType)) // OK + +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( variable( )) // expected-error {{expected ')'}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( variable( ) )) // expected-error {{expected an identifier that corresponds to an attribute subject matcher sub-rule; 'variable' matcher supports the following sub-rules: 'is_thread_local', 'is_global', 'is_parameter', 'unless(is_parameter)'}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( variable(is ) )) // expected-error {{unknown attribute subject matcher sub-rule 'is'; 'variable' matcher supports the following sub-rules: 'is_thread_local', 'is_global', 'is_parameter', 'unless(is_parameter)'}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( variable(is_parameter, not) )) // expected-error {{expected ')'}} expected-note {{to match this '('}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( variable is_parameter )) // expected-error {{expected ')'}} expected-note {{to match this '('}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( variable ( ) // expected-error {{expected ')'}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = variable ( // expected-error {{expected ')'}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( function, variable (is ()) )) // expected-error {{unknown attribute subject matcher sub-rule 'is'; 'variable' matcher supports the following sub-rules: 'is_thread_local', 'is_global', 'is_parameter', 'unless(is_parameter)'}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( function, variable (42) )) // expected-error {{expected an identifier that corresponds to an attribute subject matcher sub-rule; 'variable' matcher supports the following sub-rules: 'is_thread_local', 'is_global', 'is_parameter', 'unless(is_parameter)'}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( function, namespace("test") )) // expected-error {{expected an identifier that corresponds to an attribute subject matcher sub-rule; 'namespace' matcher does not support sub-rules}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( function, variable ("test" )) // expected-error {{expected ')'}} + +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = enum(is_parameter)) // expected-error {{invalid use of attribute subject matcher sub-rule 'is_parameter'; 'enum' matcher does not support sub-rules}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any(enum(is_parameter))) // expected-error {{invalid use of attribute subject matcher sub-rule 'is_parameter'; 'enum' matcher does not support sub-rules}} + +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any (function, variable (unless) )) // expected-error {{expected '('}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any (function, variable (unless() )) // expected-error {{expected ')'}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any ( function, variable (unless(is)) )) // expected-error {{unknown attribute subject matcher sub-rule 'unless(is)'; 'variable' matcher supports the following sub-rules: 'is_thread_local', 'is_global', 'is_parameter', 'unless(is_parameter)'}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( variable(unless(is_parameter, not)) )) // expected-error {{expected ')'}} expected-note {{to match this '('}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( variable(unless(is_parameter), not) ) // expected-error {{expected ')'}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( variable unless is_parameter )) // expected-error {{expected ')'}} expected-note {{to match this '('}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( variable(unless is_parameter) )) // expected-error {{expected '('}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( function, variable (unless(42)) )) // expected-error {{expected an identifier that corresponds to an attribute subject matcher sub-rule; 'variable' matcher supports the following sub-rules: 'is_thread_local', 'is_global', 'is_parameter', 'unless(is_parameter)'}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( function, enum(unless("test")) )) // expected-error {{expected an identifier that corresponds to an attribute subject matcher sub-rule; 'enum' matcher does not support sub-rules}} + +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( function, variable (unless(is_global)) )) // expected-error {{unknown attribute subject matcher sub-rule 'unless(is_global)'; 'variable' matcher supports the following sub-rules: 'is_thread_local', 'is_global', 'is_parameter', 'unless(is_parameter)'}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( enum(unless(is_parameter)) )) // expected-error {{invalid use of attribute subject matcher sub-rule 'unless(is_parameter)'; 'enum' matcher does not support sub-rules}} + +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( function, function )) // expected-error {{duplicate attribute subject matcher 'function'}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( function, function, function )) // expected-error 2 {{duplicate attribute subject matcher 'function'}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( function, enum, function )) // expected-error {{duplicate attribute subject matcher 'function'}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( enum, enum, function )) // expected-error {{duplicate attribute subject matcher 'enum'}} + +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( variable(is_global), variable(is_global) )) // expected-error {{duplicate attribute subject matcher 'variable(is_global)'}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( variable(is_global), function, variable(is_global), variable(is_global) )) // expected-error 2 {{duplicate attribute subject matcher 'variable(is_global)'}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( variable(unless(is_parameter)), variable(unless(is_parameter)) )) // expected-error {{duplicate attribute subject matcher 'variable(unless(is_parameter))'}} +#pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( variable(unless(is_parameter)), variable(unless(is_parameter)), enum, variable(unless(is_parameter)) )) // expected-error 2 {{duplicate attribute subject matcher 'variable(unless(is_parameter))'}} + +#pragma clang attribute // expected-error {{expected 'push' or 'pop' after '#pragma clang attribute'}} +#pragma clang attribute 42 // expected-error {{expected 'push' or 'pop' after '#pragma clang attribute'}} +#pragma clang attribute pushpop // expected-error {{unexpected argument 'pushpop' to '#pragma clang attribute'; expected 'push' or 'pop'}} + +#pragma clang attribute push // expected-error {{expected '('}} +#pragma clang attribute push ( // expected-error {{expected an attribute after '('}} +#pragma clang attribute push (__attribute__((annotate)) // expected-error {{expected ')'}} +#pragma clang attribute push () // expected-error {{expected an attribute after '('}} + +#pragma clang attribute push (__attribute__((annotate("test"))), apply_to = function) () // expected-warning {{extra tokens at end of '#pragma clang attribute'}} +// expected-error@-1 {{expected unqualified-id}} +// expected-error@-2 {{unterminated '#pragma clang attribute push' at end of file}} + +#pragma clang attribute pop () // expected-warning {{extra tokens at end of '#pragma clang attribute'}} + +; + +#pragma clang attribute push (__attribute__((42))) // expected-error {{expected identifier that represents an attribute name}} + +#pragma clang attribute push (__attribute__((annotate)) foo) // expected-error {{expected ','}} +#pragma clang attribute push (__attribute__((annotate)), apply_to=function foo) // expected-error {{extra tokens after attribute in a '#pragma clang attribute push'}} + +#pragma clang attribute push (__attribute__((objc_bridge_related)), apply_to=function) +// expected-error@-1 {{attribute 'objc_bridge_related' is not supported by '#pragma clang attribute'}} +#pragma clang attribute push (__attribute__((objc_bridge_related(1))), apply_to=function) // expected-error {{expected a related ObjectiveC class name, e.g., 'NSColor'}} + +#pragma clang attribute push (__attribute__((used)), apply_to=function) // expected-error {{attribute 'used' is not supported by '#pragma clang attribute'}} + +void statementPragmasAndPragmaExpression() { +#pragma clang attribute push (__attribute__((annotate("hello"))), apply_to=variable) +#pragma clang attribute pop +int x = 0; +_Pragma("clang attribute push (__attribute__((annotate(\"hi\"))), apply_to = function)"); + +_Pragma("clang attribute push (__attribute__((annotate(\"hi\"))), apply_to = any(function(is_method ))"); // expected-error {{expected ')'}} +} + +_Pragma("clang attribute pop"); + +#pragma clang attribute push (__attribute__((address_space(0))), apply_to=variable) // expected-error {{attribute 'address_space' is not supported by '#pragma clang attribute'}} + +// Check support for CXX11 style attributes +#pragma clang attribute push ([[noreturn]], apply_to = any(function)) +#pragma clang attribute pop + +#pragma clang attribute push ([[clang::disable_tail_calls]], apply_to = function) +#pragma clang attribute pop + +#pragma clang attribute push ([[gnu::abi_tag]], apply_to=any(function)) +#pragma clang attribute pop + +#pragma clang attribute push ([[clang::disable_tail_calls, noreturn]], apply_to = function) // expected-error {{more than one attribute specified in '#pragma clang attribute push'}} +#pragma clang attribute push ([[clang::disable_tail_calls, noreturn]]) // expected-error {{more than one attribute specified in '#pragma clang attribute push'}} + +#pragma clang attribute push ([[gnu::abi_tag]], apply_to=namespace) +#pragma clang attribute pop + +#pragma clang attribute push ([[fallthrough]], apply_to=function) // expected-error {{attribute 'fallthrough' is not supported by '#pragma clang attribute'}} +#pragma clang attribute push ([[clang::fallthrough]], apply_to=function) // expected-error {{attribute 'fallthrough' is not supported by '#pragma clang attribute'}} + +#pragma clang attribute push ([[]], apply_to = function) // A noop + +#pragma clang attribute push ([[noreturn ""]], apply_to=function) // expected-error {{expected ']'}} +#pragma clang attribute pop +#pragma clang attribute push ([[noreturn 42]]) // expected-error {{expected ']'}} expected-error {{expected ','}} + +#pragma clang attribute push(__attribute__, apply_to=function) // expected-error {{expected '(' after 'attribute'}} +#pragma clang attribute push(__attribute__(), apply_to=function) // expected-error {{expected '(' after '('}} +#pragma clang attribute push(__attribute__(()), apply_to=function) // expected-error {{expected identifier that represents an attribute name}} +#pragma clang attribute push(__attribute__((annotate, apply_to=function))) // expected-error {{expected ')'}} +#pragma clang attribute push(__attribute__((annotate("test"), apply_to=function))) // expected-error {{expected ')'}} +#pragma clang attribute push(__attribute__((annotate), apply_to=function)) // expected-error {{expected ')'}} + +#pragma clang attribute push (42) // expected-error {{expected an attribute that is specified using the GNU, C++11 or '__declspec' syntax}} +#pragma clang attribute push (test) // expected-error {{expected an attribute that is specified using the GNU, C++11 or '__declspec' syntax}} +#pragma clang attribute push (annotate) // expected-error {{expected an attribute that is specified using the GNU, C++11 or '__declspec' syntax}} +// expected-note@-1 {{use the GNU '__attribute__' syntax}} +#pragma clang attribute push (annotate("test")) // expected-error {{expected an attribute that is specified using the GNU, C++11 or '__declspec' syntax}} +// expected-note@-1 {{use the GNU '__attribute__' syntax}} |