diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -13082,7 +13082,7 @@ static auto unwrapSugar(SplitQualType &T, Qualifiers &QTotal) { SmallVector R; while (true) { - QTotal += T.Quals; + QTotal.addConsistentQualifiers(T.Quals); QualType NT = T.Ty->getLocallyUnqualifiedSingleStepDesugaredType(); if (NT == QualType(T.Ty, 0)) break; diff --git a/clang/test/SemaCXX/sugar-common-types.cpp b/clang/test/SemaCXX/sugar-common-types.cpp --- a/clang/test/SemaCXX/sugar-common-types.cpp +++ b/clang/test/SemaCXX/sugar-common-types.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++20 -fenable-matrix -triple i686-pc-win32 +// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++20 -x objective-c++ -fobjc-arc -fenable-matrix -triple i686-pc-win32 enum class N {}; @@ -131,3 +131,14 @@ auto t32 = 0 ? (UPX1){} : (UPY1){}; N t33 = t32; // expected-error {{lvalue of type 'C::type1' (aka 'int *')}} N t34 = *t32; // expected-error {{lvalue of type 'B1' (aka 'int')}} + +// See https://github.com/llvm/llvm-project/issues/61419 +namespace PR61419 { + template struct pair { + T0 first; + T1 second; + }; + + extern const pair p; + id t = false ? p.first : p.second; +} // namespace PR61419