aboutsummaryrefslogtreecommitdiff
path: root/clang/test
diff options
context:
space:
mode:
authorTimm Baeder <tbaeder@redhat.com>2024-09-07 14:27:09 +0200
committerGitHub <noreply@github.com>2024-09-07 14:27:09 +0200
commitd6d60707ec2b60843c5bfc2c3bc44e4478add17a (patch)
treee922825ab230936f058a5d017d7124f1403fe724 /clang/test
parent0ceffd362bf01769fa310103b11af9cdc12e2f5b (diff)
downloadllvm-d6d60707ec2b60843c5bfc2c3bc44e4478add17a.zip
llvm-d6d60707ec2b60843c5bfc2c3bc44e4478add17a.tar.gz
llvm-d6d60707ec2b60843c5bfc2c3bc44e4478add17a.tar.bz2
[clang][bytecode] Fix two-pointer-style std::initializer_lists (#107682)
The first pointer needs to point to the first element of the underlying array. This requires some changes to how we handle array expansion
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/AST/ByteCode/initializer_list.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/clang/test/AST/ByteCode/initializer_list.cpp b/clang/test/AST/ByteCode/initializer_list.cpp
new file mode 100644
index 0000000..4e3b8dc
--- /dev/null
+++ b/clang/test/AST/ByteCode/initializer_list.cpp
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -fms-extensions -std=c++20 -verify=expected,both %s
+// RUN: %clang_cc1 -std=c++20 -fms-extensions -verify=ref,both %s
+
+// both-no-diagnostics
+
+namespace std {
+ typedef decltype(sizeof(int)) size_t;
+ template <class _E>
+ class initializer_list
+ {
+ const _E* __begin_;
+ size_t __size_;
+
+ initializer_list(const _E* __b, size_t __s)
+ : __begin_(__b),
+ __size_(__s)
+ {}
+
+ public:
+ typedef _E value_type;
+ typedef const _E& reference;
+ typedef const _E& const_reference;
+ typedef size_t size_type;
+
+ typedef const _E* iterator;
+ typedef const _E* const_iterator;
+
+ constexpr initializer_list() : __begin_(nullptr), __size_(0) {}
+
+ constexpr size_t size() const {return __size_;}
+ constexpr const _E* begin() const {return __begin_;}
+ constexpr const _E* end() const {return __begin_ + __size_;}
+ };
+}
+
+class Thing {
+public:
+ int m = 12;
+ constexpr Thing(int m) : m(m) {}
+ constexpr bool operator==(const Thing& that) const {
+ return this->m == that.m;
+ }
+};
+
+constexpr bool is_contained(std::initializer_list<Thing> Set, const Thing &Element) {
+ return (*Set.begin() == Element);
+}
+
+constexpr int foo() {
+ const Thing a{12};
+ const Thing b{14};
+ return is_contained({a}, b);
+}
+
+static_assert(foo() == 0);