Commit 1d4f0f3f by Marek Polacek Committed by Marek Polacek

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
parent 303f4850
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> 2018-03-01 Nathan Sidwell <nathan@acm.org>
PR c++/84434 PR c++/84434
......
...@@ -1693,7 +1693,8 @@ force_paren_expr (tree expr) ...@@ -1693,7 +1693,8 @@ force_paren_expr (tree expr)
if (TREE_CODE (expr) == COMPONENT_REF if (TREE_CODE (expr) == COMPONENT_REF
|| TREE_CODE (expr) == SCOPE_REF) || TREE_CODE (expr) == SCOPE_REF)
REF_PARENTHESIZED_P (expr) = true; 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); expr = build1 (PAREN_EXPR, TREE_TYPE (expr), expr);
else if (VAR_P (expr) && DECL_HARD_REGISTER (expr)) else if (VAR_P (expr) && DECL_HARD_REGISTER (expr))
/* We can't bind a hard register variable to a reference. */; /* We can't bind a hard register variable to a reference. */;
...@@ -1724,9 +1725,10 @@ force_paren_expr (tree expr) ...@@ -1724,9 +1725,10 @@ force_paren_expr (tree expr)
tree tree
maybe_undo_parenthesized_ref (tree t) maybe_undo_parenthesized_ref (tree t)
{ {
if (cxx_dialect >= cxx14 if (cxx_dialect < cxx14)
&& INDIRECT_REF_P (t) return t;
&& REF_PARENTHESIZED_P (t))
if (INDIRECT_REF_P (t) && REF_PARENTHESIZED_P (t))
{ {
t = TREE_OPERAND (t, 0); t = TREE_OPERAND (t, 0);
while (TREE_CODE (t) == NON_LVALUE_EXPR while (TREE_CODE (t) == NON_LVALUE_EXPR
...@@ -1737,6 +1739,8 @@ maybe_undo_parenthesized_ref (tree t) ...@@ -1737,6 +1739,8 @@ maybe_undo_parenthesized_ref (tree t)
|| TREE_CODE (t) == STATIC_CAST_EXPR); || TREE_CODE (t) == STATIC_CAST_EXPR);
t = TREE_OPERAND (t, 0); t = TREE_OPERAND (t, 0);
} }
else if (TREE_CODE (t) == PAREN_EXPR)
t = TREE_OPERAND (t, 0);
return t; return t;
} }
......
...@@ -239,6 +239,7 @@ lvalue_kind (const_tree ref) ...@@ -239,6 +239,7 @@ lvalue_kind (const_tree ref)
return lvalue_kind (BASELINK_FUNCTIONS (CONST_CAST_TREE (ref))); return lvalue_kind (BASELINK_FUNCTIONS (CONST_CAST_TREE (ref)));
case NON_DEPENDENT_EXPR: case NON_DEPENDENT_EXPR:
case PAREN_EXPR:
return lvalue_kind (TREE_OPERAND (ref, 0)); return lvalue_kind (TREE_OPERAND (ref, 0));
case VIEW_CONVERT_EXPR: case VIEW_CONVERT_EXPR:
......
...@@ -822,7 +822,7 @@ store_init_value (tree decl, tree init, vec<tree, va_gc>** cleanups, int flags) ...@@ -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)) if (decl_maybe_constant_var_p (decl) || TREE_STATIC (decl))
{ {
bool const_init; bool const_init;
value = instantiate_non_dependent_expr (value); value = fold_non_dependent_expr (value);
if (DECL_DECLARED_CONSTEXPR_P (decl) if (DECL_DECLARED_CONSTEXPR_P (decl)
|| (DECL_IN_AGGR_P (decl) && !DECL_VAR_DECLARED_INLINE_P (decl))) || (DECL_IN_AGGR_P (decl) && !DECL_VAR_DECLARED_INLINE_P (decl)))
{ {
......
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> 2018-03-01 Nathan Sidwell <nathan@acm.org>
PR c++/84434 PR c++/84434
......
...@@ -22,6 +22,8 @@ template <class T> ...@@ -22,6 +22,8 @@ template <class T>
decltype(auto) h5(T t) { return t.i; } decltype(auto) h5(T t) { return t.i; }
template <class T> template <class T>
decltype(auto) h6(T t) { return (t.i); } decltype(auto) h6(T t) { return (t.i); }
template <class T>
decltype(auto) h7(T t) { return (i); }
int main() int main()
{ {
...@@ -48,4 +50,5 @@ int main() ...@@ -48,4 +50,5 @@ int main()
same_type<decltype(h4()),int&>(); same_type<decltype(h4()),int&>();
same_type<decltype(h5(a)),int>(); same_type<decltype(h5(a)),int>();
same_type<decltype(h6(a)),int&>(); same_type<decltype(h6(a)),int&>();
same_type<decltype(h7(a)),int&>();
} }
// 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;
};
// 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;
};
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