diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2016-07-14 00:11:03 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2016-07-14 00:11:03 +0000 |
commit | a547eb27fa5ed28b631f5a72f369e68e9c3cca1f (patch) | |
tree | ea8248c585a5ee4759adfc838899e3f35adfbcff /clang/test/SemaCXX/cxx1z-init-statement.cpp | |
parent | d5bbd856e2a71201d8bf9b0cbcb5339df9bf9f12 (diff) | |
download | bcm5719-llvm-a547eb27fa5ed28b631f5a72f369e68e9c3cca1f.tar.gz bcm5719-llvm-a547eb27fa5ed28b631f5a72f369e68e9c3cca1f.zip |
P0305R0: Semantic analysis and code generation for C++17 init-statement for 'if' and 'switch':
if (stmt; condition) { ... }
Patch by Anton Bikineev! Some minor formatting and comment tweets by me.
llvm-svn: 275350
Diffstat (limited to 'clang/test/SemaCXX/cxx1z-init-statement.cpp')
-rw-r--r-- | clang/test/SemaCXX/cxx1z-init-statement.cpp | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/clang/test/SemaCXX/cxx1z-init-statement.cpp b/clang/test/SemaCXX/cxx1z-init-statement.cpp new file mode 100644 index 00000000000..4afe0402d13 --- /dev/null +++ b/clang/test/SemaCXX/cxx1z-init-statement.cpp @@ -0,0 +1,91 @@ +// RUN: %clang_cc1 -std=c++1z -verify %s + +void testIf() { + int x = 0; + if (x; x) ++x; + if (int t = 0; t) ++t; else --t; + + if (int x, y = 0; y) // expected-note 2 {{previous definition is here}} + int x = 0; // expected-error {{redefinition of 'x'}} + else + int x = 0; // expected-error {{redefinition of 'x'}} + + if (x; int a = 0) ++a; + if (x, +x; int a = 0) // expected-note 2 {{previous definition is here}} expected-warning {{unused}} + int a = 0; // expected-error {{redefinition of 'a'}} + else + int a = 0; // expected-error {{redefinition of 'a'}} + + if (int b = 0; b) + ; + b = 2; // expected-error {{use of undeclared identifier}} +} + +void testSwitch() { + int x = 0; + switch (x; x) { + case 1: + ++x; + } + + switch (int x, y = 0; y) { + case 1: + ++x; + default: + ++y; + } + + switch (int x, y = 0; y) { // expected-note 2 {{previous definition is here}} + case 0: + int x = 0; // expected-error {{redefinition of 'x'}} + case 1: + int y = 0; // expected-error {{redefinition of 'y'}} + }; + + switch (x; int a = 0) { + case 0: + ++a; + } + + switch (x, +x; int a = 0) { // expected-note {{previous definition is here}} expected-warning {{unused}} + case 0: + int a = 0; // expected-error {{redefinition of 'a'}} // expected-note {{previous definition is here}} + case 1: + int a = 0; // expected-error {{redefinition of 'a'}} + } + + switch (int b = 0; b) { + case 0: + break; + } + b = 2; // expected-error {{use of undeclared identifier}} +} + +constexpr bool constexpr_if_init(int n) { + if (int a = n; ++a > 0) + return true; + else + return false; +} + +constexpr int constexpr_switch_init(int n) { + switch (int p = n + 2; p) { + case 0: + return 0; + case 1: + return 1; + default: + return -1; + } +} + +void test_constexpr_init_stmt() { + constexpr bool a = constexpr_if_init(-2); + static_assert(!a, ""); + static_assert(constexpr_if_init(1), ""); + + constexpr int b = constexpr_switch_init(-1); + static_assert(b == 1, ""); + static_assert(constexpr_switch_init(-2) == 0, ""); + static_assert(constexpr_switch_init(-5) == -1, ""); +} |