2013-08-13 05:20:55 +08:00
// RUN: %clang_cc1 -fsyntax-only -verify -Wconsumed -std=c++11 %s
2013-09-04 04:11:38 +08:00
# define CALLABLE_WHEN_UNCONSUMED __attribute__ ((callable_when_unconsumed))
2013-09-06 09:28:43 +08:00
# define CONSUMABLE(state) __attribute__ ((consumable(state)))
2013-09-04 04:11:38 +08:00
# define CONSUMES __attribute__ ((consumes))
2013-09-06 09:28:43 +08:00
# define RETURN_TYPESTATE(state) __attribute__ ((return_typestate(state)))
2013-09-04 04:11:38 +08:00
# define TESTS_UNCONSUMED __attribute__ ((tests_unconsumed))
2013-09-04 06:35:53 +08:00
// FIXME: This test is here because the warning is issued by the Consumed
// analysis, not SemaDeclAttr. The analysis won't run after an error
// has been issued. Once the attribute propagation for template
// instantiation has been fixed, this can be moved somewhere else and the
// definition can be removed.
2013-09-04 04:11:38 +08:00
int returnTypestateForUnconsumable ( ) RETURN_TYPESTATE ( consumed ) ; // expected-warning {{return state set for an unconsumable type 'int'}}
int returnTypestateForUnconsumable ( ) {
return 0 ;
}
2013-08-13 05:20:55 +08:00
class AttrTester0 {
2013-09-04 04:11:38 +08:00
void consumes ( ) __attribute__ ( ( consumes ( 42 ) ) ) ; // expected-error {{attribute takes no arguments}}
bool testsUnconsumed ( ) __attribute__ ( ( tests_unconsumed ( 42 ) ) ) ; // expected-error {{attribute takes no arguments}}
void callableWhenUnconsumed ( ) __attribute__ ( ( callable_when_unconsumed ( 42 ) ) ) ; // expected-error {{attribute takes no arguments}}
2013-08-13 05:20:55 +08:00
} ;
int var0 CONSUMES ; // expected-warning {{'consumes' attribute only applies to methods}}
int var1 TESTS_UNCONSUMED ; // expected-warning {{'tests_unconsumed' attribute only applies to methods}}
int var2 CALLABLE_WHEN_UNCONSUMED ; // expected-warning {{'callable_when_unconsumed' attribute only applies to methods}}
2013-09-06 09:28:43 +08:00
int var3 CONSUMABLE ( consumed ) ; // expected-warning {{'consumable' attribute only applies to classes}}
2013-09-04 04:11:38 +08:00
int var4 RETURN_TYPESTATE ( consumed ) ; // expected-warning {{'return_typestate' attribute only applies to functions}}
2013-08-13 05:20:55 +08:00
2013-08-31 06:56:34 +08:00
void function0 ( ) CONSUMES ; // expected-warning {{'consumes' attribute only applies to methods}}
void function1 ( ) TESTS_UNCONSUMED ; // expected-warning {{'tests_unconsumed' attribute only applies to methods}}
void function2 ( ) CALLABLE_WHEN_UNCONSUMED ; // expected-warning {{'callable_when_unconsumed' attribute only applies to methods}}
2013-09-06 09:28:43 +08:00
void function3 ( ) CONSUMABLE ( consumed ) ; // expected-warning {{'consumable' attribute only applies to classes}}
2013-08-13 05:20:55 +08:00
2013-09-06 09:28:43 +08:00
class CONSUMABLE ( unknown ) AttrTester1 {
2013-08-31 06:56:34 +08:00
void callableWhenUnconsumed ( ) CALLABLE_WHEN_UNCONSUMED ;
void consumes ( ) CONSUMES ;
bool testsUnconsumed ( ) TESTS_UNCONSUMED ;
2013-08-13 05:20:55 +08:00
} ;
2013-09-12 03:47:58 +08:00
AttrTester1 returnTypestateTester0 ( ) RETURN_TYPESTATE ( not_a_state ) ; // expected-warning {{'return_typestate' attribute argument not supported: 'not_a_state'}}
2013-09-04 04:11:38 +08:00
AttrTester1 returnTypestateTester1 ( ) RETURN_TYPESTATE ( 42 ) ; // expected-error {{'return_typestate' attribute requires an identifier}}
2013-08-13 05:20:55 +08:00
class AttrTester2 {
2013-09-04 04:11:38 +08:00
void callableWhenUnconsumed ( ) CALLABLE_WHEN_UNCONSUMED ; // expected-warning {{consumed analysis attribute is attached to member of class 'AttrTester2' which isn't marked as consumable}}
void consumes ( ) CONSUMES ; // expected-warning {{consumed analysis attribute is attached to member of class 'AttrTester2' which isn't marked as consumable}}
bool testsUnconsumed ( ) TESTS_UNCONSUMED ; // expected-warning {{consumed analysis attribute is attached to member of class 'AttrTester2' which isn't marked as consumable}}
2013-08-13 05:20:55 +08:00
} ;
2013-09-06 09:28:43 +08:00
class CONSUMABLE ( 42 ) AttrTester3 ; // expected-error {{'consumable' attribute requires an identifier}}