@@ -8226,19 +8226,25 @@ void AttributeChecker::visitWeakLinkedAttr(WeakLinkedAttr *attr) {
8226
8226
}
8227
8227
8228
8228
void AttributeChecker::visitLifetimeAttr (LifetimeAttr *attr) {
8229
- // Allow @lifetime only in the stdlib, cxx and backward compatibility modules
8230
- if (!attr->isUnderscored () &&
8231
- !(Ctx.MainModule ->isStdlibModule () || Ctx.MainModule ->isCxxModule () ||
8232
- Ctx.MainModule ->getABIName () == Ctx.StdlibModuleName )) {
8233
- Ctx.Diags .diagnose (attr->getLocation (), diag::use_lifetime_underscored);
8234
- }
8235
- if (!Ctx.LangOpts .hasFeature (Feature::LifetimeDependence) &&
8236
- !Ctx.SourceMgr .isImportMacroGeneratedLoc (attr->getLocation ())) {
8237
- diagnose (attr->getLocation (), diag::requires_experimental_feature,
8238
- std::string (" @" ) + (attr->isUnderscored ()
8239
- ? std::string (" _lifetime" )
8240
- : std::string (" lifetime" )),
8241
- false , Feature::LifetimeDependence.getName ());
8229
+ if (!attr->isUnderscored ()) {
8230
+ // Allow @lifetime only in the stdlib, cxx and backward compatibility
8231
+ // modules under -enable-experimental-feature LifetimeDependence
8232
+ if (!Ctx.MainModule ->isStdlibModule () && !Ctx.MainModule ->isCxxModule () &&
8233
+ Ctx.MainModule ->getABIName () != Ctx.StdlibModuleName ) {
8234
+ Ctx.Diags .diagnose (attr->getLocation (), diag::use_lifetime_underscored);
8235
+ }
8236
+ if (!Ctx.LangOpts .hasFeature (Feature::LifetimeDependence)) {
8237
+ diagnose (attr->getLocation (), diag::requires_experimental_feature,
8238
+ " @lifetime" , false , Feature::LifetimeDependence.getName ());
8239
+ }
8240
+ } else {
8241
+ // Allow @_lifetime under -enable-experimental-feature Lifetimes
8242
+ if (!Ctx.LangOpts .hasFeature (Feature::Lifetimes) &&
8243
+ !Ctx.SourceMgr .isImportMacroGeneratedLoc (attr->getLocation ())) {
8244
+ diagnose (attr->getLocation (), diag::requires_experimental_feature,
8245
+ " @_lifetime" ,
8246
+ false , Feature::Lifetimes.getName ());
8247
+ }
8242
8248
}
8243
8249
}
8244
8250
0 commit comments