diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -57,6 +57,9 @@ - Fix crash on invalid code when looking up a destructor in a templated class inside a namespace. This fixes `Issue 59446 `_. +- Fix crash when diagnosing incorrect usage of ``_Nullable`` involving alias + templates. This fixes + `Issue 60344 `_. Improvements to Clang's diagnostics ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -6992,7 +6992,8 @@ // type sugar, and therefore cannot be diagnosed in any other way. if (auto nullability = oldType->getImmediateNullability()) { if (!modifiedType->canHaveNullability()) { - SemaRef.Diag(TL.getAttr()->getLocation(), + SemaRef.Diag((TL.getAttr() ? TL.getAttr()->getLocation() + : TL.getModifiedLoc().getBeginLoc()), diag::err_nullability_nonpointer) << DiagNullabilityKind(*nullability, false) << modifiedType; return QualType(); diff --git a/clang/test/SemaCXX/nullability.cpp b/clang/test/SemaCXX/nullability.cpp --- a/clang/test/SemaCXX/nullability.cpp +++ b/clang/test/SemaCXX/nullability.cpp @@ -136,3 +136,9 @@ void testNullabilityCompletenessWithTemplate() { Template tip; } + +namespace GH60344 { +class a; +template using c = b _Nullable; // expected-error {{'_Nullable' cannot be applied to non-pointer type 'GH60344::a'}} +c; // expected-note {{in instantiation of template type alias 'c' requested here}} +}