Commit d67a3e2a by Andrew Pinski Committed by Jakub Jelinek

re PR c++/36695 (Value-initialization of reference type is allowed.)

	PR c++/36695
	* typeck2.c (build_functional_cast): Check for reference type and NULL
	PARMS.
                                                                                                                                         
	* g++.dg/ext/complex4.C: New test.
	* g++.dg/ext/complex5.C: New test.
	* g++.dg/init/reference1.C: New test.
	* g++.dg/init/reference2.C: New test.
	* g++.dg/init/reference3.C: New test.

From-SVN: r143244
parent 56dbbf56
2009-01-10 Andrew Pinski <pinskia@gmail.com>
PR c++/36695
* typeck2.c (build_functional_cast): Check for reference type and NULL
PARMS.
2009-01-09 Steve Ellcey <sje@cup.hp.com> 2009-01-09 Steve Ellcey <sje@cup.hp.com>
* typeck.c (cp_build_unary_op): Check for ERROR_MARK. * typeck.c (cp_build_unary_op): Check for ERROR_MARK.
......
...@@ -1445,6 +1445,12 @@ build_functional_cast (tree exp, tree parms, tsubst_flags_t complain) ...@@ -1445,6 +1445,12 @@ build_functional_cast (tree exp, tree parms, tsubst_flags_t complain)
else else
type = exp; type = exp;
if (TREE_CODE (type) == REFERENCE_TYPE && !parms)
{
error ("invalid value-initialization of reference types");
return error_mark_node;
}
if (processing_template_decl) if (processing_template_decl)
{ {
tree t = build_min (CAST_EXPR, type, parms); tree t = build_min (CAST_EXPR, type, parms);
......
2009-01-10 Andrew Pinski <pinskia@gmail.com>
PR c++/36695
* g++.dg/ext/complex4.C: New test.
* g++.dg/ext/complex5.C: New test.
* g++.dg/init/reference1.C: New test.
* g++.dg/init/reference2.C: New test.
* g++.dg/init/reference3.C: New test.
2009-01-10 Paul Thomas <pault@gcc.gnu.org> 2009-01-10 Paul Thomas <pault@gcc.gnu.org>
PR fortran/38763 PR fortran/38763
......
// { dg-do compile }
// This code used to be rejected as there was no conversion from int to float __complex__
#include <vector>
typedef float __complex__ fcomplex;
std::vector<fcomplex> vfc(10);
/* PR c++/21210 */
/* { dg-do compile } */
/* { dg-options "-O2" } */
typedef float __complex__ fcomplex;
fcomplex cplx = fcomplex(0);
// { dg-do compile }
// This code used to be accepted but it is invalid as there is no
// value initialization of a reference type.
// PR c++/36695
int main()
{
typedef int& T;
T a = T(); // { dg-error "value-initialization of reference" }
}
// { dg-do compile }
// This code used to be accepted but it is invalid as there is no
// value initialization of a reference type.
// PR c++/36695
// We should we able to diagnostic this without instantiating the template
template <int a1>
int f()
{
typedef int& T;
T a = T(); // { dg-error "value-initialization of reference" }
}
// { dg-do compile }
// This code used to be accepted but it is invalid as there is no
// value initialization of a reference type.
// PR c++/36695
template <typename T>
T f()
{
T a = T(); // { dg-error "value-initialization of reference" }
}
int &a = f<int&>(); // { dg-message "instantiated from here" }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment