@@ -8183,19 +8183,25 @@ void AttributeChecker::visitWeakLinkedAttr(WeakLinkedAttr *attr) {
81838183}
81848184
81858185void AttributeChecker::visitLifetimeAttr (LifetimeAttr *attr) {
8186- // Allow @lifetime only in the stdlib, cxx and backward compatibility modules
8187- if (!attr->isUnderscored () &&
8188- !(Ctx.MainModule ->isStdlibModule () || Ctx.MainModule ->isCxxModule () ||
8189- Ctx.MainModule ->getABIName () == Ctx.StdlibModuleName )) {
8190- Ctx.Diags .diagnose (attr->getLocation (), diag::use_lifetime_underscored);
8191- }
8192- if (!Ctx.LangOpts .hasFeature (Feature::LifetimeDependence) &&
8193- !Ctx.SourceMgr .isImportMacroGeneratedLoc (attr->getLocation ())) {
8194- diagnose (attr->getLocation (), diag::requires_experimental_feature,
8195- std::string (" @" ) + (attr->isUnderscored ()
8196- ? std::string (" _lifetime" )
8197- : std::string (" lifetime" )),
8198- false , Feature::LifetimeDependence.getName ());
8186+ if (!attr->isUnderscored ()) {
8187+ // Allow @lifetime only in the stdlib, cxx and backward compatibility
8188+ // modules under -enable-experimental-feature LifetimeDependence
8189+ if (!Ctx.MainModule ->isStdlibModule () && !Ctx.MainModule ->isCxxModule () &&
8190+ Ctx.MainModule ->getABIName () != Ctx.StdlibModuleName ) {
8191+ Ctx.Diags .diagnose (attr->getLocation (), diag::use_lifetime_underscored);
8192+ }
8193+ if (!Ctx.LangOpts .hasFeature (Feature::LifetimeDependence)) {
8194+ diagnose (attr->getLocation (), diag::requires_experimental_feature,
8195+ " @lifetime" , false , Feature::LifetimeDependence.getName ());
8196+ }
8197+ } else {
8198+ // Allow @_lifetime under -enable-experimental-feature Lifetimes
8199+ if (!Ctx.LangOpts .hasFeature (Feature::Lifetimes) &&
8200+ !Ctx.SourceMgr .isImportMacroGeneratedLoc (attr->getLocation ())) {
8201+ diagnose (attr->getLocation (), diag::requires_experimental_feature,
8202+ " @_lifetime" ,
8203+ false , Feature::Lifetimes.getName ());
8204+ }
81998205 }
82008206}
82018207
0 commit comments