[PATCH] D45755: [Sema] Do not match function type with const T in template argument deduction

2018-04-17 Thread Lei Liu via Phabricator via cfe-commits
lliu0 created this revision.
lliu0 added reviewers: rjmccall, vsapsai.
Herald added a subscriber: cfe-commits.

>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.


Repository:
  rC Clang

https://reviews.llvm.org/D45755

Files:
  lib/Sema/SemaTemplateDeduction.cpp
  test/CXX/drs/dr15xx.cpp
  test/CXX/drs/dr4xx.cpp
  test/SemaTemplate/function-pointer-qualifier.cpp

Index: test/SemaTemplate/function-pointer-qualifier.cpp
===
--- /dev/null
+++ test/SemaTemplate/function-pointer-qualifier.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+template inline
+	void testparam(_Ty **, _Ty **)
+	{
+	}
+
+template inline
+	void testparam(_Ty *const *, _Ty **)
+	{
+	}
+
+template inline
+	void testparam(_Ty **, const _Ty **)
+	{
+	}
+
+template inline
+	void testparam(_Ty *const *, const _Ty **)
+	{
+	}
+
+void case0()
+{
+void (**p1)();
+void (**p2)();
+testparam(p1, p2);
+}
Index: test/CXX/drs/dr4xx.cpp
===
--- test/CXX/drs/dr4xx.cpp
+++ test/CXX/drs/dr4xx.cpp
@@ -796,24 +796,9 @@
 }
 
 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 struct X; // expected-note 2{{here}}
+  template struct X; // expected-note {{here}}
   template struct X {};
   X x; // expected-error {{undefined}}
-  X y; // expected-error {{undefined}}
-
-  // ... but we do in a function template. GCC and EDG fail deduction of 'f'
-  // and the second 'h'.
-  template void f(const T *);
-  template void g(T *, const T * = 0);
-  template void h(T *) { T::error; }
-  template void h(const T *);
-  void i() {
-f(&i);
-g(&i);
-h(&i);
-  }
 }
 
 namespace dr470 { // dr470: yes
Index: test/CXX/drs/dr15xx.cpp
===
--- test/CXX/drs/dr15xx.cpp
+++ test/CXX/drs/dr15xx.cpp
@@ -357,6 +357,19 @@
 };
 } // end namespace dr1579
 
+namespace dr1584 {
+  // Deducing function types from cv-qualified types
+  template void f(const T *); // expected-note {{candidate template ignored}}
+  template void g(T *, const T * = 0);
+  template void h(T *) { T::error; } // expected-error {{no members}}
+  template 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
 
Index: lib/Sema/SemaTemplateDeduction.cpp
===
--- lib/Sema/SemaTemplateDeduction.cpp
+++ lib/Sema/SemaTemplateDeduction.cpp
@@ -1273,6 +1273,12 @@
   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");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45755: [Sema] Do not match function type with const T in template argument deduction

2018-05-02 Thread Lei Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL331424: [Sema] Do not match function type with const T in 
template argument deduction (authored by lliu0, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D45755?vs=142885&id=144968#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D45755

Files:
  cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
  cfe/trunk/test/CXX/drs/dr15xx.cpp
  cfe/trunk/test/CXX/drs/dr4xx.cpp
  cfe/trunk/test/SemaTemplate/function-pointer-qualifier.cpp

Index: cfe/trunk/test/SemaTemplate/function-pointer-qualifier.cpp
===
--- cfe/trunk/test/SemaTemplate/function-pointer-qualifier.cpp
+++ cfe/trunk/test/SemaTemplate/function-pointer-qualifier.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+template inline
+	void testparam(_Ty **, _Ty **)
+	{
+	}
+
+template inline
+	void testparam(_Ty *const *, _Ty **)
+	{
+	}
+
+template inline
+	void testparam(_Ty **, const _Ty **)
+	{
+	}
+
+template inline
+	void testparam(_Ty *const *, const _Ty **)
+	{
+	}
+
+void case0()
+{
+void (**p1)();
+void (**p2)();
+testparam(p1, p2);
+}
Index: cfe/trunk/test/CXX/drs/dr4xx.cpp
===
--- cfe/trunk/test/CXX/drs/dr4xx.cpp
+++ cfe/trunk/test/CXX/drs/dr4xx.cpp
@@ -796,24 +796,9 @@
 }
 
 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 struct X; // expected-note 2{{here}}
+  template struct X; // expected-note {{here}}
   template struct X {};
   X x; // expected-error {{undefined}}
-  X y; // expected-error {{undefined}}
-
-  // ... but we do in a function template. GCC and EDG fail deduction of 'f'
-  // and the second 'h'.
-  template void f(const T *);
-  template void g(T *, const T * = 0);
-  template void h(T *) { T::error; }
-  template void h(const T *);
-  void i() {
-f(&i);
-g(&i);
-h(&i);
-  }
 }
 
 namespace dr470 { // dr470: yes
Index: cfe/trunk/test/CXX/drs/dr15xx.cpp
===
--- cfe/trunk/test/CXX/drs/dr15xx.cpp
+++ cfe/trunk/test/CXX/drs/dr15xx.cpp
@@ -357,6 +357,19 @@
 };
 } // end namespace dr1579
 
+namespace dr1584 {
+  // Deducing function types from cv-qualified types
+  template void f(const T *); // expected-note {{candidate template ignored}}
+  template void g(T *, const T * = 0);
+  template void h(T *) { T::error; } // expected-error {{no members}}
+  template 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
 
Index: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
===
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
@@ -1273,6 +1273,12 @@
   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");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits