annotate clang/test/SemaCXX/warn-consumed-parsing.cpp @ 222:81f6424ef0e3 llvm-original

LLVM original branch
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 18 Jul 2021 22:10:01 +0900
parents 1d019706d866
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -fsyntax-only -verify -Wconsumed -std=c++11 %s
anatofuz
parents:
diff changeset
2
anatofuz
parents:
diff changeset
3 #define CALLABLE_WHEN(...) __attribute__ ((callable_when(__VA_ARGS__)))
anatofuz
parents:
diff changeset
4 #define CONSUMABLE(state) __attribute__ ((consumable(state)))
anatofuz
parents:
diff changeset
5 #define SET_TYPESTATE(state) __attribute__ ((set_typestate(state)))
anatofuz
parents:
diff changeset
6 #define RETURN_TYPESTATE(state) __attribute__ ((return_typestate(state)))
anatofuz
parents:
diff changeset
7 #define TEST_TYPESTATE(state) __attribute__ ((test_typestate(state)))
anatofuz
parents:
diff changeset
8
anatofuz
parents:
diff changeset
9 // FIXME: This test is here because the warning is issued by the Consumed
anatofuz
parents:
diff changeset
10 // analysis, not SemaDeclAttr. The analysis won't run after an error
anatofuz
parents:
diff changeset
11 // has been issued. Once the attribute propagation for template
anatofuz
parents:
diff changeset
12 // instantiation has been fixed, this can be moved somewhere else and the
anatofuz
parents:
diff changeset
13 // definition can be removed.
anatofuz
parents:
diff changeset
14 int returnTypestateForUnconsumable() RETURN_TYPESTATE(consumed); // expected-warning {{return state set for an unconsumable type 'int'}}
anatofuz
parents:
diff changeset
15 int returnTypestateForUnconsumable() {
anatofuz
parents:
diff changeset
16 return 0;
anatofuz
parents:
diff changeset
17 }
anatofuz
parents:
diff changeset
18
anatofuz
parents:
diff changeset
19 class AttrTester0 {
anatofuz
parents:
diff changeset
20 void consumes() __attribute__ ((set_typestate())); // expected-error {{'set_typestate' attribute takes one argument}}
anatofuz
parents:
diff changeset
21 bool testUnconsumed() __attribute__ ((test_typestate())); // expected-error {{'test_typestate' attribute takes one argument}}
anatofuz
parents:
diff changeset
22 void callableWhen() __attribute__ ((callable_when())); // expected-error {{'callable_when' attribute takes at least 1 argument}}
anatofuz
parents:
diff changeset
23 };
anatofuz
parents:
diff changeset
24
anatofuz
parents:
diff changeset
25 int var0 SET_TYPESTATE(consumed); // expected-warning {{'set_typestate' attribute only applies to functions}}
anatofuz
parents:
diff changeset
26 int var1 TEST_TYPESTATE(consumed); // expected-warning {{'test_typestate' attribute only applies to}}
anatofuz
parents:
diff changeset
27 int var2 CALLABLE_WHEN("consumed"); // expected-warning {{'callable_when' attribute only applies to}}
anatofuz
parents:
diff changeset
28 int var3 CONSUMABLE(consumed); // expected-warning {{'consumable' attribute only applies to classes}}
anatofuz
parents:
diff changeset
29 int var4 RETURN_TYPESTATE(consumed); // expected-warning {{'return_typestate' attribute only applies to functions}}
anatofuz
parents:
diff changeset
30
anatofuz
parents:
diff changeset
31 void function0() SET_TYPESTATE(consumed); // expected-warning {{'set_typestate' attribute only applies to}}
anatofuz
parents:
diff changeset
32 void function1() TEST_TYPESTATE(consumed); // expected-warning {{'test_typestate' attribute only applies to}}
anatofuz
parents:
diff changeset
33 void function2() CALLABLE_WHEN("consumed"); // expected-warning {{'callable_when' attribute only applies to}}
anatofuz
parents:
diff changeset
34 void function3() CONSUMABLE(consumed); // expected-warning {{'consumable' attribute only applies to classes}}
anatofuz
parents:
diff changeset
35
anatofuz
parents:
diff changeset
36 class CONSUMABLE(unknown) AttrTester1 {
anatofuz
parents:
diff changeset
37 void callableWhen0() CALLABLE_WHEN("unconsumed");
anatofuz
parents:
diff changeset
38 void callableWhen1() CALLABLE_WHEN(42); // expected-error {{'callable_when' attribute requires a string}}
anatofuz
parents:
diff changeset
39 void callableWhen2() CALLABLE_WHEN("foo"); // expected-warning {{'callable_when' attribute argument not supported: foo}}
anatofuz
parents:
diff changeset
40 void callableWhen3() CALLABLE_WHEN(unconsumed);
anatofuz
parents:
diff changeset
41 void consumes() SET_TYPESTATE(consumed);
anatofuz
parents:
diff changeset
42 bool testUnconsumed() TEST_TYPESTATE(consumed);
anatofuz
parents:
diff changeset
43 };
anatofuz
parents:
diff changeset
44
anatofuz
parents:
diff changeset
45 AttrTester1 returnTypestateTester0() RETURN_TYPESTATE(not_a_state); // expected-warning {{'return_typestate' attribute argument not supported: 'not_a_state'}}
anatofuz
parents:
diff changeset
46 AttrTester1 returnTypestateTester1() RETURN_TYPESTATE(42); // expected-error {{'return_typestate' attribute requires an identifier}}
anatofuz
parents:
diff changeset
47
anatofuz
parents:
diff changeset
48 void returnTypestateTester2(AttrTester1 &Param RETURN_TYPESTATE(unconsumed));
anatofuz
parents:
diff changeset
49
anatofuz
parents:
diff changeset
50 class AttrTester2 {
anatofuz
parents:
diff changeset
51 void callableWhen() CALLABLE_WHEN("unconsumed"); // expected-warning {{consumed analysis attribute is attached to member of class 'AttrTester2' which isn't marked as consumable}}
anatofuz
parents:
diff changeset
52 void consumes() SET_TYPESTATE(consumed); // expected-warning {{consumed analysis attribute is attached to member of class 'AttrTester2' which isn't marked as consumable}}
anatofuz
parents:
diff changeset
53 bool testUnconsumed() TEST_TYPESTATE(consumed); // expected-warning {{consumed analysis attribute is attached to member of class 'AttrTester2' which isn't marked as consumable}}
anatofuz
parents:
diff changeset
54 };
anatofuz
parents:
diff changeset
55
anatofuz
parents:
diff changeset
56 class CONSUMABLE(42) AttrTester3; // expected-error {{'consumable' attribute requires an identifier}}
anatofuz
parents:
diff changeset
57
anatofuz
parents:
diff changeset
58
anatofuz
parents:
diff changeset
59 class CONSUMABLE(unconsumed)
anatofuz
parents:
diff changeset
60 __attribute__((consumable_auto_cast_state))
anatofuz
parents:
diff changeset
61 __attribute__((consumable_set_state_on_read))
anatofuz
parents:
diff changeset
62 Status {
anatofuz
parents:
diff changeset
63 };
anatofuz
parents:
diff changeset
64
anatofuz
parents:
diff changeset
65
anatofuz
parents:
diff changeset
66