Author: Timm Bäder Date: 2022-10-14T10:21:53+02:00 New Revision: 0e93b6bd51a0f002e37e76d6efa8e71dde6d3e5f
URL: https://github.com/llvm/llvm-project/commit/0e93b6bd51a0f002e37e76d6efa8e71dde6d3e5f DIFF: https://github.com/llvm/llvm-project/commit/0e93b6bd51a0f002e37e76d6efa8e71dde6d3e5f.diff LOG: [clang][Interp][NFC] Add more tests for if expressions Rename the old if_consteval.cpp to just if.cpp and add tests for the if declaration. Added: clang/test/AST/Interp/if.cpp Modified: Removed: clang/test/AST/Interp/if_consteval.cpp ################################################################################ diff --git a/clang/test/AST/Interp/if.cpp b/clang/test/AST/Interp/if.cpp new file mode 100644 index 0000000000000..5d35868cd00ec --- /dev/null +++ b/clang/test/AST/Interp/if.cpp @@ -0,0 +1,46 @@ +// RUN: %clang_cc1 -std=c++2b -fsyntax-only -fexperimental-new-constant-interpreter %s -verify +// RUN: %clang_cc1 -std=c++2b -fsyntax-only %s -verify=ref + +// expected-no-diagnostics +// ref-no-diagnostics + +namespace ConstEval { + constexpr int f() { + int i = 0; + if consteval { + i = 1; + } + return i; + } + static_assert(f() == 1, ""); + + constexpr int f2() { + int i = 0; + if !consteval { + i = 12; + if consteval { + i = i + 1; + } + } + return i; + } + static_assert(f2() == 0, ""); +}; + +namespace InitDecl { + constexpr bool f() { + if (int i = 5; i != 10) { + return true; + } + return false; + } + static_assert(f(), ""); + + constexpr bool f2() { + if (bool b = false; b) { + return true; + } + return false; + } + static_assert(!f2(), ""); +}; diff --git a/clang/test/AST/Interp/if_consteval.cpp b/clang/test/AST/Interp/if_consteval.cpp deleted file mode 100644 index 1a3ff9b91d720..0000000000000 --- a/clang/test/AST/Interp/if_consteval.cpp +++ /dev/null @@ -1,28 +0,0 @@ -// RUN: %clang_cc1 -std=c++2b -fsyntax-only -fexperimental-new-constant-interpreter %s -verify -// RUN: %clang_cc1 -std=c++2b -fsyntax-only %s -verify -// expected-no-diagnostics - -constexpr void f() { - int i = 0; - if consteval { - i = 1; - } - else { - i = 2; - } - - if consteval { - i = 1; - } - - if !consteval { - i = 1; - } - - if !consteval { - i = 1; - } - else { - i = 1; - } -} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits