Commit a2b4cfaa by Jason Merrill Committed by Jason Merrill

decl.c (cp_finish_decl): Tidy.

	* decl.c (cp_finish_decl): Tidy.
	* typeck.c (finish_class_member_access_expr): Use
	type_dependent_expression_p.
	* semantics.c (finish_id_expression): Use
	type_dependent_expression_p.  Don't build_qualified_name for a
	decl in non-dependent scope.
	* pt.c (type_dependent_expression_p): A TEMPLATE_ID_EXPR of an
	identifier is dependent.  Remove variable_template_p check.

From-SVN: r226652
parent d8835b4d
2015-08-05 Jason Merrill <jason@redhat.com> 2015-08-05 Jason Merrill <jason@redhat.com>
* decl.c (cp_finish_decl): Tidy.
* typeck.c (finish_class_member_access_expr): Use
type_dependent_expression_p.
* semantics.c (finish_id_expression): Use
type_dependent_expression_p. Don't build_qualified_name for a
decl in non-dependent scope.
* pt.c (type_dependent_expression_p): A TEMPLATE_ID_EXPR of an
identifier is dependent. Remove variable_template_p check.
PR c++/66260 PR c++/66260
PR c++/66596 PR c++/66596
PR c++/66649 PR c++/66649
......
...@@ -6525,11 +6525,10 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, ...@@ -6525,11 +6525,10 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
then it can be used in future constant expressions, so its value then it can be used in future constant expressions, so its value
must be available. */ must be available. */
if (!VAR_P (decl) || dependent_type_p (type)) if (!VAR_P (decl) || type_dependent_p)
/* We can't do anything if the decl has dependent type. */; /* We can't do anything if the decl has dependent type. */;
else if (init else if (init
&& init_const_expr_p && init_const_expr_p
&& !type_dependent_p
&& TREE_CODE (type) != REFERENCE_TYPE && TREE_CODE (type) != REFERENCE_TYPE
&& decl_maybe_constant_var_p (decl) && decl_maybe_constant_var_p (decl)
&& !type_dependent_init_p (init) && !type_dependent_init_p (init)
......
...@@ -21671,11 +21671,10 @@ type_dependent_expression_p (tree expression) ...@@ -21671,11 +21671,10 @@ type_dependent_expression_p (tree expression)
(TREE_OPERAND (expression, 1))) (TREE_OPERAND (expression, 1)))
return true; return true;
expression = TREE_OPERAND (expression, 0); expression = TREE_OPERAND (expression, 0);
if (identifier_p (expression))
return true;
} }
if (variable_template_p (expression))
return dependent_type_p (TREE_TYPE (expression));
gcc_assert (TREE_CODE (expression) == OVERLOAD gcc_assert (TREE_CODE (expression) == OVERLOAD
|| TREE_CODE (expression) == FUNCTION_DECL); || TREE_CODE (expression) == FUNCTION_DECL);
......
...@@ -3362,7 +3362,7 @@ finish_id_expression (tree id_expression, ...@@ -3362,7 +3362,7 @@ finish_id_expression (tree id_expression,
} }
else else
{ {
bool dependent_p; bool dependent_p = type_dependent_expression_p (decl);
/* If the declaration was explicitly qualified indicate /* If the declaration was explicitly qualified indicate
that. The semantics of `A::f(3)' are different than that. The semantics of `A::f(3)' are different than
...@@ -3371,79 +3371,25 @@ finish_id_expression (tree id_expression, ...@@ -3371,79 +3371,25 @@ finish_id_expression (tree id_expression,
? CP_ID_KIND_QUALIFIED ? CP_ID_KIND_QUALIFIED
: (TREE_CODE (decl) == TEMPLATE_ID_EXPR : (TREE_CODE (decl) == TEMPLATE_ID_EXPR
? CP_ID_KIND_TEMPLATE_ID ? CP_ID_KIND_TEMPLATE_ID
: CP_ID_KIND_UNQUALIFIED)); : (dependent_p
? CP_ID_KIND_UNQUALIFIED_DEPENDENT
: CP_ID_KIND_UNQUALIFIED)));
/* [temp.dep.expr]
An id-expression is type-dependent if it contains an
identifier that was declared with a dependent type.
The standard is not very specific about an id-expression that
names a set of overloaded functions. What if some of them
have dependent types and some of them do not? Presumably,
such a name should be treated as a dependent name. */
/* Assume the name is not dependent. */
dependent_p = false;
if (!processing_template_decl)
/* No names are dependent outside a template. */
;
else if (TREE_CODE (decl) == CONST_DECL)
/* We don't want to treat enumerators as dependent. */
;
/* A template-id where the name of the template was not resolved
is definitely dependent. */
else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
&& (identifier_p (TREE_OPERAND (decl, 0))))
dependent_p = true;
/* For anything except an overloaded function, just check its
type. */
else if (!is_overloaded_fn (decl))
dependent_p
= dependent_type_p (TREE_TYPE (decl));
/* For a set of overloaded functions, check each of the
functions. */
else
{
tree fns = decl;
if (BASELINK_P (fns))
fns = BASELINK_FUNCTIONS (fns);
/* For a template-id, check to see if the template
arguments are dependent. */
if (TREE_CODE (fns) == TEMPLATE_ID_EXPR)
{
tree args = TREE_OPERAND (fns, 1);
dependent_p = any_dependent_template_arguments_p (args);
/* The functions are those referred to by the
template-id. */
fns = TREE_OPERAND (fns, 0);
}
/* If there are no dependent template arguments, go through
the overloaded functions. */
while (fns && !dependent_p)
{
tree fn = OVL_CURRENT (fns);
/* Member functions of dependent classes are
dependent. */
if (TREE_CODE (fn) == FUNCTION_DECL
&& type_dependent_expression_p (fn))
dependent_p = true;
else if (TREE_CODE (fn) == TEMPLATE_DECL
&& dependent_template_p (fn))
dependent_p = true;
fns = OVL_NEXT (fns);
}
}
/* If the name was dependent on a template parameter, we will /* If the name was dependent on a template parameter, we will
resolve the name at instantiation time. */ resolve the name at instantiation time. */
if (dependent_p) if (dependent_p)
{ {
/* If we found a variable, then name lookup during the
instantiation will always resolve to the same VAR_DECL
(or an instantiation thereof). */
if (VAR_P (decl)
|| TREE_CODE (decl) == CONST_DECL
|| TREE_CODE (decl) == PARM_DECL)
{
mark_used (decl);
return convert_from_reference (decl);
}
/* Create a SCOPE_REF for qualified names, if the scope is /* Create a SCOPE_REF for qualified names, if the scope is
dependent. */ dependent. */
if (scope) if (scope)
...@@ -3475,16 +3421,6 @@ finish_id_expression (tree id_expression, ...@@ -3475,16 +3421,6 @@ finish_id_expression (tree id_expression,
need. */ need. */
if (TREE_CODE (id_expression) == TEMPLATE_ID_EXPR) if (TREE_CODE (id_expression) == TEMPLATE_ID_EXPR)
return id_expression; return id_expression;
*idk = CP_ID_KIND_UNQUALIFIED_DEPENDENT;
/* If we found a variable, then name lookup during the
instantiation will always resolve to the same VAR_DECL
(or an instantiation thereof). */
if (VAR_P (decl)
|| TREE_CODE (decl) == PARM_DECL)
{
mark_used (decl);
return convert_from_reference (decl);
}
/* The same is true for FIELD_DECL, but we also need to /* The same is true for FIELD_DECL, but we also need to
make sure that the syntax is correct. */ make sure that the syntax is correct. */
else if (TREE_CODE (decl) == FIELD_DECL) else if (TREE_CODE (decl) == FIELD_DECL)
......
...@@ -2636,11 +2636,8 @@ finish_class_member_access_expr (tree object, tree name, bool template_p, ...@@ -2636,11 +2636,8 @@ finish_class_member_access_expr (tree object, tree name, bool template_p,
if (processing_template_decl) if (processing_template_decl)
{ {
if (/* If OBJECT_TYPE is dependent, so is OBJECT.NAME. */ if (/* If OBJECT is dependent, so is OBJECT.NAME. */
dependent_type_p (object_type) type_dependent_expression_p (object)
/* If NAME is just an IDENTIFIER_NODE, then the expression
is dependent. */
|| identifier_p (object)
/* If NAME is "f<args>", where either 'f' or 'args' is /* If NAME is "f<args>", where either 'f' or 'args' is
dependent, then the expression is dependent. */ dependent, then the expression is dependent. */
|| (TREE_CODE (name) == TEMPLATE_ID_EXPR || (TREE_CODE (name) == TEMPLATE_ID_EXPR
......
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