Index: clang/lib/Sema/SemaChecking.cpp =================================================================== --- clang/lib/Sema/SemaChecking.cpp +++ clang/lib/Sema/SemaChecking.cpp @@ -16158,8 +16158,12 @@ if (auto *VD = dyn_cast(cast(E)->getDecl())) { // FIXME: If VD is captured by copy or is an escaping __block variable, // use the alignment of VD's type. - if (!VD->getType()->isReferenceType()) + if (!VD->getType()->isReferenceType()) { + // Dependent alignment cannot be resolved -> bail out. + if (VD->hasDependentAlignment()) + break; return std::make_pair(Ctx.getDeclAlign(VD), CharUnits::Zero()); + } if (VD->hasInit()) return getBaseAlignmentAndOffsetFromLValue(VD->getInit(), Ctx); } Index: clang/test/SemaCXX/warn-cast-align.cpp =================================================================== --- clang/test/SemaCXX/warn-cast-align.cpp +++ clang/test/SemaCXX/warn-cast-align.cpp @@ -44,6 +44,11 @@ c = IntPtr(P); } +template void DependentAlign() { + alignas(A) int lut[]{}; + (long *)lut; // expected-warning {{cast from 'int *' to 'long *'}} +} + struct __attribute__((aligned(16))) AlignedS { char m[16]; };