aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2018-03-01 22:44:54 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2018-03-01 22:44:54 +0000
commit1d4f0f3f6097dbe3817387d4889a123ca98bf987 (patch)
tree5fdb6243970f2877667faad2061c8873ed566731
parent303f4850651051e7c7ae04851d993246f6110fb6 (diff)
downloadgcc-1d4f0f3f6097dbe3817387d4889a123ca98bf987.zip
gcc-1d4f0f3f6097dbe3817387d4889a123ca98bf987.tar.gz
gcc-1d4f0f3f6097dbe3817387d4889a123ca98bf987.tar.bz2
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
-rw-r--r--gcc/cp/ChangeLog11
-rw-r--r--gcc/cp/semantics.c12
-rw-r--r--gcc/cp/tree.c1
-rw-r--r--gcc/cp/typeck2.c2
-rw-r--r--gcc/testsuite/ChangeLog8
-rw-r--r--gcc/testsuite/g++.dg/cpp1y/auto-fn15.C3
-rw-r--r--gcc/testsuite/g++.dg/cpp1z/static1.C19
-rw-r--r--gcc/testsuite/g++.dg/template/static37.C18
8 files changed, 69 insertions, 5 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 4cb5310..d44845b 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 87c5c66..1ac1d23 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -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;
}
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 9b9e36a..19f1c06 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -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:
diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index 153b46c..583c65d 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -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)))
{
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 90b53ae..abd409e 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
diff --git a/gcc/testsuite/g++.dg/cpp1y/auto-fn15.C b/gcc/testsuite/g++.dg/cpp1y/auto-fn15.C
index ba9f357..0db428f 100644
--- a/gcc/testsuite/g++.dg/cpp1y/auto-fn15.C
+++ b/gcc/testsuite/g++.dg/cpp1y/auto-fn15.C
@@ -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&>();
}
diff --git a/gcc/testsuite/g++.dg/cpp1z/static1.C b/gcc/testsuite/g++.dg/cpp1z/static1.C
new file mode 100644
index 0000000..cb87299
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/static1.C
@@ -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;
+};
diff --git a/gcc/testsuite/g++.dg/template/static37.C b/gcc/testsuite/g++.dg/template/static37.C
new file mode 100644
index 0000000..90bc65d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/static37.C
@@ -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;
+};