-
Notifications
You must be signed in to change notification settings - Fork 363
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #556 from guwirth/enhancement/more_cpp11_tests
some more C++11 and C++14 tests...
- Loading branch information
Showing
35 changed files
with
428 additions
and
25 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
cxx-squid/src/test/resources/parser/own/C++11/attributes.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
int [[attr1]] i [[attr2, attr3]]; | ||
int [[attr4]] a [10] [[attr5]]; | ||
|
||
[[ noreturn ]] void f() { | ||
throw "error"; | ||
} | ||
|
||
[[attr1]] void [[attr2]] func(int [[attr3]] p) [[attr4]] | ||
{ | ||
//@todo | ||
// [[attr4(arg1, arg2)]] if (cond) | ||
// { | ||
// [[vendor::attr5]] return i; | ||
// } | ||
} | ||
|
||
//@todo | ||
//[[attr1]] class C [[attr2]] | ||
//{ | ||
// | ||
// C::C [[attr6]] () [[attr7]]; | ||
// | ||
//} [[attr3]] c [[attr4]], d [[attr5]]; | ||
// attr1 applies to declarator-ids c, d | ||
// attr2 applies to the definition of class C | ||
// attr3 applies to type C | ||
// attr4 applies to declarator-id c | ||
// attr5 applies to declarator-id d | ||
|
||
[[attr1]] int [[attr2]] * [[attr3]] ( * [[attr4]] * [[attr5]] f [[attr6]] ) ( ) [[attr7]], e[[attr8]]; | ||
// attr1 applies to the pointer-to-pointer to function f, and to e | ||
// attr2 applies to the return type of int | ||
// attr3 applies to the return type * | ||
// attr4 applies to the first * in the pointer-to-pointer to f | ||
// attr5 applies to the second * in the pointer-to-pointer to f | ||
// attr6 applies to the function variable f | ||
// attr7 applies to the function (**f)() | ||
// attr8 applies to e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
auto i = 0; // i is an 'int' | ||
const auto d = 0.0; // d is a 'const double' | ||
auto b = bind( &func, _1, _2, 13 ); // 'b' cannot (portably) be declared! | ||
|
||
auto test() | ||
{ | ||
for ( auto it = vec.begin() ; it != vec.end() ; ++it ) {} | ||
return true; | ||
} |
31 changes: 31 additions & 0 deletions
31
cxx-squid/src/test/resources/parser/own/C++11/const-expr.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 29 additions & 13 deletions
42
cxx-squid/src/test/resources/parser/own/C++11/decl-type.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,48 @@ | ||
#include <iostream> | ||
#include <vector> | ||
|
||
struct A { | ||
double x; | ||
double x; | ||
}; | ||
const A* a = new A{ 0 }; | ||
|
||
decltype(a->x) x3; // type of x3 is double (declared type) | ||
decltype((a->x)) x4 = x3; // type of x4 is const double& (lvalue expression) | ||
|
||
auto add_int( int a, int b ) -> int { return a + b; } | ||
|
||
template <class T, class U> | ||
auto add(T t, U u) -> decltype(t + u); // return type depends on template parameters | ||
|
||
int example() | ||
{ | ||
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 | ||
} | ||
|
||
int main() | ||
{ | ||
int i = 33; | ||
decltype(i) j = i * 2; | ||
int i = 33; | ||
decltype(i) j = i * 2; | ||
|
||
std::cout << "i = " << i << ", " | ||
<< "j = " << j << '\n'; | ||
std::cout << "i = " << i << ", " | ||
<< "j = " << j << '\n'; | ||
|
||
auto f = [](int a, int b) -> int { | ||
return a*b; | ||
}; | ||
auto f = [](int a, int b) -> int { | ||
return a*b; | ||
}; | ||
|
||
decltype(f) f2 = f; // the type of a lambda function is unique and unnamed | ||
i = f(2, 2); | ||
j = f2(3, 3); | ||
decltype(f) f2 = f; // the type of a lambda function is unique and unnamed | ||
i = f(2, 2); | ||
j = f2(3, 3); | ||
|
||
std::cout << "i = " << i << ", " | ||
<< "j = " << j << '\n'; | ||
std::cout << "i = " << i << ", " | ||
<< "j = " << j << '\n'; | ||
} |
30 changes: 30 additions & 0 deletions
30
cxx-squid/src/test/resources/parser/own/C++11/delegating-constructors.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
struct Class : public Base | ||
{ | ||
unsigned char x; | ||
unsigned char y; | ||
|
||
Class ( int x ) | ||
: Base ( 123 ), // initialize base class | ||
x ( x ), // x (member) is initialized with x (parameter) | ||
y { 0 } // y initialized to 0 | ||
{} // empty compound statement | ||
|
||
Class ( double a ) | ||
: y ( a+1 ), | ||
x ( y ) // x will be initialized before y, its value here is indeterminate | ||
{} // base class constructor does not appear in the list, it is | ||
// default-initialized (not the same as if Base() were used, which is value-init) | ||
|
||
Class() | ||
try // function-try block begins before the function body, which includes init list | ||
: Base ( 789 ), | ||
x ( 0 ), | ||
y ( 0 ) | ||
{ | ||
// ... | ||
} | ||
catch (...) | ||
{ | ||
// exception occurred on initialization | ||
} | ||
}; |
8 changes: 8 additions & 0 deletions
8
cxx-squid/src/test/resources/parser/own/C++11/explicit-conversion-operators.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
struct SomeType | ||
{ | ||
// implicit conversion | ||
operator int() const { return 7; } | ||
|
||
// explicit conversion | ||
explicit operator int*() const { return nullptr; } | ||
}; |
16 changes: 16 additions & 0 deletions
16
cxx-squid/src/test/resources/parser/own/C++11/extended-friend-declarations.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class X1 { | ||
friend C; // OK: Class C is a friend | ||
}; | ||
|
||
class X2 { | ||
friend Ct; // OK: class C is a friend | ||
friend D; // error: no type-name D in scope | ||
friend class D; // OK: elaborated-type-specifier declares new class | ||
}; | ||
|
||
template <typename T> class R { | ||
friend T; | ||
}; | ||
|
||
R<C> rc; // class C is a friend of R<C> | ||
R<int> ri; // OK: "friend int" is ignored |
1 change: 1 addition & 0 deletions
1
cxx-squid/src/test/resources/parser/own/C++11/extern-template.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
extern template class std::vector<MyClass>; |
3 changes: 3 additions & 0 deletions
3
cxx-squid/src/test/resources/parser/own/C++11/final-specifier.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
cxx-squid/src/test/resources/parser/own/C++11/forward-enum-declarations.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// forward declaration of enums | ||
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. |
7 changes: 7 additions & 0 deletions
7
cxx-squid/src/test/resources/parser/own/C++11/inheriting-constructors.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class SomeType { | ||
int number; | ||
|
||
public: | ||
SomeType(int new_number) : number(new_number) {} | ||
SomeType() : SomeType(42) {} | ||
}; |
19 changes: 19 additions & 0 deletions
19
cxx-squid/src/test/resources/parser/own/C++11/inline-namespace.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
namespace L { | ||
inline namespace M { | ||
inline namespace N { | ||
/*...*/ | ||
} | ||
} | ||
} | ||
|
||
// if you compile the following code the output of the resulting executable is 1 | ||
namespace A { | ||
inline namespace B { | ||
int foo(bool) { return 1; } | ||
} | ||
int foo(int) { return 2; } | ||
} | ||
|
||
int main(void) { | ||
return A::foo(true); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
cxx-squid/src/test/resources/parser/own/C++11/long-long-int.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
long long i = 0; | ||
long long int j = 0; | ||
|
||
void func1(long long p) {} | ||
void func2(long long int p) {} | ||
|
||
long long func3() { return 0; } | ||
long long int func4() { return 0; } | ||
|
||
//@todo | ||
//auto func5(long long p) -> long long { return 0; } | ||
//auto func6(long long int p) -> long long int { return 0; } |
4 changes: 4 additions & 0 deletions
4
cxx-squid/src/test/resources/parser/own/C++11/member-function-default.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
struct SomeType { | ||
SomeType() = default; //The default constructor is explicitly stated. | ||
SomeType(OtherType value); | ||
}; |
18 changes: 18 additions & 0 deletions
18
cxx-squid/src/test/resources/parser/own/C++11/member-function-delete.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// The following type is non-copyable: | ||
struct NonCopyable { | ||
NonCopyable() = default; | ||
NonCopyable(const NonCopyable&) = delete; | ||
NonCopyable & operator=(const NonCopyable&) = delete; | ||
}; | ||
|
||
// The = delete specifier can be used to prohibit calling any function, which can be used to disallow calling a member function with particular parameters. For example: | ||
struct NoInt { | ||
void f(double i); | ||
void f(int) = delete; | ||
}; | ||
|
||
// This can be generalized to disallow calling the function with any type other than double as follows: | ||
struct OnlyDouble { | ||
void f(double d); | ||
template<class T> void f(T) = delete; | ||
}; |
7 changes: 7 additions & 0 deletions
7
cxx-squid/src/test/resources/parser/own/C++11/new-string-literals.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
char* txt1 = u8"I'm a UTF-8 string."; | ||
char16_t* txt2 = u"This is a UTF-16 string."; | ||
char32_t* txt3 = U"This is a UTF-32 string."; | ||
|
||
char* txt1 = u8"This is a Unicode Character: \u2018."; | ||
char16_t* txt2 = u"This is a bigger Unicode Character: \u2018."; | ||
char32_t* txt3 = U"This is a Unicode Character: \U00002018."; |
10 changes: 10 additions & 0 deletions
10
cxx-squid/src/test/resources/parser/own/C++11/non-static-data-member-initializers.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class SomeClass { | ||
public: | ||
SomeClass() {} | ||
explicit SomeClass(int new_value) : value(new_value) {} | ||
|
||
private: | ||
int value = 5; | ||
MyWidget * m_myWidget = 0; | ||
double d = 1.0; | ||
}; |
Oops, something went wrong.