PR c++/82664 - ICE with reference to function template parm.
authorJason Merrill <jason@redhat.com>
Fri, 16 Feb 2018 19:06:34 +0000 (14:06 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 16 Feb 2018 19:06:34 +0000 (14:06 -0500)
* pt.c (convert_nontype_argument_function): Avoid obfuscationg
NOP_EXPRs.

From-SVN: r257753

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/g++.dg/template/nontype-fn1.C [new file with mode: 0644]

index 141a64fbdc60cdf53ce9cf4b11a9795dab5b40d6..07f093a1e30a7e4e41639b554b652d1dff18b83e 100644 (file)
@@ -1,5 +1,9 @@
 2018-02-16  Jason Merrill  <jason@redhat.com>
 
+       PR c++/82664 - ICE with reference to function template parm.
+       * pt.c (convert_nontype_argument_function): Avoid obfuscationg
+       NOP_EXPRs.
+
        PR c++/82764 - C++17 ICE with empty base
        * class.c (build_base_field_1): Set DECL_SIZE to zero for empty base.
 
index 268cfe5a4548b6ab9e9306423c57b48dfb68bacd..89790717ecad2a51c5e02e6506c9ec496e556ed0 100644 (file)
@@ -6143,7 +6143,12 @@ convert_nontype_argument_function (tree type, tree expr,
 
  accept:
   if (TREE_CODE (type) == REFERENCE_TYPE)
-    fn = build_address (fn);
+    {
+      if (REFERENCE_REF_P (fn))
+       fn = TREE_OPERAND (fn, 0);
+      else
+       fn = build_address (fn);
+    }
   if (!same_type_ignoring_top_level_qualifiers_p (type, TREE_TYPE (fn)))
     fn = build_nop (type, fn);
 
diff --git a/gcc/testsuite/g++.dg/template/nontype-fn1.C b/gcc/testsuite/g++.dg/template/nontype-fn1.C
new file mode 100644 (file)
index 0000000..12d29a9
--- /dev/null
@@ -0,0 +1,11 @@
+// PR c++/82664
+
+template < typename > struct target_disambiguator;
+template < typename R, typename A1 > struct target_disambiguator< R(A1) > {
+  typedef A1 type;
+  template < R (&)() > struct layout;
+};
+
+int main() {
+  typedef target_disambiguator< void (int) > ::type target_type ;
+}