diff options
author | Sebastian Redl <sebastian.redl@getdesigned.at> | 2011-02-05 19:23:19 +0000 |
---|---|---|
committer | Sebastian Redl <sebastian.redl@getdesigned.at> | 2011-02-05 19:23:19 +0000 |
commit | f677ea3cc9598d9952ad7ffab5fb322ba4c5be31 (patch) | |
tree | 6fd84ac5d0d6b1128c4f53e7a36f08b89996f47b /test/CXX | |
parent | 57ca32bbf03d30b8867f6c07f1a3e42484bbfec7 (diff) |
Basic implementation of inherited constructors. Only generates declarations, and probably only works for very basic use cases.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124970 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CXX')
-rw-r--r-- | test/CXX/special/class.inhctor/elsewhere.cpp | 31 | ||||
-rw-r--r-- | test/CXX/special/class.inhctor/p3.cpp | 30 | ||||
-rw-r--r-- | test/CXX/special/class.inhctor/p7.cpp | 18 |
3 files changed, 79 insertions, 0 deletions
diff --git a/test/CXX/special/class.inhctor/elsewhere.cpp b/test/CXX/special/class.inhctor/elsewhere.cpp new file mode 100644 index 0000000000..82944d65df --- /dev/null +++ b/test/CXX/special/class.inhctor/elsewhere.cpp @@ -0,0 +1,31 @@ +// RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s + +// Tests related to constructor inheriting, but not specified in [class.inhctor] + +// [namespace.udecl]p8: +// A using-declaration for a class member shall be a member-declaration. + +struct B1 { + B1(int); +}; + +using B1::B1; // expected-error {{using declaration can not refer to class member}} + +// C++0x [namespace.udecl]p10: +// A using-declaration is a declaration and can therefore be used repeatedly +// where (and only where) multiple declarations are allowed. + +struct I1 : B1 { + using B1::B1; // expected-note {{previous using declaration}} + using B1::B1; // expected-error {{redeclaration of using decl}} +}; + +// C++0x [namespace.udecl]p3: +// In a using declaration used as a member-declaration, the nested-name- +// specifier shall name a base class of the class being defined. +// If such a using-declaration names a constructor, the nested-name-specifier +// shall name a direct base class of the class being defined. + +struct D1 : I1 { + using B1::B1; // expected-error {{'B1' is not a direct base of 'D1', can not inherit constructors}} +}; diff --git a/test/CXX/special/class.inhctor/p3.cpp b/test/CXX/special/class.inhctor/p3.cpp new file mode 100644 index 0000000000..021f701ab4 --- /dev/null +++ b/test/CXX/special/class.inhctor/p3.cpp @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s + +struct B1 { + B1(int); + B1(int, int); +}; +struct D1 : B1 { + using B1::B1; +}; +D1 d1a(1), d1b(1, 1); + +D1 fd1() { return 1; } + +struct B2 { + explicit B2(int, int = 0, int = 0); +}; +struct D2 : B2 { // expected-note {{candidate constructor}} + using B2::B2; +}; +D2 d2a(1), d2b(1, 1), d2c(1, 1, 1); + +D2 fd2() { return 1; } // expected-error {{no viable conversion}} + +struct B3 { + B3(void*); // expected-note {{inherited from here}} +}; +struct D3 : B3 { // expected-note {{candidate constructor}} + using B3::B3; // expected-note {{candidate constructor (inherited)}} +}; +D3 fd3() { return 1; } // expected-error {{no viable conversion}} diff --git a/test/CXX/special/class.inhctor/p7.cpp b/test/CXX/special/class.inhctor/p7.cpp new file mode 100644 index 0000000000..3ad761f08b --- /dev/null +++ b/test/CXX/special/class.inhctor/p7.cpp @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s + +// Straight from the standard +struct B1 { + B1(int); // expected-note {{previous constructor}} +}; +struct B2 { + B2(int); // expected-note {{conflicting constructor}} +}; +struct D1 : B1, B2 { + using B1::B1; // expected-note {{inherited here}} + using B2::B2; // expected-error {{already inherited constructor with the same signature}} +}; +struct D2 : B1, B2 { + using B1::B1; + using B2::B2; + D2(int); +}; |