This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Add a testcase for C++17 selection statements with initializer
- From: Marek Polacek <polacek at redhat dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>, Jason Merrill <jason at redhat dot com>
- Date: Wed, 5 Oct 2016 23:47:41 +0200
- Subject: Add a testcase for C++17 selection statements with initializer
- Authentication-results: sourceware.org; auth=none
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