From f961ea5716867b5e426fb2136edd6d1f04c3a7ca Mon Sep 17 00:00:00 2001 From: Sean Hunt Date: Tue, 10 May 2011 19:08:14 +0000 Subject: [PATCH] Re-do R131114 without breaking code. I've edited one diagnostic which would print "copy constructor" for copy constructors and "constructor" for any other constructor. If anyone is extremely enamored with this, it can be reinstated with a simple boolean flag rather than calling getSpecialMember, which is inappropriate. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@131143 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticSemaKinds.td | 21 ++++++++++----------- include/clang/Sema/Sema.h | 2 +- lib/Sema/SemaAccess.cpp | 10 ++++------ lib/Sema/SemaDecl.cpp | 17 ++++++++++------- lib/Sema/SemaDeclCXX.cpp | 2 +- test/CXX/class.access/p4.cpp | 6 +++--- test/SemaCXX/implicit-member-functions.cpp | 2 +- 7 files changed, 30 insertions(+), 30 deletions(-) diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index c9947ee831..332351bd9b 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -600,13 +600,11 @@ def ext_rvalue_to_reference_access_ctor : ExtWarn< "C++98 requires an accessible copy constructor for class %2 when binding " "a reference to a temporary; was %select{private|protected}0">, AccessControl, InGroup; -def err_access_base : Error< +def err_access_base_ctor : Error< "%select{base class|inherited virtual base class}0 %1 has %select{private|" - "protected}3 %select{constructor|copy constructor|copy assignment operator|" - "destructor}2">, AccessControl; -def err_access_field: Error< - "field of type %0 has %select{private|protected}2 %select{constructor|copy " - "constructor|copy assignment operator|destructor}1">, AccessControl; + "protected}2 constructor">, AccessControl; +def err_access_field_ctor : Error< + "field of type %0 has %select{private|protected}1 constructor">, AccessControl; def err_access_ctor_field : Error<"field of type %1 has %select{private|protected}2 constructor">, @@ -2135,7 +2133,8 @@ def err_unavailable_message : Error<"%0 is unavailable: %1">; def warn_unavailable_fwdclass_message : Warning< "%0 maybe unavailable because receiver type is unknown">; def note_unavailable_here : Note< - "function has been explicitly marked %select{unavailable|deleted|deprecated}0 here">; + "function has been explicitly marked " + "%select{unavailable|deleted|deprecated}0 here">; def warn_not_enough_argument : Warning< "not enough variable arguments in %0 declaration to fit a sentinel">; def warn_missing_sentinel : Warning < @@ -2147,11 +2146,11 @@ def warn_missing_prototype : Warning< InGroup>, DefaultIgnore; def err_redefinition : Error<"redefinition of %0">; def err_definition_of_implicitly_declared_member : Error< - "definition of implicitly declared %select{constructor|copy constructor|" - "copy assignment operator|destructor}1">; + "definition of implicitly declared %select{default constructor|copy " + "constructor|copy assignment operator|destructor}1">; def err_definition_of_explicitly_defaulted_member : Error< - "definition of explicitly defaulted %select{constructor|copy constructor|" - "copy assignment operator|destructor}0">; + "definition of explicitly defaulted %select{default constructor|copy " + "constructor|copy assignment operator|destructor}0">; def err_redefinition_extern_inline : Error< "redefinition of a 'extern inline' function %0 is not supported in " "%select{C99 mode|C++}1">; diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 60b327251a..29117f6f91 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -1105,7 +1105,7 @@ public: enum CXXSpecialMember { CXXInvalid = -1, - CXXConstructor = 0, + CXXDefaultConstructor = 0, CXXCopyConstructor = 1, CXXCopyAssignment = 2, CXXDestructor = 3 diff --git a/lib/Sema/SemaAccess.cpp b/lib/Sema/SemaAccess.cpp index 63983c3daf..f340bb3fda 100644 --- a/lib/Sema/SemaAccess.cpp +++ b/lib/Sema/SemaAccess.cpp @@ -1423,17 +1423,15 @@ Sema::AccessResult Sema::CheckConstructorAccess(SourceLocation UseLoc, break; case InitializedEntity::EK_Base: - AccessEntity.setDiag(PDiag(diag::err_access_base) + AccessEntity.setDiag(PDiag(diag::err_access_base_ctor) << Entity.isInheritedVirtualBase() - << Entity.getBaseSpecifier()->getType() - << getSpecialMember(Constructor)); + << Entity.getBaseSpecifier()->getType()); break; case InitializedEntity::EK_Member: { const FieldDecl *Field = cast(Entity.getDecl()); - AccessEntity.setDiag(PDiag(diag::err_access_field) - << Field->getType() - << getSpecialMember(Constructor)); + AccessEntity.setDiag(PDiag(diag::err_access_field_ctor) + << Field->getType()); break; } diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index e19b06effe..b598b46743 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -1508,15 +1508,18 @@ Sema::CXXSpecialMember Sema::getSpecialMember(const CXXMethodDecl *MD) { if (Ctor->isCopyConstructor()) return Sema::CXXCopyConstructor; - return Sema::CXXConstructor; + if (Ctor->isDefaultConstructor()) + return Sema::CXXDefaultConstructor; } if (isa(MD)) return Sema::CXXDestructor; - assert(MD->isCopyAssignmentOperator() && - "Must have copy assignment operator"); - return Sema::CXXCopyAssignment; + if (MD->isCopyAssignmentOperator()) + return Sema::CXXCopyAssignment; + + llvm_unreachable("getSpecialMember on non-special member"); + return Sema::CXXInvalid; } /// canRedefineFunction - checks if a function can be redefined. Currently, @@ -7678,7 +7681,7 @@ bool Sema::CheckNontrivialField(FieldDecl *FD) { if (!RDecl->hasTrivialCopyConstructor()) member = CXXCopyConstructor; else if (!RDecl->hasTrivialDefaultConstructor()) - member = CXXConstructor; + member = CXXDefaultConstructor; else if (!RDecl->hasTrivialCopyAssignment()) member = CXXCopyAssignment; else if (!RDecl->hasTrivialDestructor()) @@ -7707,7 +7710,7 @@ void Sema::DiagnoseNontrivial(const RecordType* T, CXXSpecialMember member) { case CXXInvalid: break; - case CXXConstructor: + case CXXDefaultConstructor: if (RD->hasUserDeclaredConstructor()) { typedef CXXRecordDecl::ctor_iterator ctor_iter; for (ctor_iter ci = RD->ctor_begin(), ce = RD->ctor_end(); ci != ce;++ci){ @@ -7781,7 +7784,7 @@ void Sema::DiagnoseNontrivial(const RecordType* T, CXXSpecialMember member) { bool (CXXRecordDecl::*hasTrivial)() const; switch (member) { - case CXXConstructor: + case CXXDefaultConstructor: hasTrivial = &CXXRecordDecl::hasTrivialDefaultConstructor; break; case CXXCopyConstructor: hasTrivial = &CXXRecordDecl::hasTrivialCopyConstructor; break; diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 04d5d4ab7e..47e4ca129e 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -5109,7 +5109,7 @@ void Sema::DefineImplicitDefaultConstructor(SourceLocation CurrentLocation, if (SetCtorInitializers(Constructor, 0, 0, /*AnyErrors=*/false) || Trap.hasErrorOccurred()) { Diag(CurrentLocation, diag::note_member_synthesized_at) - << CXXConstructor << Context.getTagDeclType(ClassDecl); + << CXXDefaultConstructor << Context.getTagDeclType(ClassDecl); Constructor->setInvalidDecl(); return; } diff --git a/test/CXX/class.access/p4.cpp b/test/CXX/class.access/p4.cpp index 4228a44fc1..3157b87f7e 100644 --- a/test/CXX/class.access/p4.cpp +++ b/test/CXX/class.access/p4.cpp @@ -206,7 +206,7 @@ namespace test5 { class Test1 { A a; }; // expected-error {{private member}} void test1() { - Test1 a; + Test1 a; a = Test1(); // expected-note{{implicit default copy}} } @@ -224,12 +224,12 @@ namespace test6 { private: A(const A &); // expected-note 2 {{declared private here}} }; - class Test1 { A a; }; // expected-error {{field of type 'test6::A' has private copy constructor}} + class Test1 { A a; }; // expected-error {{field of type 'test6::A' has private constructor}} void test1(const Test1 &t) { Test1 a = t; // expected-note{{implicit default copy}} } - class Test2 : A {}; // expected-error {{base class 'test6::A' has private copy constructor}} + class Test2 : A {}; // expected-error {{base class 'test6::A' has private constructor}} void test2(const Test2 &t) { Test2 a = t; // expected-note{{implicit default copy}} } diff --git a/test/SemaCXX/implicit-member-functions.cpp b/test/SemaCXX/implicit-member-functions.cpp index 5333094d53..8451739342 100644 --- a/test/SemaCXX/implicit-member-functions.cpp +++ b/test/SemaCXX/implicit-member-functions.cpp @@ -1,7 +1,7 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s struct A { }; -A::A() { } // expected-error {{definition of implicitly declared constructor}} +A::A() { } // expected-error {{definition of implicitly declared default constructor}} struct B { }; B::B(const B&) { } // expected-error {{definition of implicitly declared copy constructor}} -- 2.40.0