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.
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 */
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;
+}
\f
/* Return zero if something is declared to be a member of type
CTYPE when in the context of CUR_TYPE. STRING is the error
&& 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. */
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.
--- /dev/null
+// 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)