1//===------ SemaDeclCXX.cpp - Semantic Analysis for C++ Declarations ------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// --- 244 unchanged lines hidden (view full) --- 253 Diag(OldParam->getLocation(), diag::note_previous_definition); 254 Invalid = true; 255 } else if (OldParam->getDefaultArg()) { 256 // Merge the old default argument into the new parameter 257 NewParam->setDefaultArg(OldParam->getDefaultArg()); 258 } 259 } 260 |
261 if (CheckEquivalentExceptionSpec( 262 Old->getType()->getAsFunctionProtoType(), Old->getLocation(), 263 New->getType()->getAsFunctionProtoType(), New->getLocation())) { 264 Invalid = true; 265 } 266 |
267 return Invalid; 268} 269 270/// CheckCXXDefaultArguments - Verify that the default arguments for a 271/// function declaration are well-formed according to C++ 272/// [dcl.fct.default]. 273void Sema::CheckCXXDefaultArguments(FunctionDecl *FD) { 274 unsigned NumParams = FD->getNumParams(); --- 207 unchanged lines hidden (view full) --- 482 } else { 483 // Okay, add this new base class. 484 KnownBaseTypes[NewBaseType] = Bases[idx]; 485 Bases[NumGoodBases++] = Bases[idx]; 486 } 487 } 488 489 // Attach the remaining base class specifiers to the derived class. |
490 Class->setBases(Context, Bases, NumGoodBases); |
491 492 // Delete the remaining (good) base class specifiers, since their 493 // data has been copied into the CXXRecordDecl. 494 for (unsigned idx = 0; idx < NumGoodBases; ++idx) 495 delete Bases[idx]; 496 497 return Invalid; 498} --- 148 unchanged lines hidden (view full) --- 647 } 648 return DeclPtrTy::make(Member); 649} 650 651/// ActOnMemInitializer - Handle a C++ member initializer. 652Sema::MemInitResult 653Sema::ActOnMemInitializer(DeclPtrTy ConstructorD, 654 Scope *S, |
655 const CXXScopeSpec &SS, |
656 IdentifierInfo *MemberOrBase, |
657 TypeTy *TemplateTypeTy, |
658 SourceLocation IdLoc, 659 SourceLocation LParenLoc, 660 ExprTy **Args, unsigned NumArgs, 661 SourceLocation *CommaLocs, 662 SourceLocation RParenLoc) { 663 if (!ConstructorD) 664 return true; 665 --- 14 unchanged lines hidden (view full) --- 680 // constructor���s class and, if not found in that scope, are looked 681 // up in the scope containing the constructor���s 682 // definition. [Note: if the constructor���s class contains a member 683 // with the same name as a direct or virtual base class of the 684 // class, a mem-initializer-id naming the member or base class and 685 // composed of a single identifier refers to the class member. A 686 // mem-initializer-id for the hidden base class may be specified 687 // using a qualified name. ] |
688 if (!SS.getScopeRep() && !TemplateTypeTy) { 689 // Look for a member, first. 690 FieldDecl *Member = 0; 691 DeclContext::lookup_result Result 692 = ClassDecl->lookup(MemberOrBase); 693 if (Result.first != Result.second) 694 Member = dyn_cast<FieldDecl>(*Result.first); |
695 |
696 // FIXME: Handle members of an anonymous union. |
697 |
698 if (Member) { 699 // FIXME: Perform direct initialization of the member. 700 return new CXXBaseOrMemberInitializer(Member, (Expr **)Args, NumArgs, 701 IdLoc); 702 } |
703 } |
704 // It didn't name a member, so see if it names a class. |
705 TypeTy *BaseTy = TemplateTypeTy ? TemplateTypeTy 706 : getTypeName(*MemberOrBase, IdLoc, S, &SS); |
707 if (!BaseTy) 708 return Diag(IdLoc, diag::err_mem_init_not_member_or_class) 709 << MemberOrBase << SourceRange(IdLoc, RParenLoc); 710 711 QualType BaseType = QualType::getFromOpaquePtr(BaseTy); |
712 if (!BaseType->isRecordType() && !BaseType->isDependentType()) |
713 return Diag(IdLoc, diag::err_base_init_does_not_name_class) 714 << BaseType << SourceRange(IdLoc, RParenLoc); 715 716 // C++ [class.base.init]p2: 717 // [...] Unless the mem-initializer-id names a nonstatic data 718 // member of the constructor���s class or a direct or virtual base 719 // of that class, the mem-initializer is ill-formed. A 720 // mem-initializer-list can initialize a base class using any --- 34 unchanged lines hidden (view full) --- 755 756 // C++ [base.class.init]p2: 757 // If a mem-initializer-id is ambiguous because it designates both 758 // a direct non-virtual base class and an inherited virtual base 759 // class, the mem-initializer is ill-formed. 760 if (DirectBaseSpec && VirtualBaseSpec) 761 return Diag(IdLoc, diag::err_base_init_direct_and_virtual) 762 << MemberOrBase << SourceRange(IdLoc, RParenLoc); |
763 // C++ [base.class.init]p2: 764 // Unless the mem-initializer-id names a nonstatic data membeer of the 765 // constructor's class ot a direst or virtual base of that class, the 766 // mem-initializer is ill-formed. 767 if (!DirectBaseSpec && !VirtualBaseSpec) 768 return Diag(IdLoc, diag::err_not_direct_base_or_virtual) 769 << BaseType << ClassDecl->getNameAsCString() 770 << SourceRange(IdLoc, RParenLoc); 771 |
772 |
773 return new CXXBaseOrMemberInitializer(BaseType, (Expr **)Args, NumArgs, 774 IdLoc); |
775} 776 777void Sema::ActOnMemInitializers(DeclPtrTy ConstructorDecl, 778 SourceLocation ColonLoc, 779 MemInitTy **MemInits, unsigned NumMemInits) { 780 if (!ConstructorDecl) 781 return; 782 783 CXXConstructorDecl *Constructor 784 = dyn_cast<CXXConstructorDecl>(ConstructorDecl.getAs<Decl>()); 785 786 if (!Constructor) { 787 Diag(ColonLoc, diag::err_only_constructors_take_base_inits); 788 return; 789 } |
790 llvm::DenseMap<void*, CXXBaseOrMemberInitializer *>Members; 791 bool err = false; 792 for (unsigned i = 0; i < NumMemInits; i++) { 793 CXXBaseOrMemberInitializer *Member = 794 static_cast<CXXBaseOrMemberInitializer*>(MemInits[i]); 795 void *KeyToMember = Member->getBaseOrMember(); 796 // For fields injected into the class via declaration of an anonymous union, 797 // use its anonymous union class declaration as the unique key. 798 if (FieldDecl *Field = Member->getMember()) 799 if (Field->getDeclContext()->isRecord() && 800 cast<RecordDecl>(Field->getDeclContext())->isAnonymousStructOrUnion()) 801 KeyToMember = static_cast<void *>(Field->getDeclContext()); 802 CXXBaseOrMemberInitializer *&PrevMember = Members[KeyToMember]; 803 if (!PrevMember) { 804 PrevMember = Member; 805 continue; 806 } 807 if (FieldDecl *Field = Member->getMember()) 808 Diag(Member->getSourceLocation(), 809 diag::error_multiple_mem_initialization) 810 << Field->getNameAsString(); 811 else { 812 Type *BaseClass = Member->getBaseClass(); 813 assert(BaseClass && "ActOnMemInitializers - neither field or base"); 814 Diag(Member->getSourceLocation(), 815 diag::error_multiple_base_initialization) 816 << BaseClass->getDesugaredType(true); 817 } 818 Diag(PrevMember->getSourceLocation(), diag::note_previous_initializer) 819 << 0; 820 err = true; 821 } 822 if (!err) 823 Constructor->setBaseOrMemberInitializers(Context, 824 reinterpret_cast<CXXBaseOrMemberInitializer **>(MemInits), 825 NumMemInits); |
826} 827 828namespace { 829 /// PureVirtualMethodCollector - traverses a class and its superclasses 830 /// and determines if it has any pure virtual methods. 831 class VISIBILITY_HIDDEN PureVirtualMethodCollector { 832 ASTContext &Context; 833 --- 39 unchanged lines hidden (view full) --- 873 } 874 875 // Next, zero out any pure virtual methods that this class overrides. 876 typedef llvm::SmallPtrSet<const CXXMethodDecl*, 4> MethodSetTy; 877 878 MethodSetTy OverriddenMethods; 879 size_t MethodsSize = Methods.size(); 880 |
881 for (RecordDecl::decl_iterator i = RD->decls_begin(), e = RD->decls_end(); |
882 i != e; ++i) { 883 // Traverse the record, looking for methods. 884 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(*i)) { 885 // If the method is pre virtual, add it to the methods vector. 886 if (MD->isPure()) { 887 Methods.push_back(MD); 888 continue; 889 } --- 80 unchanged lines hidden (view full) --- 970 class VISIBILITY_HIDDEN AbstractClassUsageDiagnoser 971 : public DeclVisitor<AbstractClassUsageDiagnoser, bool> { 972 Sema &SemaRef; 973 CXXRecordDecl *AbstractClass; 974 975 bool VisitDeclContext(const DeclContext *DC) { 976 bool Invalid = false; 977 |
978 for (CXXRecordDecl::decl_iterator I = DC->decls_begin(), 979 E = DC->decls_end(); I != E; ++I) |
980 Invalid |= Visit(*I); 981 982 return Invalid; 983 } 984 985 public: 986 AbstractClassUsageDiagnoser(Sema& SemaRef, CXXRecordDecl *ac) 987 : SemaRef(SemaRef), AbstractClass(ac) { --- 59 unchanged lines hidden (view full) --- 1047 if (!Collector.empty()) 1048 RD->setAbstract(true); 1049 } 1050 1051 if (RD->isAbstract()) 1052 AbstractClassUsageDiagnoser(*this, RD); 1053 1054 if (RD->hasTrivialConstructor() || RD->hasTrivialDestructor()) { |
1055 for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end(); 1056 i != e; ++i) { |
1057 // All the nonstatic data members must have trivial constructors. 1058 QualType FTy = i->getType(); 1059 while (const ArrayType *AT = Context.getAsArrayType(FTy)) 1060 FTy = AT->getElementType(); 1061 1062 if (const RecordType *RT = FTy->getAsRecordType()) { 1063 CXXRecordDecl *FieldRD = cast<CXXRecordDecl>(RT->getDecl()); 1064 --- 40 unchanged lines hidden (view full) --- 1105 ClassDecl->getLocation(), Name, 1106 Context.getFunctionType(Context.VoidTy, 1107 0, 0, false, 0), 1108 /*isExplicit=*/false, 1109 /*isInline=*/true, 1110 /*isImplicitlyDeclared=*/true); 1111 DefaultCon->setAccess(AS_public); 1112 DefaultCon->setImplicit(); |
1113 ClassDecl->addDecl(DefaultCon); |
1114 } 1115 1116 if (!ClassDecl->hasUserDeclaredCopyConstructor()) { 1117 // C++ [class.copy]p4: 1118 // If the class definition does not explicitly declare a copy 1119 // constructor, one is declared implicitly. 1120 1121 // C++ [class.copy]p5: --- 15 unchanged lines hidden (view full) --- 1137 HasConstCopyConstructor 1138 = BaseClassDecl->hasConstCopyConstructor(Context); 1139 } 1140 1141 // -- for all the nonstatic data members of X that are of a 1142 // class type M (or array thereof), each such class type 1143 // has a copy constructor whose first parameter is of type 1144 // const M& or const volatile M&. |
1145 for (CXXRecordDecl::field_iterator Field = ClassDecl->field_begin(); 1146 HasConstCopyConstructor && Field != ClassDecl->field_end(); |
1147 ++Field) { 1148 QualType FieldType = (*Field)->getType(); 1149 if (const ArrayType *Array = Context.getAsArrayType(FieldType)) 1150 FieldType = Array->getElementType(); 1151 if (const RecordType *FieldClassType = FieldType->getAsRecordType()) { 1152 const CXXRecordDecl *FieldClassDecl 1153 = cast<CXXRecordDecl>(FieldClassType->getDecl()); 1154 HasConstCopyConstructor --- 27 unchanged lines hidden (view full) --- 1182 CopyConstructor->setImplicit(); 1183 1184 // Add the parameter to the constructor. 1185 ParmVarDecl *FromParam = ParmVarDecl::Create(Context, CopyConstructor, 1186 ClassDecl->getLocation(), 1187 /*IdentifierInfo=*/0, 1188 ArgType, VarDecl::None, 0); 1189 CopyConstructor->setParams(Context, &FromParam, 1); |
1190 ClassDecl->addDecl(CopyConstructor); |
1191 } 1192 1193 if (!ClassDecl->hasUserDeclaredCopyAssignment()) { 1194 // Note: The following rules are largely analoguous to the copy 1195 // constructor rules. Note that virtual bases are not taken into account 1196 // for determining the argument type of the operator. Note also that 1197 // operators taking an object instead of a reference are allowed. 1198 // --- 17 unchanged lines hidden (view full) --- 1216 = cast<CXXRecordDecl>(Base->getType()->getAsRecordType()->getDecl()); 1217 HasConstCopyAssignment = BaseClassDecl->hasConstCopyAssignment(Context); 1218 } 1219 1220 // -- for all the nonstatic data members of X that are of a class 1221 // type M (or array thereof), each such class type has a copy 1222 // assignment operator whose parameter is of type const M&, 1223 // const volatile M& or M. |
1224 for (CXXRecordDecl::field_iterator Field = ClassDecl->field_begin(); 1225 HasConstCopyAssignment && Field != ClassDecl->field_end(); |
1226 ++Field) { 1227 QualType FieldType = (*Field)->getType(); 1228 if (const ArrayType *Array = Context.getAsArrayType(FieldType)) 1229 FieldType = Array->getElementType(); 1230 if (const RecordType *FieldClassType = FieldType->getAsRecordType()) { 1231 const CXXRecordDecl *FieldClassDecl 1232 = cast<CXXRecordDecl>(FieldClassType->getDecl()); 1233 HasConstCopyAssignment --- 27 unchanged lines hidden (view full) --- 1261 ParmVarDecl *FromParam = ParmVarDecl::Create(Context, CopyAssignment, 1262 ClassDecl->getLocation(), 1263 /*IdentifierInfo=*/0, 1264 ArgType, VarDecl::None, 0); 1265 CopyAssignment->setParams(Context, &FromParam, 1); 1266 1267 // Don't call addedAssignmentOperator. There is no way to distinguish an 1268 // implicit from an explicit assignment operator. |
1269 ClassDecl->addDecl(CopyAssignment); |
1270 } 1271 1272 if (!ClassDecl->hasUserDeclaredDestructor()) { 1273 // C++ [class.dtor]p2: 1274 // If a class has no user-declared destructor, a destructor is 1275 // declared implicitly. An implicitly-declared destructor is an 1276 // inline public member of its class. 1277 DeclarationName Name 1278 = Context.DeclarationNames.getCXXDestructorName(ClassType); 1279 CXXDestructorDecl *Destructor 1280 = CXXDestructorDecl::Create(Context, ClassDecl, 1281 ClassDecl->getLocation(), Name, 1282 Context.getFunctionType(Context.VoidTy, 1283 0, 0, false, 0), 1284 /*isInline=*/true, 1285 /*isImplicitlyDeclared=*/true); 1286 Destructor->setAccess(AS_public); 1287 Destructor->setImplicit(); |
1288 ClassDecl->addDecl(Destructor); |
1289 } 1290} 1291 1292void Sema::ActOnReenterTemplateScope(Scope *S, DeclPtrTy TemplateD) { 1293 TemplateDecl *Template = TemplateD.getAs<TemplateDecl>(); 1294 if (!Template) 1295 return; 1296 --- 526 unchanged lines hidden (view full) --- 1823 return DeclPtrTy::make(UDir); 1824} 1825 1826void Sema::PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir) { 1827 // If scope has associated entity, then using directive is at namespace 1828 // or translation unit scope. We add UsingDirectiveDecls, into 1829 // it's lookup structure. 1830 if (DeclContext *Ctx = static_cast<DeclContext*>(S->getEntity())) |
1831 Ctx->addDecl(UDir); |
1832 else 1833 // Otherwise it is block-sope. using-directives will affect lookup 1834 // only to the end of scope. 1835 S->PushUsingDirective(DeclPtrTy::make(UDir)); 1836} 1837 1838 1839Sema::DeclPtrTy Sema::ActOnUsingDeclaration(Scope *S, --- 84 unchanged lines hidden (view full) --- 1924 } 1925 1926 NamespaceAliasDecl *AliasDecl = 1927 NamespaceAliasDecl::Create(Context, CurContext, NamespaceLoc, AliasLoc, 1928 Alias, SS.getRange(), 1929 (NestedNameSpecifier *)SS.getScopeRep(), 1930 IdentLoc, R); 1931 |
1932 CurContext->addDecl(AliasDecl); |
1933 return DeclPtrTy::make(AliasDecl); 1934} 1935 1936void Sema::DefineImplicitDefaultConstructor(SourceLocation CurrentLocation, 1937 CXXConstructorDecl *Constructor) { 1938 assert((Constructor->isImplicit() && Constructor->isDefaultConstructor() && 1939 !Constructor->isUsed()) && 1940 "DefineImplicitDefaultConstructor - call it for implicit default ctor"); 1941 1942 CXXRecordDecl *ClassDecl 1943 = cast<CXXRecordDecl>(Constructor->getDeclContext()); 1944 assert(ClassDecl && "DefineImplicitDefaultConstructor - invalid constructor"); 1945 // Before the implicitly-declared default constructor for a class is 1946 // implicitly defined, all the implicitly-declared default constructors 1947 // for its base class and its non-static data members shall have been 1948 // implicitly defined. 1949 bool err = false; |
1950 for (CXXRecordDecl::base_class_iterator Base = ClassDecl->bases_begin(), 1951 E = ClassDecl->bases_end(); Base != E; ++Base) { |
1952 CXXRecordDecl *BaseClassDecl 1953 = cast<CXXRecordDecl>(Base->getType()->getAsRecordType()->getDecl()); 1954 if (!BaseClassDecl->hasTrivialConstructor()) { 1955 if (CXXConstructorDecl *BaseCtor = 1956 BaseClassDecl->getDefaultConstructor(Context)) 1957 MarkDeclarationReferenced(CurrentLocation, BaseCtor); 1958 else { 1959 Diag(CurrentLocation, diag::err_defining_default_ctor) 1960 << Context.getTagDeclType(ClassDecl) << 1 1961 << Context.getTagDeclType(BaseClassDecl); 1962 Diag(BaseClassDecl->getLocation(), diag::note_previous_class_decl) 1963 << Context.getTagDeclType(BaseClassDecl); 1964 err = true; 1965 } 1966 } 1967 } |
1968 for (CXXRecordDecl::field_iterator Field = ClassDecl->field_begin(), 1969 E = ClassDecl->field_end(); Field != E; ++Field) { |
1970 QualType FieldType = Context.getCanonicalType((*Field)->getType()); 1971 if (const ArrayType *Array = Context.getAsArrayType(FieldType)) 1972 FieldType = Array->getElementType(); 1973 if (const RecordType *FieldClassType = FieldType->getAsRecordType()) { 1974 CXXRecordDecl *FieldClassDecl 1975 = cast<CXXRecordDecl>(FieldClassType->getDecl()); 1976 if (!FieldClassDecl->hasTrivialConstructor()) { 1977 if (CXXConstructorDecl *FieldCtor = --- 36 unchanged lines hidden (view full) --- 2014 CXXRecordDecl *ClassDecl 2015 = cast<CXXRecordDecl>(Destructor->getDeclContext()); 2016 assert(ClassDecl && "DefineImplicitDestructor - invalid destructor"); 2017 // C++ [class.dtor] p5 2018 // Before the implicitly-declared default destructor for a class is 2019 // implicitly defined, all the implicitly-declared default destructors 2020 // for its base class and its non-static data members shall have been 2021 // implicitly defined. |
2022 for (CXXRecordDecl::base_class_iterator Base = ClassDecl->bases_begin(), 2023 E = ClassDecl->bases_end(); Base != E; ++Base) { |
2024 CXXRecordDecl *BaseClassDecl 2025 = cast<CXXRecordDecl>(Base->getType()->getAsRecordType()->getDecl()); 2026 if (!BaseClassDecl->hasTrivialDestructor()) { 2027 if (CXXDestructorDecl *BaseDtor = 2028 const_cast<CXXDestructorDecl*>(BaseClassDecl->getDestructor(Context))) 2029 MarkDeclarationReferenced(CurrentLocation, BaseDtor); 2030 else 2031 assert(false && 2032 "DefineImplicitDestructor - missing dtor in a base class"); 2033 } 2034 } 2035 |
2036 for (CXXRecordDecl::field_iterator Field = ClassDecl->field_begin(), 2037 E = ClassDecl->field_end(); Field != E; ++Field) { |
2038 QualType FieldType = Context.getCanonicalType((*Field)->getType()); 2039 if (const ArrayType *Array = Context.getAsArrayType(FieldType)) 2040 FieldType = Array->getElementType(); 2041 if (const RecordType *FieldClassType = FieldType->getAsRecordType()) { 2042 CXXRecordDecl *FieldClassDecl 2043 = cast<CXXRecordDecl>(FieldClassType->getDecl()); 2044 if (!FieldClassDecl->hasTrivialDestructor()) { 2045 if (CXXDestructorDecl *FieldDtor = --- 13 unchanged lines hidden (view full) --- 2059 CXXMethodDecl *MethodDecl) { 2060 assert((MethodDecl->isImplicit() && MethodDecl->isOverloadedOperator() && 2061 MethodDecl->getOverloadedOperator() == OO_Equal && 2062 !MethodDecl->isUsed()) && 2063 "DefineImplicitOverloadedAssign - call it for implicit assignment op"); 2064 2065 CXXRecordDecl *ClassDecl 2066 = cast<CXXRecordDecl>(MethodDecl->getDeclContext()); |
2067 2068 // C++[class.copy] p12 2069 // Before the implicitly-declared copy assignment operator for a class is 2070 // implicitly defined, all implicitly-declared copy assignment operators 2071 // for its direct base classes and its nonstatic data members shall have 2072 // been implicitly defined. 2073 bool err = false; |
2074 for (CXXRecordDecl::base_class_iterator Base = ClassDecl->bases_begin(), 2075 E = ClassDecl->bases_end(); Base != E; ++Base) { |
2076 CXXRecordDecl *BaseClassDecl 2077 = cast<CXXRecordDecl>(Base->getType()->getAsRecordType()->getDecl()); 2078 if (CXXMethodDecl *BaseAssignOpMethod = 2079 getAssignOperatorMethod(MethodDecl->getParamDecl(0), BaseClassDecl)) 2080 MarkDeclarationReferenced(CurrentLocation, BaseAssignOpMethod); 2081 } |
2082 for (CXXRecordDecl::field_iterator Field = ClassDecl->field_begin(), 2083 E = ClassDecl->field_end(); Field != E; ++Field) { |
2084 QualType FieldType = Context.getCanonicalType((*Field)->getType()); 2085 if (const ArrayType *Array = Context.getAsArrayType(FieldType)) 2086 FieldType = Array->getElementType(); 2087 if (const RecordType *FieldClassType = FieldType->getAsRecordType()) { 2088 CXXRecordDecl *FieldClassDecl 2089 = cast<CXXRecordDecl>(FieldClassType->getDecl()); 2090 if (CXXMethodDecl *FieldAssignOpMethod = 2091 getAssignOperatorMethod(MethodDecl->getParamDecl(0), FieldClassDecl)) --- 68 unchanged lines hidden (view full) --- 2160 for (CXXRecordDecl::base_class_iterator Base = ClassDecl->bases_begin(); 2161 Base != ClassDecl->bases_end(); ++Base) { 2162 CXXRecordDecl *BaseClassDecl 2163 = cast<CXXRecordDecl>(Base->getType()->getAsRecordType()->getDecl()); 2164 if (CXXConstructorDecl *BaseCopyCtor = 2165 BaseClassDecl->getCopyConstructor(Context, TypeQuals)) 2166 MarkDeclarationReferenced(CurrentLocation, BaseCopyCtor); 2167 } |
2168 for (CXXRecordDecl::field_iterator Field = ClassDecl->field_begin(), 2169 FieldEnd = ClassDecl->field_end(); 2170 Field != FieldEnd; ++Field) { |
2171 QualType FieldType = Context.getCanonicalType((*Field)->getType()); 2172 if (const ArrayType *Array = Context.getAsArrayType(FieldType)) 2173 FieldType = Array->getElementType(); 2174 if (const RecordType *FieldClassType = FieldType->getAsRecordType()) { 2175 CXXRecordDecl *FieldClassDecl 2176 = cast<CXXRecordDecl>(FieldClassType->getDecl()); 2177 if (CXXConstructorDecl *FieldCopyCtor = 2178 FieldClassDecl->getCopyConstructor(Context, TypeQuals)) --- 8 unchanged lines hidden (view full) --- 2187 QualType DeclInitType, 2188 Expr **Exprs, unsigned NumExprs) { 2189 Expr *Temp = CXXConstructExpr::Create(Context, DeclInitType, Constructor, 2190 false, Exprs, NumExprs); 2191 MarkDeclarationReferenced(VD->getLocation(), Constructor); 2192 VD->setInit(Context, Temp); 2193} 2194 |
2195void Sema::MarkDestructorReferenced(SourceLocation Loc, QualType DeclInitType) |
2196{ 2197 CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>( 2198 DeclInitType->getAsRecordType()->getDecl()); 2199 if (!ClassDecl->hasTrivialDestructor()) 2200 if (CXXDestructorDecl *Destructor = 2201 const_cast<CXXDestructorDecl*>(ClassDecl->getDestructor(Context))) 2202 MarkDeclarationReferenced(Loc, Destructor); 2203} --- 61 unchanged lines hidden (view full) --- 2265 if (!Constructor) 2266 RealDecl->setInvalidDecl(); 2267 else { 2268 VDecl->setCXXDirectInitializer(true); 2269 InitializeVarWithConstructor(VDecl, Constructor, DeclInitType, 2270 (Expr**)Exprs.release(), NumExprs); 2271 // FIXME. Must do all that is needed to destroy the object 2272 // on scope exit. For now, just mark the destructor as used. |
2273 MarkDestructorReferenced(VDecl->getLocation(), DeclInitType); |
2274 } 2275 return; 2276 } 2277 2278 if (NumExprs > 1) { 2279 Diag(CommaLocs[0], diag::err_builtin_direct_init_more_than_one_arg) 2280 << SourceRange(VDecl->getLocation(), RParenLoc); 2281 RealDecl->setInvalidDecl(); --- 47 unchanged lines hidden (view full) --- 2329 const CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(ClassRec->getDecl()); 2330 OverloadCandidateSet CandidateSet; 2331 2332 // Add constructors to the overload set. 2333 DeclarationName ConstructorName 2334 = Context.DeclarationNames.getCXXConstructorName( 2335 Context.getCanonicalType(ClassType.getUnqualifiedType())); 2336 DeclContext::lookup_const_iterator Con, ConEnd; |
2337 for (llvm::tie(Con, ConEnd) = ClassDecl->lookup(ConstructorName); |
2338 Con != ConEnd; ++Con) { 2339 CXXConstructorDecl *Constructor = cast<CXXConstructorDecl>(*Con); 2340 if ((Kind == IK_Direct) || 2341 (Kind == IK_Copy && Constructor->isConvertingConstructor()) || 2342 (Kind == IK_Default && Constructor->isDefaultConstructor())) 2343 AddOverloadCandidate(Constructor, Args, NumArgs, CandidateSet); 2344 } 2345 --- 593 unchanged lines hidden (view full) --- 2939 return DeclPtrTy(); 2940 } 2941 2942 // FIXME: Add all the various semantics of linkage specifications 2943 2944 LinkageSpecDecl *D = LinkageSpecDecl::Create(Context, CurContext, 2945 LangLoc, Language, 2946 LBraceLoc.isValid()); |
2947 CurContext->addDecl(D); |
2948 PushDeclContext(S, D); 2949 return DeclPtrTy::make(D); 2950} 2951 2952/// ActOnFinishLinkageSpecification - Completely the definition of 2953/// the C++ linkage specification LinkageSpec. If RBraceLoc is 2954/// valid, it's the position of the closing '}' brace in a linkage 2955/// specification that uses braces. --- 97 unchanged lines hidden (view full) --- 3053 3054 if (Invalid) 3055 ExDecl->setInvalidDecl(); 3056 3057 // Add the exception declaration into this scope. 3058 if (II) 3059 PushOnScopeChains(ExDecl, S); 3060 else |
3061 CurContext->addDecl(ExDecl); |
3062 3063 ProcessDeclAttributes(S, ExDecl, D); 3064 return DeclPtrTy::make(ExDecl); 3065} 3066 3067Sema::DeclPtrTy Sema::ActOnStaticAssertDeclaration(SourceLocation AssertLoc, 3068 ExprArg assertexpr, 3069 ExprArg assertmessageexpr) { --- 17 unchanged lines hidden (view full) --- 3087 } 3088 } 3089 3090 assertexpr.release(); 3091 assertmessageexpr.release(); 3092 Decl *Decl = StaticAssertDecl::Create(Context, CurContext, AssertLoc, 3093 AssertExpr, AssertMessage); 3094 |
3095 CurContext->addDecl(Decl); |
3096 return DeclPtrTy::make(Decl); 3097} 3098 3099bool Sema::ActOnFriendDecl(Scope *S, SourceLocation FriendLoc, DeclPtrTy Dcl) { 3100 if (!(S->getFlags() & Scope::ClassScope)) { 3101 Diag(FriendLoc, diag::err_friend_decl_outside_class); 3102 return true; 3103 } --- 164 unchanged lines hidden --- |