We started diagnosing this situation with a more clear diagnostic
message, but it was pointed out that unevaluated contexts don't really
have the undefined behavior property as there is no runtime access
involved.
This augments the changes in https://reviews.llvm.org/D122656 to not
diagnose in an unevaluated context.
// lvalue. Because this is inherently unsafe as an atomic operation, the
// warning defaults to an error.
if (const auto *ATy = BaseType->getAs<AtomicType>()) {
- S.Diag(OpLoc, diag::warn_atomic_member_access);
+ S.DiagRuntimeBehavior(OpLoc, nullptr,
+ S.PDiag(diag::warn_atomic_member_access));
BaseType = ATy->getValueType().getUnqualifiedType();
BaseExpr = ImplicitCastExpr::Create(
S.Context, IsArrow ? S.Context.getPointerType(BaseType) : BaseType,
_Atomic(struct { int val; }) z;
z.val = 12; // expected-error {{accessing a member of an atomic structure or union is undefined behavior}}
int zval = z.val; // expected-error {{accessing a member of an atomic structure or union is undefined behavior}}
+
+ // Don't diagnose in an unevaluated context, however.
+ (void)sizeof(x.val);
+ (void)sizeof(xp->val);
+ (void)sizeof(y.ival);
+ (void)sizeof(yp->ival);
}