@@ -9762,26 +9762,26 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
97629762 if (getLangOpts().CPlusPlus) {
97639763 // The rules for implicit inlines changed in C++20 for methods and friends
97649764 // with an in-class definition (when such a definition is not attached to
9765- // the global module). User-specified 'inline' overrides this (set when
9766- // the function decl is created above).
9765+ // the global module). This does not affect declarations that are already
9766+ // inline (whether explicitly or implicitly by being declared constexpr,
9767+ // consteval, etc).
97679768 // FIXME: We need a better way to separate C++ standard and clang modules.
97689769 bool ImplicitInlineCXX20 = !getLangOpts().CPlusPlusModules ||
9769- NewFD->isConstexpr() || NewFD->isConsteval() ||
97709770 !NewFD->getOwningModule() ||
97719771 NewFD->isFromGlobalModule() ||
97729772 NewFD->getOwningModule()->isHeaderLikeModule();
97739773 bool isInline = D.getDeclSpec().isInlineSpecified();
97749774 bool isVirtual = D.getDeclSpec().isVirtualSpecified();
97759775 bool hasExplicit = D.getDeclSpec().hasExplicitSpecifier();
97769776 isFriend = D.getDeclSpec().isFriendSpecified();
9777- if (isFriend && !isInline && D.isFunctionDefinition()) {
9777+ if (ImplicitInlineCXX20 && isFriend && D.isFunctionDefinition()) {
97789778 // Pre-C++20 [class.friend]p5
97799779 // A function can be defined in a friend declaration of a
97809780 // class . . . . Such a function is implicitly inline.
97819781 // Post C++20 [class.friend]p7
97829782 // Such a function is implicitly an inline function if it is attached
97839783 // to the global module.
9784- NewFD->setImplicitlyInline(ImplicitInlineCXX20 );
9784+ NewFD->setImplicitlyInline();
97859785 }
97869786
97879787 // If this is a method defined in an __interface, and is not a constructor
@@ -10083,15 +10083,15 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
1008310083 break;
1008410084 }
1008510085
10086- if (isa<CXXMethodDecl>(NewFD) && DC == CurContext &&
10087- D.isFunctionDefinition() && !isInline ) {
10086+ if (ImplicitInlineCXX20 && isa<CXXMethodDecl>(NewFD) && DC == CurContext &&
10087+ D.isFunctionDefinition()) {
1008810088 // Pre C++20 [class.mfct]p2:
1008910089 // A member function may be defined (8.4) in its class definition, in
1009010090 // which case it is an inline member function (7.1.2)
1009110091 // Post C++20 [class.mfct]p1:
1009210092 // If a member function is attached to the global module and is defined
1009310093 // in its class definition, it is inline.
10094- NewFD->setImplicitlyInline(ImplicitInlineCXX20 );
10094+ NewFD->setImplicitlyInline();
1009510095 }
1009610096
1009710097 if (!isFriend && SC != SC_None) {
0 commit comments