2009-12-16 04:14:24 +08:00
// RUN: %clang_cc1 %s -verify -fsyntax-only
2008-03-03 11:28:21 +08:00
2013-12-19 07:30:06 +08:00
int f ( ) __attribute__ ( ( deprecated ) ) ; // expected-note 2 {{'f' has been explicitly marked deprecated here}}
2008-03-03 11:28:21 +08:00
void g ( ) __attribute__ ( ( deprecated ) ) ;
2013-12-19 07:30:06 +08:00
void g ( ) ; // expected-note {{'g' has been explicitly marked deprecated here}}
2008-03-03 11:28:21 +08:00
2013-12-19 07:30:06 +08:00
extern int var __attribute__ ( ( deprecated ) ) ; // expected-note {{'var' has been explicitly marked deprecated here}}
2008-03-03 11:28:21 +08:00
int a ( ) {
int ( * ptr ) ( ) = f ; // expected-warning {{'f' is deprecated}}
f ( ) ; // expected-warning {{'f' is deprecated}}
// test if attributes propagate to functions
g ( ) ; // expected-warning {{'g' is deprecated}}
return var ; // expected-warning {{'var' is deprecated}}
}
// test if attributes propagate to variables
2013-12-19 07:30:06 +08:00
extern int var ; // expected-note {{'var' has been explicitly marked deprecated here}}
2008-03-03 11:28:21 +08:00
int w ( ) {
2009-09-09 23:08:12 +08:00
return var ; // expected-warning {{'var' is deprecated}}
2008-03-03 11:28:21 +08:00
}
2009-02-14 16:27:44 +08:00
int old_fn ( ) __attribute__ ( ( deprecated ) ) ;
2013-12-19 07:30:06 +08:00
int old_fn ( ) ; // expected-note {{'old_fn' has been explicitly marked deprecated here}}
2009-02-14 16:27:44 +08:00
int ( * fn_ptr ) ( ) = old_fn ; // expected-warning {{'old_fn' is deprecated}}
int old_fn ( ) {
2009-02-15 09:38:09 +08:00
return old_fn ( ) + 1 ; // no warning, deprecated functions can use deprecated symbols.
2009-02-14 16:27:44 +08:00
}
2009-02-17 01:07:21 +08:00
struct foo {
2013-12-19 07:30:06 +08:00
int x __attribute__ ( ( deprecated ) ) ; // expected-note 3 {{'x' has been explicitly marked deprecated here}}
2009-02-17 01:07:21 +08:00
} ;
void test1 ( struct foo * F ) {
+ + F - > x ; // expected-warning {{'x' is deprecated}}
2011-06-30 05:51:31 +08:00
struct foo f1 = { . x = 17 } ; // expected-warning {{'x' is deprecated}}
struct foo f2 = { 17 } ; // expected-warning {{'x' is deprecated}}
2009-02-17 01:07:21 +08:00
}
2009-02-17 01:19:12 +08:00
2013-12-19 07:30:06 +08:00
typedef struct foo foo_dep __attribute__ ( ( deprecated ) ) ; // expected-note 12 {{'foo_dep' has been explicitly marked deprecated here}}
2009-02-17 06:07:16 +08:00
foo_dep * test2 ; // expected-warning {{'foo_dep' is deprecated}}
2009-10-26 06:21:57 +08:00
2011-12-17 08:36:09 +08:00
struct __attribute__ ( ( deprecated ,
2013-12-19 07:30:06 +08:00
invalid_attribute ) ) bar_dep ; // expected-warning {{unknown attribute 'invalid_attribute' ignored}} expected-note 2 {{'bar_dep' has been explicitly marked deprecated here}}
2009-10-26 06:21:57 +08:00
struct bar_dep * test3 ; // expected-warning {{'bar_dep' is deprecated}}
2009-10-26 06:31:57 +08:00
// These should not warn because the actually declaration itself is deprecated.
// rdar://6756623
foo_dep * test4 __attribute__ ( ( deprecated ) ) ;
struct bar_dep * test5 __attribute__ ( ( deprecated ) ) ;
2009-11-04 10:18:39 +08:00
typedef foo_dep test6 ( struct bar_dep * ) ; / / expected - warning { { ' foo_dep ' is deprecated } } \
// expected-warning {{'bar_dep' is deprecated}}
typedef foo_dep test7 ( struct bar_dep * ) __attribute__ ( ( deprecated ) ) ;
int test8 ( char * p ) {
p + = sizeof ( foo_dep ) ; // expected-warning {{'foo_dep' is deprecated}}
foo_dep * ptr ; // expected-warning {{'foo_dep' is deprecated}}
ptr = ( foo_dep * ) p ; // expected-warning {{'foo_dep' is deprecated}}
int func ( foo_dep * foo ) ; // expected-warning {{'foo_dep' is deprecated}}
return func ( ptr ) ;
}
foo_dep * test9 ( void ) __attribute__ ( ( deprecated ) ) ;
foo_dep * test9 ( void ) {
void * myalloc ( unsigned long ) ;
foo_dep * ptr
= ( foo_dep * )
myalloc ( sizeof ( foo_dep ) ) ;
return ptr ;
}
void test10 ( void ) __attribute__ ( ( deprecated ) ) ;
void test10 ( void ) {
if ( sizeof ( foo_dep ) = = sizeof ( void * ) ) {
}
foo_dep * localfunc ( void ) ;
foo_dep localvar ;
}
char test11 [ sizeof ( foo_dep ) ] __attribute__ ( ( deprecated ) ) ;
char test12 [ sizeof ( foo_dep ) ] ; // expected-warning {{'foo_dep' is deprecated}}
int test13 ( foo_dep * foo ) __attribute__ ( ( deprecated ) ) ;
int test14 ( foo_dep * foo ) ; // expected-warning {{'foo_dep' is deprecated}}
unsigned long test15 = sizeof ( foo_dep ) ; // expected-warning {{'foo_dep' is deprecated}}
unsigned long test16 __attribute__ ( ( deprecated ) )
= sizeof ( foo_dep ) ;
foo_dep test17 , // expected-warning {{'foo_dep' is deprecated}}
test18 __attribute__ ( ( deprecated ) ) ,
test19 ;
2010-10-23 07:36:17 +08:00
// rdar://problem/8518751
2013-12-19 07:30:06 +08:00
enum __attribute__ ( ( deprecated ) ) Test20 { // expected-note {{'Test20' has been explicitly marked deprecated here}}
test20_a __attribute__ ( ( deprecated ) ) , / / expected - note { { ' test20_a ' has been explicitly marked deprecated here } }
test20_b // expected-note {{'test20_b' has been explicitly marked deprecated here}}
2010-10-23 07:36:17 +08:00
} ;
void test20 ( ) {
enum Test20 f ; // expected-warning {{'Test20' is deprecated}}
f = test20_a ; // expected-warning {{'test20_a' is deprecated}}
2011-11-29 03:45:58 +08:00
f = test20_b ; // expected-warning {{'test20_b' is deprecated}}
2010-10-23 07:36:17 +08:00
}
2010-11-09 03:48:17 +08:00
char test21 [ __has_feature ( attribute_deprecated_with_message ) ? 1 : - 1 ] ;
2012-08-09 07:04:35 +08:00
struct test22 {
foo_dep a __attribute ( ( deprecated ) ) ;
foo_dep b ; // expected-warning {{'foo_dep' is deprecated}}
foo_dep c , d __attribute ( ( deprecated ) ) ; // expected-warning {{'foo_dep' is deprecated}}
__attribute ( ( deprecated ) ) foo_dep e , f ;
} ;
2013-07-16 10:07:49 +08:00
typedef int test23_ty __attribute ( ( deprecated ) ) ; // expected-note {{previous definition is here}}
2013-12-19 07:30:06 +08:00
typedef int test23_ty ; // expected-note {{'test23_ty' has been explicitly marked deprecated here}} expected-warning {{redefinition of typedef 'test23_ty' is a C11 feature}}
2013-07-16 10:07:49 +08:00
test23_ty test23_v ; // expected-warning {{'test23_ty' is deprecated}}