diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index c351ccff0b6ca..6e7a5fb76b602 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -465,6 +465,7 @@ Bug Fixes to C++ Support - Fixed an assertion failure in debug mode, and potential crashes in release mode, when diagnosing a failed cast caused indirectly by a failed implicit conversion to the type of the constructor parameter. - Fixed an assertion failure by adjusting integral to boolean vector conversions (#GH108326) +- Fixed an issue deducing non-type template arguments of reference type. (#GH73460) - Mangle friend function templates with a constraint that depends on a template parameter from an enclosing template as members of the enclosing class. (#GH110247) - Fixed an issue in constraint evaluation, where type constraints on the lambda expression containing outer unexpanded parameters were not correctly expanded. (#GH101754) diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index 0a973a3a0ce03..03ff8145e3b4a 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -442,18 +442,18 @@ DeduceNonTypeTemplateArgument(Sema &S, TemplateParameterList *TemplateParams, // FIXME: It's not clear how deduction of a parameter of reference // type from an argument (of non-reference type) should be performed. - // For now, we just remove reference types from both sides and let - // the final check for matching types sort out the mess. - ValueType = ValueType.getNonReferenceType(); - if (ParamType->isReferenceType()) - ParamType = ParamType.getNonReferenceType(); - else - // Top-level cv-qualifiers are irrelevant for a non-reference type. - ValueType = ValueType.getUnqualifiedType(); + // For now, we just make the argument have same reference type as the + // parameter. + if (ParamType->isReferenceType() && !ValueType->isReferenceType()) { + if (ParamType->isRValueReferenceType()) + ValueType = S.Context.getRValueReferenceType(ValueType); + else + ValueType = S.Context.getLValueReferenceType(ValueType); + } return DeduceTemplateArgumentsByTypeMatch( S, TemplateParams, ParamType, ValueType, Info, Deduced, - TDF_SkipNonDependent, + TDF_SkipNonDependent | TDF_IgnoreQualifiers, PartialOrdering ? PartialOrderingKind::NonCall : PartialOrderingKind::None, /*ArrayBound=*/NewDeduced.wasDeducedFromArrayBound(), HasDeducedAnyParam); diff --git a/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp b/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp index ae06055bf5265..8d9356bb3201c 100644 --- a/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp +++ b/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp @@ -613,3 +613,11 @@ struct { template using a = s; } + +namespace GH73460 { + template struct A; + template struct A {}; + + int j; + template struct A; +} // namespace GH73460