re PR c++/84582 (Rejected valid C++ code since r257961)

PR c++/84582
	* semantics.c (force_paren_expr): Create a PAREN_EXPR when in
	a template.
	(maybe_undo_parenthesized_ref): Unwrap PAREN_EXPR.
	* typeck2.c (store_init_value): Call fold_non_dependent_expr instead
	of instantiate_non_dependent_expr.
	* tree.c (lvalue_kind): Handle PAREN_EXPR like NON_DEPENDENT_EXPR.

	* g++.dg/cpp1y/auto-fn15.C: Extend testing.
	* g++.dg/cpp1z/static1.C: New test.
	* g++.dg/template/static37.C: New test.

Co-Authored-By: Jason Merrill <jason@redhat.com>

From-SVN: r258116
This commit is contained in:
Marek Polacek 2018-03-01 22:44:54 +00:00 committed by Marek Polacek
parent 303f485065
commit 1d4f0f3f60
8 changed files with 69 additions and 5 deletions

View File

@ -1,3 +1,14 @@
2018-03-01 Marek Polacek <polacek@redhat.com>
Jason Merrill <jason@redhat.com>
PR c++/84582
* semantics.c (force_paren_expr): Create a PAREN_EXPR when in
a template.
(maybe_undo_parenthesized_ref): Unwrap PAREN_EXPR.
* typeck2.c (store_init_value): Call fold_non_dependent_expr instead
of instantiate_non_dependent_expr.
* tree.c (lvalue_kind): Handle PAREN_EXPR like NON_DEPENDENT_EXPR.
2018-03-01 Nathan Sidwell <nathan@acm.org>
PR c++/84434

View File

@ -1693,7 +1693,8 @@ force_paren_expr (tree expr)
if (TREE_CODE (expr) == COMPONENT_REF
|| TREE_CODE (expr) == SCOPE_REF)
REF_PARENTHESIZED_P (expr) = true;
else if (type_dependent_expression_p (expr))
else if (type_dependent_expression_p (expr)
|| processing_template_decl)
expr = build1 (PAREN_EXPR, TREE_TYPE (expr), expr);
else if (VAR_P (expr) && DECL_HARD_REGISTER (expr))
/* We can't bind a hard register variable to a reference. */;
@ -1724,9 +1725,10 @@ force_paren_expr (tree expr)
tree
maybe_undo_parenthesized_ref (tree t)
{
if (cxx_dialect >= cxx14
&& INDIRECT_REF_P (t)
&& REF_PARENTHESIZED_P (t))
if (cxx_dialect < cxx14)
return t;
if (INDIRECT_REF_P (t) && REF_PARENTHESIZED_P (t))
{
t = TREE_OPERAND (t, 0);
while (TREE_CODE (t) == NON_LVALUE_EXPR
@ -1737,6 +1739,8 @@ maybe_undo_parenthesized_ref (tree t)
|| TREE_CODE (t) == STATIC_CAST_EXPR);
t = TREE_OPERAND (t, 0);
}
else if (TREE_CODE (t) == PAREN_EXPR)
t = TREE_OPERAND (t, 0);
return t;
}

View File

@ -239,6 +239,7 @@ lvalue_kind (const_tree ref)
return lvalue_kind (BASELINK_FUNCTIONS (CONST_CAST_TREE (ref)));
case NON_DEPENDENT_EXPR:
case PAREN_EXPR:
return lvalue_kind (TREE_OPERAND (ref, 0));
case VIEW_CONVERT_EXPR:

View File

@ -822,7 +822,7 @@ store_init_value (tree decl, tree init, vec<tree, va_gc>** cleanups, int flags)
if (decl_maybe_constant_var_p (decl) || TREE_STATIC (decl))
{
bool const_init;
value = instantiate_non_dependent_expr (value);
value = fold_non_dependent_expr (value);
if (DECL_DECLARED_CONSTEXPR_P (decl)
|| (DECL_IN_AGGR_P (decl) && !DECL_VAR_DECLARED_INLINE_P (decl)))
{

View File

@ -1,3 +1,11 @@
2018-03-01 Marek Polacek <polacek@redhat.com>
Jason Merrill <jason@redhat.com>
PR c++/84582
* g++.dg/cpp1y/auto-fn15.C: Extend testing.
* g++.dg/cpp1z/static1.C: New test.
* g++.dg/template/static37.C: New test.
2018-03-01 Nathan Sidwell <nathan@acm.org>
PR c++/84434

View File

@ -22,6 +22,8 @@ template <class T>
decltype(auto) h5(T t) { return t.i; }
template <class T>
decltype(auto) h6(T t) { return (t.i); }
template <class T>
decltype(auto) h7(T t) { return (i); }
int main()
{
@ -48,4 +50,5 @@ int main()
same_type<decltype(h4()),int&>();
same_type<decltype(h5(a)),int>();
same_type<decltype(h6(a)),int&>();
same_type<decltype(h7(a)),int&>();
}

View File

@ -0,0 +1,19 @@
// PR c++/84582
// { dg-options -std=c++17 }
class C {
static inline const long b = 0;
static inline const unsigned c = (b);
};
class D {
static inline const long b = 0;
static inline const unsigned c = b;
};
template <class> class A {
static inline const long b = 0;
static inline const unsigned c = (b);
};
template <class> class B {
static inline const long b = 0;
static inline const unsigned c = b;
};

View File

@ -0,0 +1,18 @@
// PR c++/84582
class C {
static const long b = 0;
static const unsigned c = (b);
};
class D {
static const long b = 0;
static const unsigned c = b;
};
template <class> class A {
static const long b = 0;
static const unsigned c = (b);
};
template <class> class B {
static const long b = 0;
static const unsigned c = b;
};