re PR c++/13833 (Conversion problem in template function)
authorMark Mitchell <mark@codesourcery.com>
Mon, 26 Jan 2004 03:13:49 +0000 (03:13 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Mon, 26 Jan 2004 03:13:49 +0000 (03:13 +0000)
PR c++/13833
* call.c (build_over_call): Do not convert arguments when
processing a template.
* pt.c (build_non_dependent_expr): Do not build a
NON_DEPENDENT_EXPR for arithmetic constants.

PR c++/13833
* g++.dg/template/cond3.C: New test.

From-SVN: r76616

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

index 5171c70f96334c232cfd7071b47993af110e6e7b..a463df6d813e5b36b0cbf3e3c1b33d3a3b3cad99 100644 (file)
@@ -1,3 +1,11 @@
+2004-01-25  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/13833
+       * call.c (build_over_call): Do not convert arguments when
+       processing a template.
+       * pt.c (build_non_dependent_expr): Do not build a
+       NON_DEPENDENT_EXPR for arithmetic constants.
+
 2004-01-25  Giovanni Bajo  <giovannibajo@gcc.gnu.org>
 
        PR c++/13810
index 5fefefe6a9e1a28dbe7c7fb595cb285016e17678..ea494c7b8c5a669fd318346329e32ad087b980c4 100644 (file)
@@ -4306,6 +4306,21 @@ build_over_call (struct z_candidate *cand, int flags)
   int i = 0;
   int is_method = 0;
 
+  /* In a template, there is no need to perform all of the work that
+     is normally done.  We are only interested in the type of the call
+     expression, i.e., the return type of the function.  Any semantic
+     errors will be deferred until the template is instantiated.  */
+  if (processing_template_decl)
+    {
+      tree expr;
+      tree return_type;
+      return_type = TREE_TYPE (TREE_TYPE (fn));
+      expr = build (CALL_EXPR, return_type, fn, args);
+      if (!VOID_TYPE_P (return_type))
+       require_complete_type (return_type);
+      return convert_from_reference (expr);
+    }
+
   /* Give any warnings we noticed during overload resolution.  */
   if (cand->warnings)
     for (val = cand->warnings; val; val = TREE_CHAIN (val))
index 2178e90e924bda2ed292d8430f30db37599f82c4..a9ab858ff96cec1a4000df11a1bea22f0c33da0a 100644 (file)
@@ -11993,6 +11993,10 @@ build_non_dependent_expr (tree expr)
      cannot be used to initialize a "char *".  */
   if (TREE_CODE (expr) == STRING_CST)
     return expr;
+  /* Preserve arithmetic constants, as an optimization -- there is no
+     reason to create a new node.  */
+  if (TREE_CODE (expr) == INTEGER_CST || TREE_CODE (expr) == REAL_CST)
+    return expr;
 
   if (TREE_CODE (expr) == COND_EXPR)
     return build (COND_EXPR,
index a8a7b5d0d16faf986d7000e3dbc61dbe2c862ab6..b1920033286edd53021b52e9e1c04b110b15ed08 100644 (file)
@@ -1,3 +1,8 @@
+2004-01-25  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/13833
+       * g++.dg/template/cond3.C: New test.
+
 2004-01-25  Giovanni Bajo  <giovannibajo@gcc.gnu.org>
 
        PR c++/13810
diff --git a/gcc/testsuite/g++.dg/template/cond3.C b/gcc/testsuite/g++.dg/template/cond3.C
new file mode 100644 (file)
index 0000000..788b375
--- /dev/null
@@ -0,0 +1,15 @@
+// PR c++/13833
+
+struct X { 
+  template <typename T> 
+  X & operator << (const T &t); 
+  X & operator<< (int& (*p) (int&)); 
+}; 
+X x; 
+template <int> void foo () { 
+  x << (1 ? "ok" : "failed"); 
+} 
+template void foo<1>();