This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG27f9b0c619c6: [clang] Include the type of a pointer or reference non-type template parameter… (authored by rsmith, committed by mizvekov).
Changed prior to commit: https://reviews.llvm.org/D136803?vs=470976&id=471003#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D136803/new/ https://reviews.llvm.org/D136803 Files: clang/docs/ReleaseNotes.rst clang/lib/AST/ASTContext.cpp clang/lib/AST/TemplateBase.cpp clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp Index: clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp =================================================================== --- clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp +++ clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp @@ -579,3 +579,22 @@ } }; } // no_crash + +namespace PR47792 { + using I = int; + + template<decltype(auto)> int a; + const int n = 0; + const I n2 = 0; + static_assert(&a<n> == &a<0>, "both should have type 'int'"); + static_assert(&a<n2> == &a<0>, "both should have type 'int'"); + + int m; + const int &r1 = m; + int &r2 = m; + static_assert(&a<r1> != &a<r2>, "should have different types"); + + const I &r3 = m; + static_assert(&a<r1> == &a<r3>, "should have different types"); + static_assert(&a<r2> != &a<r3>, "should have different types"); +} Index: clang/lib/AST/TemplateBase.cpp =================================================================== --- clang/lib/AST/TemplateBase.cpp +++ clang/lib/AST/TemplateBase.cpp @@ -363,7 +363,8 @@ TemplateArg.NumExpansions == Other.TemplateArg.NumExpansions; case Declaration: - return getAsDecl() == Other.getAsDecl(); + return getAsDecl() == Other.getAsDecl() && + getParamTypeForDecl() == Other.getParamTypeForDecl(); case Integral: return getIntegralType() == Other.getIntegralType() && Index: clang/lib/AST/ASTContext.cpp =================================================================== --- clang/lib/AST/ASTContext.cpp +++ clang/lib/AST/ASTContext.cpp @@ -6771,7 +6771,7 @@ case TemplateArgument::Declaration: { auto *D = cast<ValueDecl>(Arg.getAsDecl()->getCanonicalDecl()); - return TemplateArgument(D, Arg.getParamTypeForDecl()); + return TemplateArgument(D, getCanonicalType(Arg.getParamTypeForDecl())); } case TemplateArgument::NullPtr: Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -255,6 +255,9 @@ - Reject non-type template arguments formed by casting a non-zero integer to a pointer in pre-C++17 modes, instead of treating them as null pointers. +- Fix template arguments of pointer and reference not taking the type as + part of their identity. + `Issue 47136 <https://github.com/llvm/llvm-project/issues/47136>`_ Improvements to Clang's diagnostics ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Index: clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp =================================================================== --- clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp +++ clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp @@ -579,3 +579,22 @@ } }; } // no_crash + +namespace PR47792 { + using I = int; + + template<decltype(auto)> int a; + const int n = 0; + const I n2 = 0; + static_assert(&a<n> == &a<0>, "both should have type 'int'"); + static_assert(&a<n2> == &a<0>, "both should have type 'int'"); + + int m; + const int &r1 = m; + int &r2 = m; + static_assert(&a<r1> != &a<r2>, "should have different types"); + + const I &r3 = m; + static_assert(&a<r1> == &a<r3>, "should have different types"); + static_assert(&a<r2> != &a<r3>, "should have different types"); +} Index: clang/lib/AST/TemplateBase.cpp =================================================================== --- clang/lib/AST/TemplateBase.cpp +++ clang/lib/AST/TemplateBase.cpp @@ -363,7 +363,8 @@ TemplateArg.NumExpansions == Other.TemplateArg.NumExpansions; case Declaration: - return getAsDecl() == Other.getAsDecl(); + return getAsDecl() == Other.getAsDecl() && + getParamTypeForDecl() == Other.getParamTypeForDecl(); case Integral: return getIntegralType() == Other.getIntegralType() && Index: clang/lib/AST/ASTContext.cpp =================================================================== --- clang/lib/AST/ASTContext.cpp +++ clang/lib/AST/ASTContext.cpp @@ -6771,7 +6771,7 @@ case TemplateArgument::Declaration: { auto *D = cast<ValueDecl>(Arg.getAsDecl()->getCanonicalDecl()); - return TemplateArgument(D, Arg.getParamTypeForDecl()); + return TemplateArgument(D, getCanonicalType(Arg.getParamTypeForDecl())); } case TemplateArgument::NullPtr: Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -255,6 +255,9 @@ - Reject non-type template arguments formed by casting a non-zero integer to a pointer in pre-C++17 modes, instead of treating them as null pointers. +- Fix template arguments of pointer and reference not taking the type as + part of their identity. + `Issue 47136 <https://github.com/llvm/llvm-project/issues/47136>`_ Improvements to Clang's diagnostics ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits