re PR c++/12163 (static_cast + explicit ctor regression)

PR c++/12163
	* call.c (perform_direct_initialization): Correct logic for
	direct-initialization of a class type.

	PR c++/12146
	* pt.c (lookup_template_function): Robustify.

	PR c++/12163
	* g++.dg/expr/static_cast4.C: New test.

	PR c++/12146
	* g++.dg/template/crash9.C: New test.

From-SVN: r71115
This commit is contained in:
Mark Mitchell 2003-09-05 18:04:21 +00:00 committed by Mark Mitchell
parent 3f8dc57bd2
commit ceeae2d125
6 changed files with 57 additions and 2 deletions

View file

@ -1,3 +1,12 @@
2003-09-05 Mark Mitchell <mark@codesourcery.com>
PR c++/12163
* call.c (perform_direct_initialization): Correct logic for
direct-initialization of a class type.
PR c++/12146
* pt.c (lookup_template_function): Robustify.
2003-09-05 Nathan Sidwell <nathan@codesourcery.com>
PR c++/11922

View file

@ -5951,7 +5951,8 @@ perform_implicit_conversion (tree type, tree expr)
/* Convert EXPR to TYPE (as a direct-initialization) if that is
permitted. If the conversion is valid, the converted expression is
returned. Otherwise, NULL_TREE is returned. */
returned. Otherwise, NULL_TREE is returned, except in the case
that TYPE is a class type; in that case, an error is issued. */
tree
perform_direct_initialization_if_possible (tree type, tree expr)
@ -5960,6 +5961,19 @@ perform_direct_initialization_if_possible (tree type, tree expr)
if (type == error_mark_node || error_operand_p (expr))
return error_mark_node;
/* [dcl.init]
If the destination type is a (possibly cv-qualified) class type:
-- If the initialization is direct-initialization ...,
constructors are considered. ... If no constructor applies, or
the overload resolution is ambiguous, the initialization is
ill-formed. */
if (CLASS_TYPE_P (type))
return build_special_member_call (NULL_TREE, complete_ctor_identifier,
build_tree_list (NULL_TREE, expr),
TYPE_BINFO (type),
LOOKUP_NORMAL);
conv = implicit_conversion (type, TREE_TYPE (expr), expr,
LOOKUP_NORMAL);
if (!conv || ICS_BAD_FLAG (conv))

View file

@ -3854,7 +3854,8 @@ lookup_template_function (tree fns, tree arglist)
return error_mark_node;
my_friendly_assert (!arglist || TREE_CODE (arglist) == TREE_VEC, 20030726);
if (fns == NULL_TREE)
if (fns == NULL_TREE
|| TREE_CODE (fns) == FUNCTION_DECL)
{
error ("non-template used as template");
return error_mark_node;

View file

@ -1,3 +1,11 @@
2003-09-05 Mark Mitchell <mark@codesourcery.com>
PR c++/12163
* g++.dg/expr/static_cast4.C: New test.
PR c++/12146
* g++.dg/template/crash9.C: New test.
2003-09-05 Andrew Pinski <pinskia@physics.uc.edu>
* g++.old-deja/g++.ext/pretty2.C: Update for change

View file

@ -0,0 +1,11 @@
class C {
public:
explicit C(int) {}
};
int main()
{
int i = 0;
static_cast<C>(i);
return 0;
}

View file

@ -0,0 +1,12 @@
struct A { };
struct B { };
A f(const B & b) {
return A();
}
template<>
B f(const A & a) { // { dg-error "" }
return B();
}