summaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/ChangeLog65
-rw-r--r--gcc/cp/class.c25
-rw-r--r--gcc/cp/cp-tree.def2
-rw-r--r--gcc/cp/cp-tree.h9
-rw-r--r--gcc/cp/decl.c14
-rw-r--r--gcc/cp/error.c1
-rw-r--r--gcc/cp/pt.c112
-rw-r--r--gcc/cp/ptree.c4
-rw-r--r--gcc/cp/search.c8
-rw-r--r--gcc/cp/semantics.c4
-rw-r--r--gcc/cp/tree.c2
-rw-r--r--gcc/cp/typeck.c6
12 files changed, 215 insertions, 37 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 4e5b26523e1..c08314449bf 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,68 @@
+2011-11-20 Jason Merrill <jason@redhat.com>
+
+ * pt.c (tsubst_pack_expansion): Fix SFINAE.
+
+ PR c++/48322
+ * cp-tree.h (PACK_EXPANSION_EXTRA_ARGS): New.
+ * cp-tree.def (EXPR_PACK_EXPANSION): Add an operand for it.
+ * pt.c (tsubst_pack_expansion): Set and use it.
+ (iterative_hash_template_arg): Hash it.
+ (template_args_equal): Compare it.
+ (comp_template_args_with_info): Handle nulls.
+ * tree.c (cp_walk_subtrees): Walk it.
+ * typeck.c (structural_comptypes): Compare it.
+ * ptree.c (cxx_print_type): Print it.
+
+ * pt.c (type_unification_real): Set input_location
+ during default arg instantiation.
+
+2011-11-20 Paolo Carlini <paolo.carlini@oracle.com>
+
+ PR c++/51230
+ * pt.c (unify_inconsistency): Handle non-type parameters better.
+ * error.c (dump_expr): Handle TEMPLATE_TEMPLATE_PARM.
+
+2011-11-20 Dodji Seketeli <dodji@redhat.com>
+
+ PR c++/51194
+ * pt.c (lookup_template_class_1): Go out early if the type of the
+ template is error_mark_node.
+
+2011-11-19 Paolo Carlini <paolo.carlini@oracle.com>
+
+ PR c++/51216
+ * semantics.c (potential_constant_expression_1): Handle IF_STMT,
+ DO_STMT, FOR_STMT, and WHILE_STMT.
+
+2011-11-18 Fabien ChĂȘne <fabien@gcc.gnu.org>
+
+ PR c++/51188
+ * search.c (lookup_field_1): Handle USING_DECLs for the storted
+ case.
+
+2011-11-18 Paolo Carlini <paolo.carlini@oracle.com>
+
+ PR c++/51150
+ * pt.c (tsubst_copy_and_build): Handle FIX_TRUNC_EXPR.
+
+2011-11-18 Dodji Seketeli <dodji@redhat.com>
+
+ PR c++/51191
+ * pt.c (primary_template_instantiation_p): Don't forget to
+ consider alias declarations.
+
+2011-11-17 Jason Merrill <jason@redhat.com>
+
+ PR c++/51186
+ * decl.c (grokdeclarator): Improve C++98 trailing return diagnostic.
+
+ N3203
+ * class.c (add_implicitly_declared_members): Update move
+ conditions.
+
+ PR c++/51137
+ * class.c (build_base_path): Don't do calculation in templates.
+
2011-11-15 Torvald Riegel <triegel@redhat.com>
* parser.c (cp_parser_transaction_expression): Require parentheses
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index 4a291acca8a..cb0e683c597 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -304,8 +304,13 @@ build_base_path (enum tree_code code,
virtual_access = (v_binfo && fixed_type_p <= 0);
/* Don't bother with the calculations inside sizeof; they'll ICE if the
- source type is incomplete and the pointer value doesn't matter. */
- if (cp_unevaluated_operand != 0)
+ source type is incomplete and the pointer value doesn't matter. In a
+ template (even in fold_non_dependent_expr), we don't have vtables set
+ up properly yet, and the value doesn't matter there either; we're just
+ interested in the result of overload resolution. */
+ if (cp_unevaluated_operand != 0
+ || (current_function_decl
+ && uses_template_parms (current_function_decl)))
{
expr = build_nop (ptr_target_type, expr);
if (!want_pointer)
@@ -359,11 +364,6 @@ build_base_path (enum tree_code code,
V_BINFO. That offset is an entry in D_BINFO's vtable. */
tree v_offset;
- /* In a constructor template, current_in_charge_parm isn't set,
- and we might end up here via fold_non_dependent_expr. */
- if (fixed_type_p < 0 && !(cfun && current_in_charge_parm))
- fixed_type_p = 0;
-
if (fixed_type_p < 0 && in_base_initializer)
{
/* In a base member initializer, we cannot rely on the
@@ -2721,6 +2721,13 @@ add_implicitly_declared_members (tree t,
int cant_have_const_cctor,
int cant_have_const_assignment)
{
+ bool move_ok = false;
+
+ if (cxx_dialect >= cxx0x && !CLASSTYPE_DESTRUCTORS (t)
+ && !TYPE_HAS_COPY_CTOR (t) && !TYPE_HAS_COPY_ASSIGN (t)
+ && !type_has_move_constructor (t) && !type_has_move_assign (t))
+ move_ok = true;
+
/* Destructor. */
if (!CLASSTYPE_DESTRUCTORS (t))
{
@@ -2758,7 +2765,7 @@ add_implicitly_declared_members (tree t,
TYPE_HAS_COPY_CTOR (t) = 1;
TYPE_HAS_CONST_COPY_CTOR (t) = !cant_have_const_cctor;
CLASSTYPE_LAZY_COPY_CTOR (t) = 1;
- if (cxx_dialect >= cxx0x && !type_has_move_constructor (t))
+ if (move_ok)
CLASSTYPE_LAZY_MOVE_CTOR (t) = 1;
}
@@ -2771,7 +2778,7 @@ add_implicitly_declared_members (tree t,
TYPE_HAS_COPY_ASSIGN (t) = 1;
TYPE_HAS_CONST_COPY_ASSIGN (t) = !cant_have_const_assignment;
CLASSTYPE_LAZY_COPY_ASSIGN (t) = 1;
- if (cxx_dialect >= cxx0x && !type_has_move_assign (t))
+ if (move_ok)
CLASSTYPE_LAZY_MOVE_ASSIGN (t) = 1;
}
diff --git a/gcc/cp/cp-tree.def b/gcc/cp/cp-tree.def
index 4eec9f97c7d..5fc5496ef9e 100644
--- a/gcc/cp/cp-tree.def
+++ b/gcc/cp/cp-tree.def
@@ -419,7 +419,7 @@ DEFTREECODE (TYPE_PACK_EXPANSION, "type_pack_expansion", tcc_type, 0)
EXPR_PACK_EXPANSION plays precisely the same role as TYPE_PACK_EXPANSION,
but will be used for expressions. */
-DEFTREECODE (EXPR_PACK_EXPANSION, "expr_pack_expansion", tcc_expression, 2)
+DEFTREECODE (EXPR_PACK_EXPANSION, "expr_pack_expansion", tcc_expression, 3)
/* Selects the Ith parameter out of an argument pack. This node will
be used when instantiating pack expansions; see
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index fe50e34e7d9..3f4f4081f38 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -2813,7 +2813,14 @@ extern void decl_shadowed_for_var_insert (tree, tree);
#define PACK_EXPANSION_PARAMETER_PACKS(NODE) \
*(TREE_CODE (NODE) == EXPR_PACK_EXPANSION \
? &TREE_OPERAND (NODE, 1) \
- : &TREE_CHAIN (TYPE_PACK_EXPANSION_CHECK (NODE)))
+ : &TYPE_MINVAL (TYPE_PACK_EXPANSION_CHECK (NODE)))
+
+/* Any additional template args to be applied when substituting into
+ the pattern, set by tsubst_pack_expansion for partial instantiations. */
+#define PACK_EXPANSION_EXTRA_ARGS(NODE) \
+ *(TREE_CODE (NODE) == TYPE_PACK_EXPANSION \
+ ? &TYPE_MAXVAL (NODE) \
+ : &TREE_OPERAND ((NODE), 2))
/* Determine if this is an argument pack. */
#define ARGUMENT_PACK_P(NODE) \
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index d744da85f3e..b77963b72df 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -9126,12 +9126,12 @@ grokdeclarator (const cp_declarator *declarator,
if (!declarator->u.function.late_return_type)
{
error ("%qs function uses %<auto%> type specifier without"
- " late return type", name);
+ " trailing return type", name);
return error_mark_node;
}
else if (!is_auto (type))
{
- error ("%qs function with late return type has"
+ error ("%qs function with trailing return type has"
" %qT as its type rather than plain %<auto%>",
name, type);
return error_mark_node;
@@ -9139,8 +9139,14 @@ grokdeclarator (const cp_declarator *declarator,
}
else if (declarator->u.function.late_return_type)
{
- error ("%qs function with late return type not declared"
- " with %<auto%> type specifier", name);
+ if (cxx_dialect < cxx0x)
+ /* Not using maybe_warn_cpp0x because this should
+ always be an error. */
+ error ("trailing return type only available with "
+ "-std=c++11 or -std=gnu++11");
+ else
+ error ("%qs function with trailing return type not "
+ "declared with %<auto%> type specifier", name);
return error_mark_node;
}
}
diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index 602cb75236a..4940a783353 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -2406,6 +2406,7 @@ dump_expr (tree t, int flags)
break;
case TEMPLATE_TYPE_PARM:
+ case TEMPLATE_TEMPLATE_PARM:
case BOUND_TEMPLATE_TEMPLATE_PARM:
dump_type (t, flags);
break;
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 97380260ae4..2ba26b206bd 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -1534,7 +1534,8 @@ iterative_hash_template_arg (tree arg, hashval_t val)
case TYPE_PACK_EXPANSION:
case EXPR_PACK_EXPANSION:
- return iterative_hash_template_arg (PACK_EXPANSION_PATTERN (arg), val);
+ val = iterative_hash_template_arg (PACK_EXPANSION_PATTERN (arg), val);
+ return iterative_hash_template_arg (PACK_EXPANSION_EXTRA_ARGS (arg), val);
case TYPE_ARGUMENT_PACK:
case NONTYPE_ARGUMENT_PACK:
@@ -2870,7 +2871,7 @@ primary_template_instantiation_p (const_tree t)
return DECL_LANG_SPECIFIC (t)
&& DECL_TEMPLATE_INSTANTIATION (t)
&& PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t));
- else if (CLASS_TYPE_P (t))
+ else if (CLASS_TYPE_P (t) && !TYPE_DECL_ALIAS_P (TYPE_NAME (t)))
return CLASSTYPE_TEMPLATE_INSTANTIATION (t)
&& PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t));
else if (TYPE_P (t)
@@ -5501,7 +5502,7 @@ unify_inconsistency (bool explain_p, tree parm, tree first, tree second)
{
if (explain_p)
inform (input_location,
- " deduced conflicting types for parameter %qT (%qT and %qT)",
+ " conflicting deductions for parameter %qE (%qE and %qE)",
parm, first, second);
return 1;
}
@@ -6902,9 +6903,11 @@ template_args_equal (tree ot, tree nt)
/* For member templates */
return TREE_CODE (ot) == TREE_VEC && comp_template_args (ot, nt);
else if (PACK_EXPANSION_P (ot))
- return PACK_EXPANSION_P (nt)
- && template_args_equal (PACK_EXPANSION_PATTERN (ot),
- PACK_EXPANSION_PATTERN (nt));
+ return (PACK_EXPANSION_P (nt)
+ && template_args_equal (PACK_EXPANSION_PATTERN (ot),
+ PACK_EXPANSION_PATTERN (nt))
+ && template_args_equal (PACK_EXPANSION_EXTRA_ARGS (ot),
+ PACK_EXPANSION_EXTRA_ARGS (nt)));
else if (ARGUMENT_PACK_P (ot))
{
int i, len;
@@ -6954,6 +6957,12 @@ comp_template_args_with_info (tree oldargs, tree newargs,
{
int i;
+ if (oldargs == newargs)
+ return 1;
+
+ if (!oldargs || !newargs)
+ return 0;
+
if (TREE_VEC_LENGTH (oldargs) != TREE_VEC_LENGTH (newargs))
return 0;
@@ -7270,6 +7279,12 @@ lookup_template_class_1 (tree d1, tree arglist, tree in_decl, tree context,
int is_dependent_type;
int use_partial_inst_tmpl = false;
+ if (template_type == error_mark_node)
+ /* An error occured while building the template TEMPL, and a
+ diagnostic has most certainly been emitted for that
+ already. Let's propagate that error. */
+ return error_mark_node;
+
gen_tmpl = most_general_template (templ);
parmlist = DECL_TEMPLATE_PARMS (gen_tmpl);
parm_depth = TMPL_PARMS_DEPTH (parmlist);
@@ -9235,13 +9250,21 @@ tsubst_pack_expansion (tree t, tree args, tsubst_flags_t complain,
tree pattern;
tree pack, packs = NULL_TREE;
bool unsubstituted_packs = false;
+ bool real_packs = false;
+ int missing_level = 0;
int i, len = -1;
tree result;
htab_t saved_local_specializations = NULL;
+ int levels;
gcc_assert (PACK_EXPANSION_P (t));
pattern = PACK_EXPANSION_PATTERN (t);
+ /* Add in any args remembered from an earlier partial instantiation. */
+ args = add_to_template_args (PACK_EXPANSION_EXTRA_ARGS (t), args);
+
+ levels = TMPL_ARGS_DEPTH (args);
+
/* Determine the argument packs that will instantiate the parameter
packs used in the expansion expression. While we're at it,
compute the number of arguments to be expanded and make sure it
@@ -9252,6 +9275,7 @@ tsubst_pack_expansion (tree t, tree args, tsubst_flags_t complain,
tree parm_pack = TREE_VALUE (pack);
tree arg_pack = NULL_TREE;
tree orig_arg = NULL_TREE;
+ int level = 0;
if (TREE_CODE (parm_pack) == BASES)
{
@@ -9284,10 +9308,9 @@ tsubst_pack_expansion (tree t, tree args, tsubst_flags_t complain,
}
else
{
- int level, idx, levels;
+ int idx;
template_parm_level_and_index (parm_pack, &level, &idx);
- levels = TMPL_ARGS_DEPTH (args);
if (level <= levels)
arg_pack = TMPL_ARG (args, level, idx);
}
@@ -9327,7 +9350,9 @@ tsubst_pack_expansion (tree t, tree args, tsubst_flags_t complain,
len = my_len;
else if (len != my_len)
{
- if (TREE_CODE (t) == TYPE_PACK_EXPANSION)
+ if (!(complain & tf_error))
+ /* Fail quietly. */;
+ else if (TREE_CODE (t) == TYPE_PACK_EXPANSION)
error ("mismatched argument pack lengths while expanding "
"%<%T%>",
pattern);
@@ -9338,6 +9363,13 @@ tsubst_pack_expansion (tree t, tree args, tsubst_flags_t complain,
return error_mark_node;
}
+ if (TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg_pack)) == 1
+ && PACK_EXPANSION_P (TREE_VEC_ELT (ARGUMENT_PACK_ARGS (arg_pack),
+ 0)))
+ /* This isn't a real argument pack yet. */;
+ else
+ real_packs = true;
+
/* Keep track of the parameter packs and their corresponding
argument packs. */
packs = tree_cons (parm_pack, arg_pack, packs);
@@ -9345,25 +9377,57 @@ tsubst_pack_expansion (tree t, tree args, tsubst_flags_t complain,
}
else
{
- /* We can't substitute for this parameter pack. */
+ /* We can't substitute for this parameter pack. We use a flag as
+ well as the missing_level counter because function parameter
+ packs don't have a level. */
unsubstituted_packs = true;
- break;
+ if (!missing_level || missing_level > level)
+ missing_level = level;
}
}
/* We cannot expand this expansion expression, because we don't have
- all of the argument packs we need. Substitute into the pattern
- and return a PACK_EXPANSION_*. The caller will need to deal with
- that. */
+ all of the argument packs we need. */
if (unsubstituted_packs)
{
- tree new_pat;
- if (TREE_CODE (t) == EXPR_PACK_EXPANSION)
- new_pat = tsubst_expr (pattern, args, complain, in_decl,
- /*integral_constant_expression_p=*/false);
+ if (real_packs)
+ {
+ /* We got some full packs, but we can't substitute them in until we
+ have values for all the packs. So remember these until then. */
+ tree save_args;
+
+ t = make_pack_expansion (pattern);
+
+ /* The call to add_to_template_args above assumes no overlap
+ between saved args and new args, so prune away any fake
+ args, i.e. those that satisfied arg_from_parm_pack_p above. */
+ if (missing_level && levels >= missing_level)
+ {
+ gcc_assert (TMPL_ARGS_HAVE_MULTIPLE_LEVELS (args)
+ && missing_level > 1);
+ TREE_VEC_LENGTH (args) = missing_level - 1;
+ save_args = copy_node (args);
+ TREE_VEC_LENGTH (args) = levels;
+ }
+ else
+ save_args = args;
+
+ PACK_EXPANSION_EXTRA_ARGS (t) = save_args;
+ }
else
- new_pat = tsubst (pattern, args, complain, in_decl);
- return make_pack_expansion (new_pat);
+ {
+ /* There were no real arguments, we're just replacing a parameter
+ pack with another version of itself. Substitute into the
+ pattern and return a PACK_EXPANSION_*. The caller will need to
+ deal with that. */
+ if (TREE_CODE (t) == EXPR_PACK_EXPANSION)
+ t = tsubst_expr (pattern, args, complain, in_decl,
+ /*integral_constant_expression_p=*/false);
+ else
+ t = tsubst (pattern, args, complain, in_decl);
+ t = make_pack_expansion (t);
+ }
+ return t;
}
/* We could not find any argument packs that work. */
@@ -13387,6 +13451,10 @@ tsubst_copy_and_build (tree t,
return build_x_unary_op (TREE_CODE (t), RECUR (TREE_OPERAND (t, 0)),
complain);
+ case FIX_TRUNC_EXPR:
+ return cp_build_unary_op (FIX_TRUNC_EXPR, RECUR (TREE_OPERAND (t, 0)),
+ 0, complain);
+
case ADDR_EXPR:
op1 = TREE_OPERAND (t, 0);
if (TREE_CODE (op1) == LABEL_DECL)
@@ -15208,9 +15276,13 @@ type_unification_real (tree tparms,
{
tree parm = TREE_VALUE (TREE_VEC_ELT (tparms, i));
tree arg = TREE_PURPOSE (TREE_VEC_ELT (tparms, i));
+ location_t save_loc = input_location;
+ if (DECL_P (parm))
+ input_location = DECL_SOURCE_LOCATION (parm);
arg = tsubst_template_arg (arg, targs, complain, NULL_TREE);
arg = convert_template_argument (parm, arg, targs, complain,
i, NULL_TREE);
+ input_location = save_loc;
if (arg == error_mark_node)
return 1;
else
diff --git a/gcc/cp/ptree.c b/gcc/cp/ptree.c
index fb05e136045..a66e695c1f7 100644
--- a/gcc/cp/ptree.c
+++ b/gcc/cp/ptree.c
@@ -104,6 +104,10 @@ cxx_print_type (FILE *file, tree node, int indent)
indent + 4);
return;
+ case TYPE_PACK_EXPANSION:
+ print_node (file, "args", PACK_EXPANSION_EXTRA_ARGS (node), indent + 4);
+ return;
+
default:
return;
}
diff --git a/gcc/cp/search.c b/gcc/cp/search.c
index 9f308e29d79..3894c685884 100644
--- a/gcc/cp/search.c
+++ b/gcc/cp/search.c
@@ -436,6 +436,14 @@ lookup_field_1 (tree type, tree name, bool want_type)
field = fields[i++];
while (i < hi && DECL_NAME (fields[i]) == name);
}
+
+ if (field)
+ {
+ field = strip_using_decl (field);
+ if (is_overloaded_fn (field))
+ field = NULL_TREE;
+ }
+
return field;
}
}
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index f70bdb377b5..fe685fa1527 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -8178,6 +8178,10 @@ potential_constant_expression_1 (tree t, bool want_rval, tsubst_flags_t flags)
case EXPR_STMT:
case BIND_EXPR:
case TRANSACTION_EXPR:
+ case IF_STMT:
+ case DO_STMT:
+ case FOR_STMT:
+ case WHILE_STMT:
if (flags & tf_error)
error ("expression %qE is not a constant-expression", t);
return false;
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 841029f3385..d206fd2ec24 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -2993,11 +2993,13 @@ cp_walk_subtrees (tree *tp, int *walk_subtrees_p, walk_tree_fn func,
case TYPE_PACK_EXPANSION:
WALK_SUBTREE (TREE_TYPE (*tp));
+ WALK_SUBTREE (PACK_EXPANSION_EXTRA_ARGS (*tp));
*walk_subtrees_p = 0;
break;
case EXPR_PACK_EXPANSION:
WALK_SUBTREE (TREE_OPERAND (*tp, 0));
+ WALK_SUBTREE (PACK_EXPANSION_EXTRA_ARGS (*tp));
*walk_subtrees_p = 0;
break;
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index b8d4c10c8ca..a23e27491d8 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -1329,8 +1329,10 @@ structural_comptypes (tree t1, tree t2, int strict)
break;
case TYPE_PACK_EXPANSION:
- return same_type_p (PACK_EXPANSION_PATTERN (t1),
- PACK_EXPANSION_PATTERN (t2));
+ return (same_type_p (PACK_EXPANSION_PATTERN (t1),
+ PACK_EXPANSION_PATTERN (t2))
+ && comp_template_args (PACK_EXPANSION_EXTRA_ARGS (t1),
+ PACK_EXPANSION_EXTRA_ARGS (t2)));
case DECLTYPE_TYPE:
if (DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (t1)