From a1366cbab89ec6d4f630dca91e85d03d9e5d1d7d Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Fri, 27 Apr 2012 19:33:05 +0000 Subject: [PATCH] PR12224 (sort of): Diagnose inheriting constructor declarations in C++11 mode. We do not support IRGen for these, and get some parts of the semantic analysis wrong. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@155728 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticSemaKinds.td | 10 +++++++--- lib/Sema/SemaDeclCXX.cpp | 6 ++++-- test/CXX/special/class.inhctor/elsewhere.cpp | 16 ++++++++-------- test/CXX/special/class.inhctor/p3.cpp | 12 ++++++------ test/CXX/special/class.inhctor/p7.cpp | 12 ++++++------ test/CodeGenCXX/inheriting-constructor.cpp | 2 ++ test/SemaCXX/cxx98-compat.cpp | 6 +++++- 7 files changed, 38 insertions(+), 26 deletions(-) diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index f85a39ea5e..b53e250f19 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -231,9 +231,13 @@ def err_using_decl_can_not_refer_to_namespace : Error< "using declaration can not refer to namespace">; def err_using_decl_constructor : Error< "using declaration can not refer to a constructor">; -def warn_cxx98_compat_using_decl_constructor : Warning< - "inherited constructors are incompatible with C++98">, - InGroup, DefaultIgnore; +def err_using_decl_constructor_unsupported : Error< + "inheriting constructors are not supported">; +// FIXME: Replace the above error with this warning if support for +// inheriting constructors is implemented. +//def warn_cxx98_compat_using_decl_constructor : Warning< +// "inheriting constructors are incompatible with C++98">, +// InGroup, DefaultIgnore; def err_using_decl_destructor : Error< "using declaration can not refer to a destructor">; def err_using_decl_template_id : Error< diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 5267499ea4..6183942893 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -5925,10 +5925,12 @@ Decl *Sema::ActOnUsingDeclaration(Scope *S, case UnqualifiedId::IK_ConstructorName: case UnqualifiedId::IK_ConstructorTemplateId: - // C++0x inherited constructors. + // C++11 inheriting constructors. Diag(Name.getLocStart(), getLangOpts().CPlusPlus0x ? - diag::warn_cxx98_compat_using_decl_constructor : + // FIXME: Produce warn_cxx98_compat_using_decl_constructor + // instead once inheriting constructors work. + diag::err_using_decl_constructor_unsupported : diag::err_using_decl_constructor) << SS.getRange(); diff --git a/test/CXX/special/class.inhctor/elsewhere.cpp b/test/CXX/special/class.inhctor/elsewhere.cpp index 66afa17309..09fd3d50dc 100644 --- a/test/CXX/special/class.inhctor/elsewhere.cpp +++ b/test/CXX/special/class.inhctor/elsewhere.cpp @@ -9,15 +9,15 @@ struct B1 { B1(int); }; -using B1::B1; // expected-error {{using declaration can not refer to class member}} +using B1::B1; // expected-error {{using declaration can not refer to class member}} expected-error {{not supported}} // 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}} + using B1::B1; // expected-note {{previous using declaration}} expected-error {{not supported}} + using B1::B1; // expected-error {{redeclaration of using decl}} expected-error {{not supported}} }; // C++0x [namespace.udecl]p3: @@ -27,31 +27,31 @@ struct I1 : B1 { // 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}} + using B1::B1; // expected-error {{'B1' is not a direct base of 'D1', can not inherit constructors}} expected-error {{not supported}} }; template struct A {}; template struct B : A, A { - using A::A; // expected-error {{'A::', which is not a base class of 'B'}} + using A::A; // expected-error {{'A::', which is not a base class of 'B'}} expected-error {{not supported}} }; B bb; B bc; B bd; // expected-note {{here}} template struct C : A { - using A::A; // expected-error {{'A::', which is not a base class of 'C'}} + using A::A; // expected-error {{'A::', which is not a base class of 'C'}} expected-error {{not supported}} }; C cb; C cc; // expected-note {{here}} template struct D : A {}; template struct E : D { - using A::A; // expected-error {{'A' is not a direct base of 'E', can not inherit}} + using A::A; // expected-error {{'A' is not a direct base of 'E', can not inherit}} expected-error {{not supported}} }; E eb; // expected-note {{here}} template struct F : D { - using A::A; // expected-error {{'A' is not a direct base of 'F'}} + using A::A; // expected-error {{'A' is not a direct base of 'F'}} expected-error {{not supported}} }; F fb; // expected-note {{here}} diff --git a/test/CXX/special/class.inhctor/p3.cpp b/test/CXX/special/class.inhctor/p3.cpp index f71ab16c0f..d7093fb369 100644 --- a/test/CXX/special/class.inhctor/p3.cpp +++ b/test/CXX/special/class.inhctor/p3.cpp @@ -5,7 +5,7 @@ struct B1 { B1(int, int); }; struct D1 : B1 { - using B1::B1; + using B1::B1; // expected-error {{not supported}} }; D1 d1a(1), d1b(1, 1); @@ -15,7 +15,7 @@ struct B2 { explicit B2(int, int = 0, int = 0); }; struct D2 : B2 { // expected-note 2 {{candidate constructor}} - using B2::B2; + using B2::B2; // expected-error {{not supported}} }; D2 d2a(1), d2b(1, 1), d2c(1, 1, 1); @@ -25,18 +25,18 @@ struct B3 { B3(void*); // expected-note {{inherited from here}} }; struct D3 : B3 { // expected-note 2 {{candidate constructor}} - using B3::B3; // expected-note {{candidate constructor (inherited)}} + using B3::B3; // expected-note {{candidate constructor (inherited)}} expected-error {{not supported}} }; D3 fd3() { return 1; } // expected-error {{no viable conversion}} template struct T1 : B1 { - using B1::B1; + using B1::B1; // expected-error {{not supported}} }; template struct T2 : T1 { - using T1::T1; + using T1::T1; // expected-error {{not supported}} }; template struct T3 : T1 { - using T1::T1; + using T1::T1; // expected-error {{not supported}} }; struct U { friend T1::T1(int); diff --git a/test/CXX/special/class.inhctor/p7.cpp b/test/CXX/special/class.inhctor/p7.cpp index 9ae160f054..bfaa3ac359 100644 --- a/test/CXX/special/class.inhctor/p7.cpp +++ b/test/CXX/special/class.inhctor/p7.cpp @@ -8,12 +8,12 @@ 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}} + using B1::B1; // expected-note {{inherited here}} expected-error {{not supported}} + using B2::B2; // expected-error {{already inherited constructor with the same signature}} expected-error {{not supported}} }; struct D2 : B1, B2 { - using B1::B1; - using B2::B2; + using B1::B1; // expected-error {{not supported}} + using B2::B2; // expected-error {{not supported}} D2(int); }; @@ -22,8 +22,8 @@ template struct B3 { }; template struct B4 : B3, B1 { B4(); - using B3::B3; // expected-note {{inherited here}} - using B1::B1; // expected-error {{already inherited}} + using B3::B3; // expected-note {{inherited here}} expected-error {{not supported}} + using B1::B1; // expected-error {{already inherited}} expected-error {{not supported}} }; B4 b4c; B4 b4i; // expected-note {{here}} diff --git a/test/CodeGenCXX/inheriting-constructor.cpp b/test/CodeGenCXX/inheriting-constructor.cpp index b921a6d2bb..a99840290a 100644 --- a/test/CodeGenCXX/inheriting-constructor.cpp +++ b/test/CodeGenCXX/inheriting-constructor.cpp @@ -1,5 +1,7 @@ // RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck %s +// XFAIL: * + // PR12219 struct A { A(int); virtual ~A(); }; struct B : A { using A::A; ~B(); }; diff --git a/test/SemaCXX/cxx98-compat.cpp b/test/SemaCXX/cxx98-compat.cpp index 8ac3234411..cd3ffed546 100644 --- a/test/SemaCXX/cxx98-compat.cpp +++ b/test/SemaCXX/cxx98-compat.cpp @@ -138,12 +138,16 @@ bool no_except_expr = noexcept(1 + 1); // expected-warning {{noexcept expression void *null = nullptr; // expected-warning {{'nullptr' is incompatible with C++98}} static_assert(true, "!"); // expected-warning {{static_assert declarations are incompatible with C++98}} +// FIXME: Reintroduce this test if support for inheriting constructors is +// implemented. +#if 0 struct InhCtorBase { InhCtorBase(int); }; struct InhCtorDerived : InhCtorBase { - using InhCtorBase::InhCtorBase; // expected-warning {{inherited constructors are incompatible with C++98}} + using InhCtorBase::InhCtorBase; // xpected-warning {{inheriting constructors are incompatible with C++98}} }; +#endif struct FriendMember { static void MemberFn(); -- 2.40.0