re PR c++/32839 (internal compiler error: Segmentation fault (templates))
authorNathan Sidwell <nathan@codesourcery.com>
Sun, 22 Jul 2007 18:46:51 +0000 (18:46 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Sun, 22 Jul 2007 18:46:51 +0000 (18:46 +0000)
cp/
PR c++/32839
* typeck.c (convert_arguments): Only use default args if we have
a function decl.

testsuite/
PR c++/32839
* g++.dg/expr/call4.C: New.
* g++.dg/expr/call5.C: New.

From-SVN: r126829

gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/expr/call4.C [new file with mode: 0644]
gcc/testsuite/g++.dg/expr/call5.C [new file with mode: 0644]

index 6faa01f80a112957ac5a84e338471817855dd410..39da6aaf3ff1a541671ab379879cec4dd209bcaf 100644 (file)
@@ -1,5 +1,9 @@
 2007-07-22  Nathan Sidwell  <nathan@codesourcery.com>
 
+       PR c++/32839
+       * typeck.c (convert_arguments): Only use default args if we have
+       a function decl.
+
        PR c++/30818
        * typeck.c (structural_comptypes): No need to check
        resolve_typename_type return value here.
index 7e59ec36b0584e93e76a51ff16bf08aa9574d19f..7a1a725b69a9dbdb837d5eedd99757629bf9ac5e 100644 (file)
@@ -2885,8 +2885,14 @@ convert_arguments (int nargs, tree *argarray,
 
   if (typetail != 0 && typetail != void_list_node)
     {
-      /* See if there are default arguments that can be used.  */
-      if (TREE_PURPOSE (typetail)
+      /* See if there are default arguments that can be used.  Because
+        we hold default arguments in the FUNCTION_TYPE (which is so
+        wrong), we can see default parameters here from deduced
+        contexts (and via typeof) for indirect function calls.
+        Fortunately we know whether we have a function decl to
+        provide default arguments in a language conformant
+        manner.  */
+      if (fndecl && TREE_PURPOSE (typetail)
          && TREE_CODE (TREE_PURPOSE (typetail)) != DEFAULT_ARG)
        {
          for (; typetail != void_list_node; ++i)
index 17989ace25a4d905cb7c72e317f002ebf8792d33..2cf110b2181221b6f091d421cc923c6d419b87e6 100644 (file)
@@ -1,3 +1,9 @@
+2007-07-22  Nathan Sidwell  <nathan@codesourcery.com>
+
+       PR c++/32839
+       * g++.dg/expr/call4.C: New.
+       * g++.dg/expr/call5.C: New.
+
 2007-07-22  Daniel Franke  <franke.daniel@gmail.com>
 
        PR fortran/32710
diff --git a/gcc/testsuite/g++.dg/expr/call4.C b/gcc/testsuite/g++.dg/expr/call4.C
new file mode 100644 (file)
index 0000000..b4f2d60
--- /dev/null
@@ -0,0 +1,27 @@
+// { dg-do compile }
+
+// Copyright (C) 2007 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 22 Jul 2007 <nathan@codesourcery.com>
+
+// Origin: Danny Boelens <danny.boelens@artwork-systems.com>
+// PR 32839.  Default arguments propagated through the type system to
+// an indirect call.
+
+template<typename T>
+struct TPL
+{
+  enum Whatever {e1, e2};
+  static void Quux (int i = e1 | e2);
+};
+
+template <typename F>
+void DoIt (F fun)
+{
+  fun (); // { dg-error "too few arguments" }
+}
+
+void Foo ()
+{
+  DoIt (&TPL<int>::Quux);
+}
diff --git a/gcc/testsuite/g++.dg/expr/call5.C b/gcc/testsuite/g++.dg/expr/call5.C
new file mode 100644 (file)
index 0000000..023ad81
--- /dev/null
@@ -0,0 +1,19 @@
+// { dg-do compile }
+
+// Copyright (C) 2007 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 22 Jul 2007 <nathan@codesourcery.com>
+
+// PR 32839.  Default arguments propagated through the type system to
+// an indirect call.
+
+void Quux (int i = 0);
+void Baz (int i);
+
+void Foo ()
+{
+  __typeof (Quux) *q = Baz;
+
+  q (); // { dg-error "too few arguments" }
+}
+
+