summaryrefslogtreecommitdiff
path: root/clang/test/SemaCXX/member-init.cpp
diff options
context:
space:
mode:
authorCarlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au>2012-10-15 17:10:06 +1100
committerCarlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au>2012-10-15 17:10:06 +1100
commitbe1de4be954c80875ad4108e0a33e8e131b2f2c0 (patch)
tree1fbbecf276bf7c7bdcbb4dd446099d6d90eaa516 /clang/test/SemaCXX/member-init.cpp
parentc4626a62754862d20b41e8a46a3574264ea80e6d (diff)
parentf1bd2e48c5324d3f7cda4090c87f8a5b6f463ce2 (diff)
Merge branch 'master' of ssh://bitbucket.org/czan/honours
Diffstat (limited to 'clang/test/SemaCXX/member-init.cpp')
-rw-r--r--clang/test/SemaCXX/member-init.cpp75
1 files changed, 75 insertions, 0 deletions
diff --git a/clang/test/SemaCXX/member-init.cpp b/clang/test/SemaCXX/member-init.cpp
new file mode 100644
index 0000000..c93c85b
--- /dev/null
+++ b/clang/test/SemaCXX/member-init.cpp
@@ -0,0 +1,75 @@
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -verify -std=c++11 -Wall %s
+
+struct Bitfield {
+ int n : 3 = 7; // expected-error {{bitfield member cannot have an in-class initializer}}
+};
+
+int a;
+class NoWarning {
+ int &n = a;
+public:
+ int &GetN() { return n; }
+};
+
+bool b();
+int k;
+struct Recurse {
+ int &n = b() ? Recurse().n : k; // ok
+};
+
+struct UnknownBound {
+ int as[] = { 1, 2, 3 }; // expected-error {{array bound cannot be deduced from an in-class initializer}}
+ int bs[4] = { 4, 5, 6, 7 };
+ int cs[] = { 8, 9, 10 }; // expected-error {{array bound cannot be deduced from an in-class initializer}}
+};
+
+template<int n> struct T { static const int B; };
+template<> struct T<2> { template<int C, int D> using B = int; };
+const int C = 0, D = 0;
+struct S {
+ int as[] = { decltype(x)::B<C, D>(0) }; // expected-error {{array bound cannot be deduced from an in-class initializer}}
+ T<sizeof(as) / sizeof(int)> x; // expected-error {{requires a type specifier}}
+ // test that we handle invalid array bound deductions without crashing when the declarator name is itself invalid
+ operator int[](){}; // expected-error {{'operator int' cannot be the name of a variable or data member}} \
+ // expected-error {{array bound cannot be deduced from an in-class initializer}}
+};
+
+struct ThrowCtor { ThrowCtor(int) noexcept(false); };
+struct NoThrowCtor { NoThrowCtor(int) noexcept(true); };
+
+struct Throw { ThrowCtor tc = 42; };
+struct NoThrow { NoThrowCtor tc = 42; };
+
+static_assert(!noexcept(Throw()), "incorrect exception specification");
+static_assert(noexcept(NoThrow()), "incorrect exception specification");
+
+struct CheckExcSpec {
+ CheckExcSpec() noexcept(true) = default;
+ int n = 0;
+};
+struct CheckExcSpecFail {
+ CheckExcSpecFail() noexcept(true) = default; // expected-error {{exception specification of explicitly defaulted default constructor does not match the calculated one}}
+ ThrowCtor tc = 123;
+};
+
+struct TypedefInit {
+ typedef int A = 0; // expected-error {{illegal initializer}}
+};
+
+// PR10578 / <rdar://problem/9877267>
+namespace PR10578 {
+ template<typename T>
+ struct X {
+ X() {
+ T* x = 1; // expected-error{{cannot initialize a variable of type 'int *' with an rvalue of type 'int'}}
+ }
+ };
+
+ struct Y : X<int> {
+ Y();
+ };
+
+ Y::Y() try { // expected-note{{in instantiation of member function 'PR10578::X<int>::X' requested here}}
+ } catch(...) {
+ }
+}