Author: lliu0 Date: Wed May 2 18:43:23 2018 New Revision: 331424 URL: http://llvm.org/viewvc/llvm-project?rev=331424&view=rev Log: [Sema] Do not match function type with const T in template argument deduction
From http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1584, function type should not match cv-qualified type in template argument deduction. This also matches what GCC and EDG do in template argument deduction. Differential Revision: https://reviews.llvm.org/D45755 Added: cfe/trunk/test/SemaTemplate/function-pointer-qualifier.cpp Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp cfe/trunk/test/CXX/drs/dr15xx.cpp cfe/trunk/test/CXX/drs/dr4xx.cpp Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=331424&r1=331423&r2=331424&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original) +++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Wed May 2 18:43:23 2018 @@ -1273,6 +1273,12 @@ DeduceTemplateArgumentsByTypeMatch(Sema return Sema::TDK_Underqualified; } + // Do not match a function type with a cv-qualified type. + // http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1584 + if (Arg->isFunctionType() && Param.hasQualifiers()) { + return Sema::TDK_NonDeducedMismatch; + } + assert(TemplateTypeParm->getDepth() == Info.getDeducedDepth() && "saw template type parameter with wrong depth"); assert(Arg != S.Context.OverloadTy && "Unresolved overloaded function"); Modified: cfe/trunk/test/CXX/drs/dr15xx.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/drs/dr15xx.cpp?rev=331424&r1=331423&r2=331424&view=diff ============================================================================== --- cfe/trunk/test/CXX/drs/dr15xx.cpp (original) +++ cfe/trunk/test/CXX/drs/dr15xx.cpp Wed May 2 18:43:23 2018 @@ -357,6 +357,19 @@ auto DR1579_lambda_invalid = []() -> Gen }; } // end namespace dr1579 +namespace dr1584 { + // Deducing function types from cv-qualified types + template<typename T> void f(const T *); // expected-note {{candidate template ignored}} + template<typename T> void g(T *, const T * = 0); + template<typename T> void h(T *) { T::error; } // expected-error {{no members}} + template<typename T> void h(const T *); + void i() { + f(&i); // expected-error {{no matching function}} + g(&i); + h(&i); // expected-note {{here}} + } +} + namespace dr1589 { // dr1589: 3.7 c++11 // Ambiguous ranking of list-initialization sequences Modified: cfe/trunk/test/CXX/drs/dr4xx.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/drs/dr4xx.cpp?rev=331424&r1=331423&r2=331424&view=diff ============================================================================== --- cfe/trunk/test/CXX/drs/dr4xx.cpp (original) +++ cfe/trunk/test/CXX/drs/dr4xx.cpp Wed May 2 18:43:23 2018 @@ -796,24 +796,9 @@ namespace dr468 { // dr468: yes c++11 } namespace dr469 { // dr469: no - // FIXME: The core issue here didn't really answer the question. We don't - // deduce 'const T' from a function or reference type in a class template... - template<typename T> struct X; // expected-note 2{{here}} + template<typename T> struct X; // expected-note {{here}} template<typename T> struct X<const T> {}; X<int&> x; // expected-error {{undefined}} - X<int()> y; // expected-error {{undefined}} - - // ... but we do in a function template. GCC and EDG fail deduction of 'f' - // and the second 'h'. - template<typename T> void f(const T *); - template<typename T> void g(T *, const T * = 0); - template<typename T> void h(T *) { T::error; } - template<typename T> void h(const T *); - void i() { - f(&i); - g(&i); - h(&i); - } } namespace dr470 { // dr470: yes Added: cfe/trunk/test/SemaTemplate/function-pointer-qualifier.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/function-pointer-qualifier.cpp?rev=331424&view=auto ============================================================================== --- cfe/trunk/test/SemaTemplate/function-pointer-qualifier.cpp (added) +++ cfe/trunk/test/SemaTemplate/function-pointer-qualifier.cpp Wed May 2 18:43:23 2018 @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// expected-no-diagnostics + +template<class _Ty> inline + void testparam(_Ty **, _Ty **) + { + } + +template<class _Ty> inline + void testparam(_Ty *const *, _Ty **) + { + } + +template<class _Ty> inline + void testparam(_Ty **, const _Ty **) + { + } + +template<class _Ty> inline + void testparam(_Ty *const *, const _Ty **) + { + } + +void case0() +{ + void (**p1)(); + void (**p2)(); + testparam(p1, p2); +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits