This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Add a testcase for C++17 selection statements with initializer


This adds a further test for selection statements with initializer C++17
feature.  Except that I'm not quite sure if it's valid, but I think it is;
although the standard says
An if statement of the form

  if constexpr opt ( init-statement condition ) statement

is equivalent to

  {
    init-statement
    if constexpr opt ( condition ) statement
  }

it also says "except that names declared in the init-statement are in the same
declarative region as those declared in the condition."
and program like

  if (int x = 4)
    {
      int x;
    }
is ill-formed.

Ok for trunk?

2016-10-05  Marek Polacek  <polacek@redhat.com>

	* g++.dg/cpp1z/init-statement9.C: New test.

diff --git gcc/testsuite/g++.dg/cpp1z/init-statement9.C gcc/testsuite/g++.dg/cpp1z/init-statement9.C
index e69de29..5425f97 100644
--- gcc/testsuite/g++.dg/cpp1z/init-statement9.C
+++ gcc/testsuite/g++.dg/cpp1z/init-statement9.C
@@ -0,0 +1,17 @@
+// { dg-options -std=c++1z }
+
+void
+f ()
+{
+  {
+    int c;
+    if (int c = 2; c != 0)
+      int c = 4; // { dg-error "redeclaration" }
+  }
+
+  if (int c = 2; c != 0)
+    int c = 4; // { dg-error "redeclaration" }
+
+  if (int c = 2; int c = 6) // { dg-error "redeclaration" }
+    int c = 4; // { dg-error "redeclaration" }
+}

	Marek


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]