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 | 9530e8bab6f84fd9b0da961423a395f5bfcb1e2a (patch) | |
tree | 07ab95d87e818ddb292f6451274407ac3fd09bd7 /test/PCH | |
parent | d1642265a78e95e9050fbd574554a7f53ae0c649 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@275350 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/PCH')
-rw-r--r-- | test/PCH/cxx1z-init-statement.cpp | 17 | ||||
-rw-r--r-- | test/PCH/cxx1z-init-statement.h | 22 |
2 files changed, 39 insertions, 0 deletions
diff --git a/test/PCH/cxx1z-init-statement.cpp b/test/PCH/cxx1z-init-statement.cpp new file mode 100644 index 0000000000..d08fb7c56b --- /dev/null +++ b/test/PCH/cxx1z-init-statement.cpp @@ -0,0 +1,17 @@ +// Test this without pch. +// RUN: %clang_cc1 -std=c++1z -include %S/cxx1z-init-statement.h -fsyntax-only -emit-llvm -o - %s + +// Test with pch. +// RUN: %clang_cc1 -x c++ -std=c++1z -emit-pch -o %t %S/cxx1z-init-statement.h +// RUN: %clang_cc1 -std=c++1z -include-pch %t -fsyntax-only -emit-llvm -o - %s + +void g0(void) { + static_assert(test_if(-1) == -1, ""); + static_assert(test_if(0) == 0, ""); +} + +void g1(void) { + static_assert(test_switch(-1) == -1, ""); + static_assert(test_switch(0) == 0, ""); + static_assert(test_switch(1) == 1, ""); +} diff --git a/test/PCH/cxx1z-init-statement.h b/test/PCH/cxx1z-init-statement.h new file mode 100644 index 0000000000..16bd569c84 --- /dev/null +++ b/test/PCH/cxx1z-init-statement.h @@ -0,0 +1,22 @@ +// Header for PCH test cxx1z-init-statement.cpp + +constexpr int test_if(int x) { + if (int a = ++x; a == 0) { + return -1; + } else if (++a; a == 2) { + return 0; + } + return 2; +} + +constexpr int test_switch(int x) { + switch (int a = ++x; a) { + case 0: + return -1; + case 1: + return 0; + case 2: + return 1; + } + return 2; +} |