Patch by Chris Wailes <chris.wailes@gmail.com>.
Reviewed by delesley, dblaikie.
Add the annotations and code needed to support a basic 'consumed' analysis.
Summary:
This new analysis is based on academic literature on linear types. It tracks
the state of a value, either as unconsumed, consumed, or unknown. Methods are
then annotated as CallableWhenUnconsumed, and when an annotated method is
called while the value is in the 'consumed' state a warning is issued. A value
may be tested in the conditional statement of an if-statement; when this occurs
we know the state of the value in the different branches, and this information
is added to our analysis. The code is still highly experimental, and the names
of annotations or the algorithm may be subject to change.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188206 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/SemaCXX/warn-consumed-parsing.cpp b/test/SemaCXX/warn-consumed-parsing.cpp
new file mode 100644
index 0000000..23df1d1
--- /dev/null
+++ b/test/SemaCXX/warn-consumed-parsing.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wconsumed -std=c++11 %s
+
+#define CONSUMES __attribute__ ((consumes))
+#define TESTS_UNCONSUMED __attribute__ ((tests_unconsumed))
+#define CALLABLE_WHEN_UNCONSUMED __attribute__ ((callable_when_unconsumed))
+
+class AttrTester0 {
+ void Consumes(void) __attribute__ ((consumes(42))); // expected-error {{attribute takes no arguments}}
+ bool TestsUnconsumed(void) __attribute__ ((tests_unconsumed(42))); // expected-error {{attribute takes no arguments}}
+ void CallableWhenUnconsumed(void)
+ __attribute__ ((callable_when_unconsumed(42))); // expected-error {{attribute takes no arguments}}
+};
+
+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}}
+
+void function0(void) CONSUMES; // expected-warning {{'consumes' attribute only applies to methods}}
+void function1(void) TESTS_UNCONSUMED; // expected-warning {{'tests_unconsumed' attribute only applies to methods}}
+void function2(void) CALLABLE_WHEN_UNCONSUMED; // expected-warning {{'callable_when_unconsumed' attribute only applies to methods}}
+
+class AttrTester1 {
+ void consumes(void) CONSUMES;
+ bool testsUnconsumed(void) TESTS_UNCONSUMED;
+};
+
+class AttrTester2 {
+ void callableWhenUnconsumed(void) CALLABLE_WHEN_UNCONSUMED;
+};