2013-08-13 05:20:55 +08:00
// RUN: %clang_cc1 -fsyntax-only -verify -Wconsumed -std=c++11 %s
2013-10-05 05:28:06 +08:00
# define CALLABLE_WHEN(...) __attribute__ ((callable_when(__VA_ARGS__)))
2013-10-12 07:03:26 +08:00
# define CONSUMABLE(state) __attribute__ ((consumable(state)))
# define SET_TYPESTATE(state) __attribute__ ((set_typestate(state)))
# define RETURN_TYPESTATE(state) __attribute__ ((return_typestate(state)))
2013-10-30 04:28:41 +08:00
# define TEST_TYPESTATE(state) __attribute__ ((test_typestate(state)))
2013-09-04 04:11:38 +08:00
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 {
2014-01-03 05:26:14 +08:00
void consumes ( ) __attribute__ ( ( set_typestate ( ) ) ) ; // expected-error {{'set_typestate' attribute takes one argument}}
bool testUnconsumed ( ) __attribute__ ( ( test_typestate ( ) ) ) ; // expected-error {{'test_typestate' attribute takes one argument}}
void callableWhen ( ) __attribute__ ( ( callable_when ( ) ) ) ; // expected-error {{'callable_when' attribute takes at least 1 argument}}
2013-08-13 05:20:55 +08:00
} ;
2013-10-12 07:03:26 +08:00
int var0 SET_TYPESTATE ( consumed ) ; // expected-warning {{'set_typestate' attribute only applies to methods}}
2013-10-30 04:28:41 +08:00
int var1 TEST_TYPESTATE ( consumed ) ; // expected-warning {{'test_typestate' attribute only applies to methods}}
2013-10-12 07:03:26 +08:00
int var2 CALLABLE_WHEN ( " consumed " ) ; // expected-warning {{'callable_when' 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-10-12 07:03:26 +08:00
void function0 ( ) SET_TYPESTATE ( consumed ) ; // expected-warning {{'set_typestate' attribute only applies to methods}}
2013-10-30 04:28:41 +08:00
void function1 ( ) TEST_TYPESTATE ( consumed ) ; // expected-warning {{'test_typestate' attribute only applies to methods}}
2013-10-12 07:03:26 +08:00
void function2 ( ) CALLABLE_WHEN ( " consumed " ) ; // expected-warning {{'callable_when' 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-10-30 04:28:41 +08:00
void callableWhen0 ( ) CALLABLE_WHEN ( " unconsumed " ) ;
void callableWhen1 ( ) CALLABLE_WHEN ( 42 ) ; // expected-error {{'callable_when' attribute requires a string}}
void callableWhen2 ( ) CALLABLE_WHEN ( " foo " ) ; // expected-warning {{'callable_when' attribute argument not supported: foo}}
void consumes ( ) SET_TYPESTATE ( consumed ) ;
bool testUnconsumed ( ) TEST_TYPESTATE ( consumed ) ;
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-10-18 06:53:04 +08:00
void returnTypestateTester2 ( AttrTester1 & Param RETURN_TYPESTATE ( unconsumed ) ) ;
2013-08-13 05:20:55 +08:00
class AttrTester2 {
2013-10-30 04:28:41 +08:00
void callableWhen ( ) CALLABLE_WHEN ( " unconsumed " ) ; // expected-warning {{consumed analysis attribute is attached to member of class 'AttrTester2' which isn't marked as consumable}}
void consumes ( ) SET_TYPESTATE ( consumed ) ; // expected-warning {{consumed analysis attribute is attached to member of class 'AttrTester2' which isn't marked as consumable}}
bool testUnconsumed ( ) TEST_TYPESTATE ( consumed ) ; // 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}}
2014-01-14 08:36:53 +08:00
class CONSUMABLE ( unconsumed )
__attribute__ ( ( consumable_auto_cast_state ) )
__attribute__ ( ( consumable_set_state_on_read ) )
Status {
} ;