@@ -9839,86 +9839,95 @@ static void findImplicitlyDeclaredEqualityComparisons(
98399839/// [special]p1). This routine can only be executed just before the
98409840/// definition of the class is complete.
98419841void Sema::AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl) {
9842- if (ClassDecl->needsImplicitDefaultConstructor()) {
9843- ++getASTContext().NumImplicitDefaultConstructors;
9842+ // Don't add implicit special members to templated classes.
9843+ // FIXME: This means unqualified lookups for 'operator=' within a class
9844+ // template don't work properly.
9845+ if (!ClassDecl->isDependentType()) {
9846+ if (ClassDecl->needsImplicitDefaultConstructor()) {
9847+ ++getASTContext().NumImplicitDefaultConstructors;
98449848
9845- if (ClassDecl->hasInheritedConstructor())
9846- DeclareImplicitDefaultConstructor(ClassDecl);
9847- }
9849+ if (ClassDecl->hasInheritedConstructor())
9850+ DeclareImplicitDefaultConstructor(ClassDecl);
9851+ }
98489852
9849- if (ClassDecl->needsImplicitCopyConstructor()) {
9850- ++getASTContext().NumImplicitCopyConstructors;
9853+ if (ClassDecl->needsImplicitCopyConstructor()) {
9854+ ++getASTContext().NumImplicitCopyConstructors;
98519855
9852- // If the properties or semantics of the copy constructor couldn't be
9853- // determined while the class was being declared, force a declaration
9854- // of it now.
9855- if (ClassDecl->needsOverloadResolutionForCopyConstructor() ||
9856- ClassDecl->hasInheritedConstructor())
9857- DeclareImplicitCopyConstructor(ClassDecl);
9858- // For the MS ABI we need to know whether the copy ctor is deleted. A
9859- // prerequisite for deleting the implicit copy ctor is that the class has a
9860- // move ctor or move assignment that is either user-declared or whose
9861- // semantics are inherited from a subobject. FIXME: We should provide a more
9862- // direct way for CodeGen to ask whether the constructor was deleted.
9863- else if (Context.getTargetInfo().getCXXABI().isMicrosoft() &&
9864- (ClassDecl->hasUserDeclaredMoveConstructor() ||
9865- ClassDecl->needsOverloadResolutionForMoveConstructor() ||
9866- ClassDecl->hasUserDeclaredMoveAssignment() ||
9867- ClassDecl->needsOverloadResolutionForMoveAssignment()))
9868- DeclareImplicitCopyConstructor(ClassDecl);
9869- }
9856+ // If the properties or semantics of the copy constructor couldn't be
9857+ // determined while the class was being declared, force a declaration
9858+ // of it now.
9859+ if (ClassDecl->needsOverloadResolutionForCopyConstructor() ||
9860+ ClassDecl->hasInheritedConstructor())
9861+ DeclareImplicitCopyConstructor(ClassDecl);
9862+ // For the MS ABI we need to know whether the copy ctor is deleted. A
9863+ // prerequisite for deleting the implicit copy ctor is that the class has
9864+ // a move ctor or move assignment that is either user-declared or whose
9865+ // semantics are inherited from a subobject. FIXME: We should provide a
9866+ // more direct way for CodeGen to ask whether the constructor was deleted.
9867+ else if (Context.getTargetInfo().getCXXABI().isMicrosoft() &&
9868+ (ClassDecl->hasUserDeclaredMoveConstructor() ||
9869+ ClassDecl->needsOverloadResolutionForMoveConstructor() ||
9870+ ClassDecl->hasUserDeclaredMoveAssignment() ||
9871+ ClassDecl->needsOverloadResolutionForMoveAssignment()))
9872+ DeclareImplicitCopyConstructor(ClassDecl);
9873+ }
98709874
9871- if (getLangOpts().CPlusPlus11 && ClassDecl->needsImplicitMoveConstructor()) {
9872- ++getASTContext().NumImplicitMoveConstructors;
9875+ if (getLangOpts().CPlusPlus11 &&
9876+ ClassDecl->needsImplicitMoveConstructor()) {
9877+ ++getASTContext().NumImplicitMoveConstructors;
98739878
9874- if (ClassDecl->needsOverloadResolutionForMoveConstructor() ||
9875- ClassDecl->hasInheritedConstructor())
9876- DeclareImplicitMoveConstructor(ClassDecl);
9877- }
9879+ if (ClassDecl->needsOverloadResolutionForMoveConstructor() ||
9880+ ClassDecl->hasInheritedConstructor())
9881+ DeclareImplicitMoveConstructor(ClassDecl);
9882+ }
98789883
9879- if (ClassDecl->needsImplicitCopyAssignment()) {
9880- ++getASTContext().NumImplicitCopyAssignmentOperators;
9884+ if (ClassDecl->needsImplicitCopyAssignment()) {
9885+ ++getASTContext().NumImplicitCopyAssignmentOperators;
98819886
9882- // If we have a dynamic class, then the copy assignment operator may be
9883- // virtual, so we have to declare it immediately. This ensures that, e.g.,
9884- // it shows up in the right place in the vtable and that we diagnose
9885- // problems with the implicit exception specification.
9886- if (ClassDecl->isDynamicClass() ||
9887- ClassDecl->needsOverloadResolutionForCopyAssignment() ||
9888- ClassDecl->hasInheritedAssignment())
9889- DeclareImplicitCopyAssignment(ClassDecl);
9890- }
9887+ // If we have a dynamic class, then the copy assignment operator may be
9888+ // virtual, so we have to declare it immediately. This ensures that, e.g.,
9889+ // it shows up in the right place in the vtable and that we diagnose
9890+ // problems with the implicit exception specification.
9891+ if (ClassDecl->isDynamicClass() ||
9892+ ClassDecl->needsOverloadResolutionForCopyAssignment() ||
9893+ ClassDecl->hasInheritedAssignment())
9894+ DeclareImplicitCopyAssignment(ClassDecl);
9895+ }
98919896
9892- if (getLangOpts().CPlusPlus11 && ClassDecl->needsImplicitMoveAssignment()) {
9893- ++getASTContext().NumImplicitMoveAssignmentOperators;
9897+ if (getLangOpts().CPlusPlus11 && ClassDecl->needsImplicitMoveAssignment()) {
9898+ ++getASTContext().NumImplicitMoveAssignmentOperators;
98949899
9895- // Likewise for the move assignment operator.
9896- if (ClassDecl->isDynamicClass() ||
9897- ClassDecl->needsOverloadResolutionForMoveAssignment() ||
9898- ClassDecl->hasInheritedAssignment())
9899- DeclareImplicitMoveAssignment(ClassDecl);
9900- }
9900+ // Likewise for the move assignment operator.
9901+ if (ClassDecl->isDynamicClass() ||
9902+ ClassDecl->needsOverloadResolutionForMoveAssignment() ||
9903+ ClassDecl->hasInheritedAssignment())
9904+ DeclareImplicitMoveAssignment(ClassDecl);
9905+ }
99019906
9902- if (ClassDecl->needsImplicitDestructor()) {
9903- ++getASTContext().NumImplicitDestructors;
9907+ if (ClassDecl->needsImplicitDestructor()) {
9908+ ++getASTContext().NumImplicitDestructors;
99049909
9905- // If we have a dynamic class, then the destructor may be virtual, so we
9906- // have to declare the destructor immediately. This ensures that, e.g., it
9907- // shows up in the right place in the vtable and that we diagnose problems
9908- // with the implicit exception specification.
9909- if (ClassDecl->isDynamicClass() ||
9910- ClassDecl->needsOverloadResolutionForDestructor())
9911- DeclareImplicitDestructor(ClassDecl);
9910+ // If we have a dynamic class, then the destructor may be virtual, so we
9911+ // have to declare the destructor immediately. This ensures that, e.g., it
9912+ // shows up in the right place in the vtable and that we diagnose problems
9913+ // with the implicit exception specification.
9914+ if (ClassDecl->isDynamicClass() ||
9915+ ClassDecl->needsOverloadResolutionForDestructor())
9916+ DeclareImplicitDestructor(ClassDecl);
9917+ }
99129918 }
99139919
99149920 // C++2a [class.compare.default]p3:
99159921 // If the member-specification does not explicitly declare any member or
99169922 // friend named operator==, an == operator function is declared implicitly
9917- // for each defaulted three-way comparison operator function defined in the
9918- // member-specification
9923+ // for each defaulted three-way comparison operator function defined in
9924+ // the member-specification
99199925 // FIXME: Consider doing this lazily.
9920- if (getLangOpts().CPlusPlus20) {
9921- llvm::SmallVector<FunctionDecl*, 4> DefaultedSpaceships;
9926+ // We do this during the initial parse for a class template, not during
9927+ // instantiation, so that we can handle unqualified lookups for 'operator=='
9928+ // when parsing the template.
9929+ if (getLangOpts().CPlusPlus20 && !inTemplateInstantiation()) {
9930+ llvm::SmallVector<FunctionDecl *, 4> DefaultedSpaceships;
99229931 findImplicitlyDeclaredEqualityComparisons(Context, ClassDecl,
99239932 DefaultedSpaceships);
99249933 for (auto *FD : DefaultedSpaceships)
0 commit comments