mizvekov created this revision. Herald added a project: All. mizvekov requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
We already did this for all the other kinds of non-type template argument. We're still missing the type from the mangling, so we continue to be able to see collisions at link time; that's an open ABI issue. Note: Based on earlier reverted patch from zygoloid. Repository: rG LLVM Github Monorepo 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,23 @@ } }; } // 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'"); + + // FIXME: We will need to mangle these cases differently too! + 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,23 @@ } }; } // 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'"); + + // FIXME: We will need to mangle these cases differently too! + 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