Hi,
I'm finishing (in the C++ library testsuite now) testing this
straightforward patch for a couple of "standard" SFINAE issues
(interestingly, however, 54541 is a regression in mainline).
Ok for mainline?
Thanks,
Paolo.
PS: I suspect that the require_complete_type in convert_arg_to_ellipsis
should also be require_complete_type_sfinae
////////////////////
/cp
2012-09-11 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/54541
PR c++/54542
* call.c (build_cxx_call): Add tsubst_flags_t parameter, use
require_complete_type_sfinae.
(build_op_delete_call, build_over_call): Adjust.
* typeck.c (build_x_compound_expr_from_vec): Add tsubst_flags_t
parameter.
(cp_build_function_call_vec): Adjust.
* init.c (build_new_1): Likewise.
* rtti.c (throw_bad_cast, throw_bad_typeid, build_dynamic_cast_1):
Likewise.
* optimize.c (build_delete_destructor_body): Likewise.
* cp-tree.h: Adjust declarations.
/testsuite
2012-09-11 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/54541
PR c++/54542
* g++.dg/cpp0x/sfinae40.C: New.
* g++.dg/cpp0x/sfinae41.C: Likewise.
Index: testsuite/g++.dg/cpp0x/sfinae40.C
===================================================================
--- testsuite/g++.dg/cpp0x/sfinae40.C (revision 0)
+++ testsuite/g++.dg/cpp0x/sfinae40.C (revision 0)
@@ -0,0 +1,21 @@
+// PR c++/54541
+// { dg-do compile { target c++11 } }
+
+template <typename T> T&& declval();
+
+struct X;
+
+X f(int);
+
+template <class T>
+void g(decltype((void)f(declval<T>())) *)
+{}
+
+template <class T>
+void g(...)
+{}
+
+int main()
+{
+ g<int>(0);
+}
Index: testsuite/g++.dg/cpp0x/sfinae41.C
===================================================================
--- testsuite/g++.dg/cpp0x/sfinae41.C (revision 0)
+++ testsuite/g++.dg/cpp0x/sfinae41.C (revision 0)
@@ -0,0 +1,17 @@
+// PR c++/54542
+// { dg-do compile { target c++11 } }
+
+template <class T>
+void f(decltype(new T(1, 2)) *)
+{
+ T(1, 2);
+}
+
+template <class T>
+void f(...)
+{}
+
+int main()
+{
+ f<int>(0);
+}
Index: cp/typeck.c
===================================================================
--- cp/typeck.c (revision 191162)
+++ cp/typeck.c (working copy)
@@ -3373,7 +3373,7 @@ cp_build_function_call_vec (tree function, VEC(tre
null parameters. */
check_function_arguments (fntype, nargs, argarray);
- ret = build_cxx_call (function, nargs, argarray);
+ ret = build_cxx_call (function, nargs, argarray, complain);
if (allocated != NULL)
release_tree_vector (allocated);
@@ -5719,7 +5719,8 @@ build_x_compound_expr_from_list (tree list, expr_l
/* Like build_x_compound_expr_from_list, but using a VEC. */
tree
-build_x_compound_expr_from_vec (VEC(tree,gc) *vec, const char *msg)
+build_x_compound_expr_from_vec (VEC(tree,gc) *vec, const char *msg,
+ tsubst_flags_t complain)
{
if (VEC_empty (tree, vec))
return NULL_TREE;
@@ -5732,14 +5733,19 @@ tree
tree t;
if (msg != NULL)
- permerror (input_location,
- "%s expression list treated as compound expression",
- msg);
+ {
+ if (complain & tf_error)
+ permerror (input_location,
+ "%s expression list treated as compound expression",
+ msg);
+ else
+ return error_mark_node;
+ }
expr = VEC_index (tree, vec, 0);
for (ix = 1; VEC_iterate (tree, vec, ix, t); ++ix)
expr = build_x_compound_expr (EXPR_LOCATION (t), expr,
- t, tf_warning_or_error);
+ t, complain);
return expr;
}
Index: cp/optimize.c
===================================================================
--- cp/optimize.c (revision 191162)
+++ cp/optimize.c (working copy)
@@ -128,7 +128,8 @@ build_delete_destructor_body (tree delete_dtor, tr
/* Call the corresponding complete destructor. */
gcc_assert (complete_dtor);
- call_dtor = build_cxx_call (complete_dtor, 1, &parm);
+ call_dtor = build_cxx_call (complete_dtor, 1, &parm,
+ tf_warning_or_error);
add_stmt (call_dtor);
add_stmt (build_stmt (0, LABEL_EXPR, cdtor_label));
Index: cp/init.c
===================================================================
--- cp/init.c (revision 191162)
+++ cp/init.c (working copy)
@@ -2740,7 +2740,8 @@ build_new_1 (VEC(tree,gc) **placement, tree type,
/* We are processing something like `new int (10)', which
means allocate an int, and initialize it with 10. */
- ie = build_x_compound_expr_from_vec (*init, "new initializer");
+ ie = build_x_compound_expr_from_vec (*init, "new initializer",
+ complain);
init_expr = cp_build_modify_expr (init_expr, INIT_EXPR, ie,
complain);
}
Index: cp/rtti.c
===================================================================
--- cp/rtti.c (revision 191162)
+++ cp/rtti.c (working copy)
@@ -206,7 +206,7 @@ throw_bad_cast (void)
fn = push_throw_library_fn (fn, build_function_type_list (ptr_type_node,
NULL_TREE));
- return build_cxx_call (fn, 0, NULL);
+ return build_cxx_call (fn, 0, NULL, tf_warning_or_error);
}
/* Return an expression for "__cxa_bad_typeid()". The expression
@@ -225,7 +225,7 @@ throw_bad_typeid (void)
fn = push_throw_library_fn (fn, t);
}
- return build_cxx_call (fn, 0, NULL);
+ return build_cxx_call (fn, 0, NULL, tf_warning_or_error);
}
/* Return an lvalue expression whose type is "const std::type_info"
@@ -743,7 +743,7 @@ build_dynamic_cast_1 (tree type, tree expr, tsubst
pop_abi_namespace ();
dynamic_cast_node = dcast_fn;
}
- result = build_cxx_call (dcast_fn, 4, elems);
+ result = build_cxx_call (dcast_fn, 4, elems, complain);
if (tc == REFERENCE_TYPE)
{
Index: cp/call.c
===================================================================
--- cp/call.c (revision 191162)
+++ cp/call.c (working copy)
@@ -5525,7 +5525,7 @@ build_op_delete_call (enum tree_code code, tree ad
for (i = 1; i < nargs; i++)
argarray[i] = CALL_EXPR_ARG (placement, i);
mark_used (fn);
- return build_cxx_call (fn, nargs, argarray);
+ return build_cxx_call (fn, nargs, argarray, complain);
}
else
{
@@ -6882,7 +6882,7 @@ build_over_call (struct z_candidate *cand, int fla
return error_mark_node;
}
- return build_cxx_call (fn, nargs, argarray);
+ return build_cxx_call (fn, nargs, argarray, complain);
}
/* Build and return a call to FN, using NARGS arguments in ARGARRAY.
@@ -6890,7 +6890,8 @@ build_over_call (struct z_candidate *cand, int fla
high-level operations. */
tree
-build_cxx_call (tree fn, int nargs, tree *argarray)
+build_cxx_call (tree fn, int nargs, tree *argarray,
+ tsubst_flags_t complain)
{
tree fndecl;
int optimize_sav;
@@ -6923,12 +6924,12 @@ tree
if (VOID_TYPE_P (TREE_TYPE (fn)))
return fn;
- fn = require_complete_type (fn);
+ fn = require_complete_type_sfinae (fn, complain);
if (fn == error_mark_node)
return error_mark_node;
if (MAYBE_CLASS_TYPE_P (TREE_TYPE (fn)))
- fn = build_cplus_new (TREE_TYPE (fn), fn, tf_warning_or_error);
+ fn = build_cplus_new (TREE_TYPE (fn), fn, complain);
return convert_from_reference (fn);
}
Index: cp/cp-tree.h
===================================================================
--- cp/cp-tree.h (revision 191162)
+++ cp/cp-tree.h (working copy)
@@ -4918,7 +4918,8 @@ extern tree build_integral_nontype_arg_conv (tree,
extern tree perform_direct_initialization_if_possible (tree, tree, bool,
tsubst_flags_t);
extern tree in_charge_arg_for_name (tree);
-extern tree build_cxx_call (tree, int, tree *);
+extern tree build_cxx_call (tree, int, tree *,
+ tsubst_flags_t);
extern bool is_std_init_list (tree);
extern bool is_list_ctor (tree);
#ifdef ENABLE_CHECKING
@@ -5851,7 +5852,8 @@ extern tree build_x_conditional_expr
(location_t,
tsubst_flags_t);
extern tree build_x_compound_expr_from_list (tree, expr_list_kind,
tsubst_flags_t);
-extern tree build_x_compound_expr_from_vec (VEC(tree,gc) *, const char *);
+extern tree build_x_compound_expr_from_vec (VEC(tree,gc) *, const char *,
+ tsubst_flags_t);
extern tree build_x_compound_expr (location_t, tree, tree,
tsubst_flags_t);
extern tree build_compound_expr (location_t, tree, tree);