re PR c++/48535 ([C++0x][SFINAE] Hard errors during list-value-initialization)

PR c++/48535
	* decl.c (cp_complete_array_type_or_error): New.
	* semantics.c (finish_compound_literal): Use it.
	* cp-tree.h: Declare it.

From-SVN: r172287
This commit is contained in:
Jason Merrill 2011-04-11 18:01:04 -04:00 committed by Jason Merrill
parent 76186d20cc
commit 80c6dcf59b
6 changed files with 67 additions and 2 deletions

View File

@ -1,5 +1,10 @@
2011-04-11 Jason Merrill <jason@redhat.com>
PR c++/48535
* decl.c (cp_complete_array_type_or_error): New.
* semantics.c (finish_compound_literal): Use it.
* cp-tree.h: Declare it.
PR c++/48535
* semantics.c (finish_compound_literal): Handle references.

View File

@ -4791,6 +4791,7 @@ extern void start_decl_1 (tree, bool);
extern bool check_array_initializer (tree, tree, tree);
extern void cp_finish_decl (tree, tree, bool, tree, int);
extern int cp_complete_array_type (tree *, tree, bool);
extern int cp_complete_array_type_or_error (tree *, tree, bool, tsubst_flags_t);
extern tree build_ptrmemfunc_type (tree);
extern tree build_ptrmem_type (tree, tree);
/* the grokdeclarator prototype is in decl.h */

View File

@ -6689,6 +6689,39 @@ cp_complete_array_type (tree *ptype, tree initial_value, bool do_default)
return failure;
}
/* As above, but either give an error or reject zero-size arrays, depending
on COMPLAIN. */
int
cp_complete_array_type_or_error (tree *ptype, tree initial_value,
bool do_default, tsubst_flags_t complain)
{
int failure;
bool sfinae = !(complain & tf_error);
/* In SFINAE context we can't be lenient about zero-size arrays. */
if (sfinae)
++pedantic;
failure = cp_complete_array_type (ptype, initial_value, do_default);
if (sfinae)
--pedantic;
if (failure)
{
if (sfinae)
/* Not an error. */;
else if (failure == 1)
error ("initializer fails to determine size of %qT", *ptype);
else if (failure == 2)
{
if (do_default)
error ("array size missing in %qT", *ptype);
}
else if (failure == 3)
error ("zero-size array %qT", *ptype);
*ptype = error_mark_node;
}
return failure;
}
/* Return zero if something is declared to be a member of type
CTYPE when in the context of CUR_TYPE. STRING is the error

View File

@ -2355,8 +2355,14 @@ finish_compound_literal (tree type, tree compound_literal,
&& check_array_initializer (NULL_TREE, type, compound_literal))
return error_mark_node;
compound_literal = reshape_init (type, compound_literal);
if (TREE_CODE (type) == ARRAY_TYPE)
cp_complete_array_type (&type, compound_literal, false);
if (TREE_CODE (type) == ARRAY_TYPE
&& TYPE_DOMAIN (type) == NULL_TREE)
{
cp_complete_array_type_or_error (&type, compound_literal,
false, complain);
if (type == error_mark_node)
return error_mark_node;
}
compound_literal = digest_init (type, compound_literal);
/* Put static/constant array temporaries in static variables, but always
represent class temporaries with TARGET_EXPR so we elide copies. */

View File

@ -1,5 +1,7 @@
2011-04-11 Jason Merrill <jason@redhat.com>
* g++.dg/cpp0x/sfinae12.C: New.
* g++.dg/cpp0x/enum10.C: New.
* g++.dg/cpp0x/lambda/lambda-this4.C: New.

View File

@ -0,0 +1,18 @@
// PR c++/48535
// { dg-options -std=c++0x }
template<class T,
class = decltype(T{})
>
char f(int);
template<class>
char (&f(...))[2];
struct A { virtual ~A() = 0; };
static_assert(sizeof(f<A>(0)) != 1, "Error"); // (a)
static_assert(sizeof(f<void()>(0)) != 1, "Error"); // (b)
static_assert(sizeof(f<int&>(0)) != 1, "Error"); // (d)
static_assert(sizeof(f<const int&>(0)) == 1, "Error"); // (e)
static_assert(sizeof(f<int[]>(0)) != 1, "Error"); // (f)