summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRalf Habacker <ralf.habacker@freenet.de>2016-01-25 07:50:16 (GMT)
committerRalf Habacker <ralf.habacker@freenet.de>2016-09-09 05:34:40 (GMT)
commit13a513d629e86e8cc98d750f1d9e5741bbc8791a (patch)
tree18a451ec698a56ef1e5545bffa73fe3c3d05d146
parent368c43e09de3cce0e2faf1ab1db0bd9e495aebcc (diff)
Add c++11 code import test cases.
CCBUG:338649
-rw-r--r--test/import/cxx/cxx11-alternative-function-syntax.h14
l---------test/import/cxx/cxx11-constexpr.cpp1
-rw-r--r--test/import/cxx/cxx11-constexpr.h9
-rw-r--r--test/import/cxx/cxx11-explicit-overrides-and-final.h24
-rw-r--r--test/import/cxx/cxx11-extern-template.h4
-rw-r--r--test/import/cxx/cxx11-initializer-lists.h21
-rw-r--r--test/import/cxx/cxx11-lambda-functions-and-expressions.h4
-rw-r--r--test/import/cxx/cxx11-null-pointer-constant.h9
-rw-r--r--test/import/cxx/cxx11-object-construction-improvement.h32
-rw-r--r--test/import/cxx/cxx11-range-based-for-loop.h12
-rw-r--r--test/import/cxx/cxx11-strongly-typed-enumerations.h22
-rw-r--r--test/import/cxx/cxx11-type-inference.h29
-rw-r--r--test/import/cxx/cxx11-uniform-initialization.h31
13 files changed, 212 insertions, 0 deletions
diff --git a/test/import/cxx/cxx11-alternative-function-syntax.h b/test/import/cxx/cxx11-alternative-function-syntax.h
new file mode 100644
index 0000000..ee1411a
--- /dev/null
+++ b/test/import/cxx/cxx11-alternative-function-syntax.h
@@ -0,0 +1,14 @@
+// https://en.wikipedia.org/wiki/C%2B%2B11#Alternative_function_syntax
+
+// #1
+template<class Lhs, class Rhs>
+ auto adding_func(const Lhs &lhs, const Rhs &rhs) -> decltype(lhs+rhs) {return lhs + rhs;}
+
+// #2
+struct SomeStruct {
+ auto func_name(int x, int y) -> int;
+};
+
+auto SomeStruct::func_name(int x, int y) -> int {
+ return x + y;
+}
diff --git a/test/import/cxx/cxx11-constexpr.cpp b/test/import/cxx/cxx11-constexpr.cpp
new file mode 120000
index 0000000..d4a7d10
--- /dev/null
+++ b/test/import/cxx/cxx11-constexpr.cpp
@@ -0,0 +1 @@
+cxx11-constexpr.h \ No newline at end of file
diff --git a/test/import/cxx/cxx11-constexpr.h b/test/import/cxx/cxx11-constexpr.h
new file mode 100644
index 0000000..527fe01
--- /dev/null
+++ b/test/import/cxx/cxx11-constexpr.h
@@ -0,0 +1,9 @@
+// https://en.wikipedia.org/wiki/C%2B%2B11#constexpr_.E2.80.93_Generalized_constant_expressions
+
+// #1
+constexpr int get_five() {return 5;}
+int some_value[get_five() + 7]; // Create an array of 12 integers. Legal C++11
+
+// #2
+constexpr double earth_gravitational_acceleration = 9.8;
+constexpr double moon_gravitational_acceleration = earth_gravitational_acceleration / 6.0;
diff --git a/test/import/cxx/cxx11-explicit-overrides-and-final.h b/test/import/cxx/cxx11-explicit-overrides-and-final.h
new file mode 100644
index 0000000..0e241b9
--- /dev/null
+++ b/test/import/cxx/cxx11-explicit-overrides-and-final.h
@@ -0,0 +1,24 @@
+// https://en.wikipedia.org/wiki/C%2B%2B11#Explicit_overrides_and_final
+
+// #1
+struct Base {
+ virtual void some_func(float);
+};
+
+struct Derived : Base {
+ virtual void some_func(int) override; // ill-formed - doesn't override a base class method
+};
+
+// #2
+struct Base1 final { };
+
+struct Derived1 : Base1 { }; // ill-formed because the class Base1 has been marked final
+
+// #3
+struct Base2 {
+ virtual void f() final;
+};
+
+struct Derived2 : Base2 {
+ void f(); // ill-formed because the virtual function Base2::f has been marked final
+};
diff --git a/test/import/cxx/cxx11-extern-template.h b/test/import/cxx/cxx11-extern-template.h
new file mode 100644
index 0000000..da72b39
--- /dev/null
+++ b/test/import/cxx/cxx11-extern-template.h
@@ -0,0 +1,4 @@
+// https://en.wikipedia.org/wiki/C%2B%2B11#Extern_template
+
+// #1
+extern template class std::vector<MyClass>;
diff --git a/test/import/cxx/cxx11-initializer-lists.h b/test/import/cxx/cxx11-initializer-lists.h
new file mode 100644
index 0000000..4d25638
--- /dev/null
+++ b/test/import/cxx/cxx11-initializer-lists.h
@@ -0,0 +1,21 @@
+// https://en.wikipedia.org/wiki/C%2B%2B11#Initializer_lists
+
+// #1
+class SequenceClass {
+public:
+ SequenceClass(std::initializer_list<int> list);
+};
+
+// #2
+SequenceClass some_var = {1, 4, 5, 6};
+
+// #3
+void function_name(std::initializer_list<float> list);
+
+function_name({1.0f, -3.45f, -0.4f});
+
+
+// #4
+std::vector<std::string> v = { "xyzzy", "plugh", "abracadabra" };
+std::vector<std::string> v({ "xyzzy", "plugh", "abracadabra" });
+std::vector<std::string> v{ "xyzzy", "plugh", "abracadabra" }; // see "Uniform initialization" below
diff --git a/test/import/cxx/cxx11-lambda-functions-and-expressions.h b/test/import/cxx/cxx11-lambda-functions-and-expressions.h
new file mode 100644
index 0000000..5de3d2e
--- /dev/null
+++ b/test/import/cxx/cxx11-lambda-functions-and-expressions.h
@@ -0,0 +1,4 @@
+// https://en.wikipedia.org/wiki/C%2B%2B11#Lambda_functions_and_expressions
+
+// #1
+[](int x, int y) -> int { return x + y; }
diff --git a/test/import/cxx/cxx11-null-pointer-constant.h b/test/import/cxx/cxx11-null-pointer-constant.h
new file mode 100644
index 0000000..bec7395
--- /dev/null
+++ b/test/import/cxx/cxx11-null-pointer-constant.h
@@ -0,0 +1,9 @@
+// https://en.wikipedia.org/wiki/C%2B%2B11#Null_pointer_constant
+
+// #1
+char *pc = nullptr; // OK
+int *pi = nullptr; // OK
+bool b = nullptr; // OK. b is false.
+//int i = nullptr; // error
+
+foo(nullptr); // calls foo(nullptr_t), not foo(int);
diff --git a/test/import/cxx/cxx11-object-construction-improvement.h b/test/import/cxx/cxx11-object-construction-improvement.h
new file mode 100644
index 0000000..7682546
--- /dev/null
+++ b/test/import/cxx/cxx11-object-construction-improvement.h
@@ -0,0 +1,32 @@
+// https://en.wikipedia.org/wiki/C%2B%2B11#Object_construction_improvement
+
+// #1
+class SomeType {
+ int number;
+
+public:
+ SomeType(int new_number) : number(new_number) {}
+ SomeType() : SomeType(42) {}
+};
+
+// #2
+class BaseClass {
+public:
+ BaseClass(int value);
+};
+
+class DerivedClass : public BaseClass {
+public:
+ using BaseClass::BaseClass;
+};
+
+// #3
+class SomeClass {
+public:
+ SomeClass() {}
+ explicit SomeClass(int new_value) : value(new_value) {}
+
+private:
+ int value = 5;
+};
+
diff --git a/test/import/cxx/cxx11-range-based-for-loop.h b/test/import/cxx/cxx11-range-based-for-loop.h
new file mode 100644
index 0000000..4b1192d
--- /dev/null
+++ b/test/import/cxx/cxx11-range-based-for-loop.h
@@ -0,0 +1,12 @@
+// https://en.wikipedia.org/wiki/C%2B%2B11#Range-based_for_loop
+
+// #1
+int my_array[5] = {1, 2, 3, 4, 5};
+// double the value of each element in my_array:
+for (int &x : my_array) {
+ x *= 2;
+}
+// similar but also using type inference for array elements
+for (auto &x : my_array) {
+ x *= 2;
+}
diff --git a/test/import/cxx/cxx11-strongly-typed-enumerations.h b/test/import/cxx/cxx11-strongly-typed-enumerations.h
new file mode 100644
index 0000000..8e9fdd7
--- /dev/null
+++ b/test/import/cxx/cxx11-strongly-typed-enumerations.h
@@ -0,0 +1,22 @@
+// https://en.wikipedia.org/wiki/C%2B%2B11#Strongly_typed_enumerations
+
+// #1
+enum class Enumeration {
+ Val1,
+ Val2,
+ Val3 = 100,
+ Val4 // = 101
+};
+
+// #2
+enum class Enum2 : unsigned int {Val1, Val2};
+
+// #3
+enum Enum3 : unsigned long {Val1 = 1, Val2};
+
+// #4
+//enum Enum1; // Illegal in C++03 and C++11; the underlying type cannot be determined.
+enum Enum2 : unsigned int; // Legal in C++11, the underlying type is explicitly specified.
+enum class Enum3; // Legal in C++11, the underlying type is int.
+enum class Enum4 : unsigned int; // Legal in C++11.
+//enum Enum2 : unsigned short; // Illegal in C++11, because Enum2 was previously declared with a different underlying type. \ No newline at end of file
diff --git a/test/import/cxx/cxx11-type-inference.h b/test/import/cxx/cxx11-type-inference.h
new file mode 100644
index 0000000..2274c5f
--- /dev/null
+++ b/test/import/cxx/cxx11-type-inference.h
@@ -0,0 +1,29 @@
+// https://en.wikipedia.org/wiki/C%2B%2B11#Type_inference
+
+// #1
+auto some_strange_callable_type = std::bind(&some_function, _2, _1, some_object);
+auto other_variable = 5;
+
+// #2
+int some_int;
+decltype(some_int) other_integer_variable = 5;
+
+// #3
+for (auto itr = myvec.cbegin(); itr != myvec.cend(); ++itr) ;
+
+// #4
+for (auto& x : myvec) ;
+
+// #5
+#include <vector>
+int main() {
+ const std::vector<int> v(1);
+ auto a = v[0]; // a has type int
+ decltype(v[1]) b = 1; // b has type const int&, the return type of
+ // std::vector<int>::operator[](size_type) const
+ auto c = 0; // c has type int
+ auto d = c; // d has type int
+ decltype(c) e; // e has type int, the type of the entity named by c
+ decltype((c)) f = c; // f has type int&, because (c) is an lvalue
+ decltype(0) g; // g has type int, because 0 is an rvalue
+}
diff --git a/test/import/cxx/cxx11-uniform-initialization.h b/test/import/cxx/cxx11-uniform-initialization.h
new file mode 100644
index 0000000..02eb4d6
--- /dev/null
+++ b/test/import/cxx/cxx11-uniform-initialization.h
@@ -0,0 +1,31 @@
+// https://en.wikipedia.org/wiki/C%2B%2B11#Uniform_initialization
+
+// #1
+struct BasicStruct {
+ int x;
+ double y;
+};
+
+struct AltStruct {
+ AltStruct(int x, double y) : x_{x}, y_{y} {}
+
+ private:
+ int x_;
+ double y_;
+};
+
+BasicStruct var1{5, 3.2};
+AltStruct var2{2, 4.3};
+
+// #2
+struct IdString {
+ std::string name;
+ int identifier;
+};
+
+IdString get_string() {
+ return {"foo", 42}; //Note the lack of explicit type.
+}
+
+// #3
+std::vector<int> the_vec{4};