123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- // Copyright 2019 The Chromium Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style license that can be
- // found in the LICENSE file.
- // This is a "No Compile Test" suite.
- // http://dev.chromium.org/developers/testing/no-compile-tests
- #include "base/containers/checked_iterators.h"
- namespace base {
- #if defined(NCTEST_CHECKED_ITERATORS_CONSTRUCTOR_START_END) // [r"constexpr variable 'iter' must be initialized by a constant expression"]
- constexpr int kArray[] = {1, 2, 3, 4, 5};
- void WontCompile() {
- // start can't be larger than end
- constexpr CheckedContiguousIterator<const int> iter(kArray + 1, kArray);
- }
- #elif defined(NCTEST_CHECKED_ITERATORS_CONSTRUCTOR_START_CURRENT) // [r"constexpr variable 'iter' must be initialized by a constant expression"]
- constexpr int kArray[] = {1, 2, 3, 4, 5};
- void WontCompile() {
- // current can't be larger than start
- constexpr CheckedContiguousIterator<const int> iter(kArray + 1, kArray, kArray + 5);
- }
- #elif defined(NCTEST_CHECKED_ITERATORS_CONSTRUCTOR_CURRENT_END) // [r"constexpr variable 'iter' must be initialized by a constant expression"]
- constexpr int kArray[] = {1, 2, 3, 4, 5};
- void WontCompile() {
- // current can't be larger than end
- constexpr CheckedContiguousIterator<const int> iter(kArray, kArray + 2, kArray + 1);
- }
- #elif defined(NCTEST_CHECKED_ITERATORS_EQ_DIFFERENT_ITER) // [r"constexpr variable 'equal' must be initialized by a constant expression"]
- constexpr int kArray1[] = {1, 2, 3, 4, 5};
- constexpr int kArray2[] = {1, 2, 3, 4, 5};
- void WontCompile() {
- // Can't compare iterators into different containers
- constexpr CheckedContiguousIterator<const int> iter1(kArray1, kArray1 + 5);
- constexpr CheckedContiguousIterator<const int> iter2(kArray2, kArray2 + 5);
- constexpr bool equal = iter1 == iter2;
- }
- #elif defined(NCTEST_CHECKED_ITERATORS_NE_DIFFERENT_ITER) // [r"constexpr variable 'not_equal' must be initialized by a constant expression"]
- constexpr int kArray1[] = {1, 2, 3, 4, 5};
- constexpr int kArray2[] = {1, 2, 3, 4, 5};
- void WontCompile() {
- // Can't compare iterators into different containers
- constexpr CheckedContiguousIterator<const int> iter1(kArray1, kArray1 + 5);
- constexpr CheckedContiguousIterator<const int> iter2(kArray2, kArray2 + 5);
- constexpr bool not_equal = iter1 != iter2;
- }
- #elif defined(NCTEST_CHECKED_ITERATORS_LT_DIFFERENT_ITER) // [r"constexpr variable 'less_than' must be initialized by a constant expression"]
- constexpr int kArray1[] = {1, 2, 3, 4, 5};
- constexpr int kArray2[] = {1, 2, 3, 4, 5};
- void WontCompile() {
- // Can't compare iterators into different containers
- constexpr CheckedContiguousIterator<const int> iter1(kArray1, kArray1 + 5);
- constexpr CheckedContiguousIterator<const int> iter2(kArray2, kArray2 + 5);
- constexpr bool less_than = iter1 < iter2;
- }
- #elif defined(NCTEST_CHECKED_ITERATORS_LE_DIFFERENT_ITER) // [r"constexpr variable 'less_equal' must be initialized by a constant expression"]
- constexpr int kArray1[] = {1, 2, 3, 4, 5};
- constexpr int kArray2[] = {1, 2, 3, 4, 5};
- void WontCompile() {
- // Can't compare iterators into different containers
- constexpr CheckedContiguousIterator<const int> iter1(kArray1, kArray1 + 5);
- constexpr CheckedContiguousIterator<const int> iter2(kArray2, kArray2 + 5);
- constexpr bool less_equal = iter1 <= iter2;
- }
- #elif defined(NCTEST_CHECKED_ITERATORS_GT_DIFFERENT_ITER) // [r"constexpr variable 'greater_than' must be initialized by a constant expression"]
- constexpr int kArray1[] = {1, 2, 3, 4, 5};
- constexpr int kArray2[] = {1, 2, 3, 4, 5};
- void WontCompile() {
- // Can't compare iterators into different containers
- constexpr CheckedContiguousIterator<const int> iter1(kArray1, kArray1 + 5);
- constexpr CheckedContiguousIterator<const int> iter2(kArray2, kArray2 + 5);
- constexpr bool greater_than = iter1 > iter2;
- }
- #elif defined(NCTEST_CHECKED_ITERATORS_GE_DIFFERENT_ITER) // [r"constexpr variable 'greater_equal' must be initialized by a constant expression"]
- constexpr int kArray1[] = {1, 2, 3, 4, 5};
- constexpr int kArray2[] = {1, 2, 3, 4, 5};
- void WontCompile() {
- // Can't compare iterators into different containers
- constexpr CheckedContiguousIterator<const int> iter1(kArray1, kArray1 + 5);
- constexpr CheckedContiguousIterator<const int> iter2(kArray2, kArray2 + 5);
- constexpr bool greater_equal = iter1 >= iter2;
- }
- #elif defined(NCTEST_CHECKED_ITERATORS_PRE_INCR_END) // [r"constexpr variable 'pre_incr' must be initialized by a constant expression"]
- constexpr int kArray[] = {1, 2, 3, 4, 5};
- constexpr int PreIncr() {
- // Can't pre-increment the end iterator.
- CheckedContiguousIterator<const int> end_iter(kArray, kArray + 5, kArray + 5);
- ++end_iter;
- return 0;
- }
- void WontCompile() {
- constexpr int pre_incr = PreIncr();
- }
- #elif defined(NCTEST_CHECKED_ITERATORS_POST_INCR_END) // [r"constexpr variable 'post_incr' must be initialized by a constant expression"]
- constexpr int kArray[] = {1, 2, 3, 4, 5};
- constexpr int PostIncr() {
- // Can't post-increment the end iterator.
- CheckedContiguousIterator<const int> end_iter(kArray, kArray + 5, kArray + 5);
- end_iter++;
- return 0;
- }
- void WontCompile() {
- constexpr int post_incr = PostIncr();
- }
- #elif defined(NCTEST_CHECKED_ITERATORS_PRE_DECR_BEGIN) // [r"constexpr variable 'pre_decr' must be initialized by a constant expression"]
- constexpr int kArray[] = {1, 2, 3, 4, 5};
- constexpr int PreDecr() {
- // Can't pre-decrement the begin iterator.
- CheckedContiguousIterator<const int> begin_iter(kArray, kArray + 5);
- --begin_iter;
- return 0;
- }
- void WontCompile() {
- constexpr int pre_decr = PreDecr();
- }
- #elif defined(NCTEST_CHECKED_ITERATORS_POST_DECR_BEGIN) // [r"constexpr variable 'post_decr' must be initialized by a constant expression"]
- constexpr int kArray[] = {1, 2, 3, 4, 5};
- constexpr int PostDecr() {
- // Can't post-decrement the begin iterator.
- CheckedContiguousIterator<const int> begin_iter(kArray, kArray + 5);
- begin_iter--;
- return 0;
- }
- void WontCompile() {
- constexpr int post_decr = PostDecr();
- }
- #elif defined(NCTEST_CHECKED_ITERATORS_INCR_PAST_END) // [r"constexpr variable 'incr_past_end' must be initialized by a constant expression"]
- constexpr int kArray[] = {1, 2, 3, 4, 5};
- constexpr int IncrPastEnd() {
- // Can't increment iterator past the end.
- CheckedContiguousIterator<const int> iter(kArray, kArray + 5);
- iter += 6;
- return 0;
- }
- void WontCompile() {
- constexpr int incr_past_end = IncrPastEnd();
- }
- #elif defined(NCTEST_CHECKED_ITERATORS_DECR_PAST_BEGIN) // [r"constexpr variable 'decr_past_begin' must be initialized by a constant expression"]
- constexpr int kArray[] = {1, 2, 3, 4, 5};
- constexpr int DecrPastBegin() {
- // Can't decrement iterator past the begin.
- CheckedContiguousIterator<const int> iter(kArray, kArray + 5);
- iter += -1;
- return 0;
- }
- void WontCompile() {
- constexpr int decr_past_begin = DecrPastBegin();
- }
- #elif defined(NCTEST_CHECKED_ITERATORS_INCR_PAST_END_2) // [r"constexpr variable 'iter_past_end' must be initialized by a constant expression"]
- constexpr int kArray[] = {1, 2, 3, 4, 5};
- void WontCompile() {
- // Can't increment iterator past the end.
- constexpr CheckedContiguousIterator<const int> iter(kArray, kArray + 5);
- constexpr auto iter_past_end = iter + 6;
- }
- #elif defined(NCTEST_CHECKED_ITERATORS_DECR_PAST_BEGIN_2) // [r"constexpr variable 'iter_past_begin' must be initialized by a constant expression"]
- constexpr int kArray[] = {1, 2, 3, 4, 5};
- void WontCompile() {
- // Can't decrement iterator past the begin.
- constexpr CheckedContiguousIterator<const int> iter(kArray, kArray + 5);
- constexpr auto iter_past_begin = iter + (-1);
- }
- #elif defined(NCTEST_CHECKED_ITERATORS_DECR_PAST_BEGIN_3) // [r"constexpr variable 'decr_past_begin' must be initialized by a constant expression"]
- constexpr int kArray[] = {1, 2, 3, 4, 5};
- constexpr int DecrPastBegin() {
- // Can't decrement iterator past the begin.
- CheckedContiguousIterator<const int> iter(kArray, kArray + 5);
- iter -= 1;
- return 0;
- }
- void WontCompile() {
- constexpr int decr_past_begin = DecrPastBegin();
- }
- #elif defined(NCTEST_CHECKED_ITERATORS_INCR_PAST_END_3) // [r"constexpr variable 'incr_past_end' must be initialized by a constant expression"]
- constexpr int kArray[] = {1, 2, 3, 4, 5};
- constexpr int IncrPastEnd() {
- // Can't increment iterator past the end.
- CheckedContiguousIterator<const int> iter(kArray, kArray + 5);
- iter -= (-6);
- return 0;
- }
- void WontCompile() {
- constexpr int incr_past_end = IncrPastEnd();
- }
- #elif defined(NCTEST_CHECKED_ITERATORS_DECR_PAST_BEGIN_4) // [r"constexpr variable 'iter_past_begin' must be initialized by a constant expression"]
- constexpr int kArray[] = {1, 2, 3, 4, 5};
- void WontCompile() {
- // Can't decrement iterator past the begin.
- constexpr CheckedContiguousIterator<const int> iter(kArray, kArray + 5);
- constexpr auto iter_past_begin = iter - 1;
- }
- #elif defined(NCTEST_CHECKED_ITERATORS_INCR_PAST_END_4) // [r"constexpr variable 'iter_past_end' must be initialized by a constant expression"]
- constexpr int kArray[] = {1, 2, 3, 4, 5};
- void WontCompile() {
- // Can't increment iterator past the end.
- constexpr CheckedContiguousIterator<const int> iter(kArray, kArray + 5);
- constexpr auto iter_past_end = iter - (-6);
- }
- #elif defined(NCTEST_CHECKED_ITERATORS_DIFFERENCE_DIFFERENT_ITER) // [r"constexpr variable 'difference' must be initialized by a constant expression"]
- constexpr int kArray1[] = {1, 2, 3, 4, 5};
- constexpr int kArray2[] = {1, 2, 3, 4, 5};
- void WontCompile() {
- // Can't compare iterators into different containers
- constexpr CheckedContiguousIterator<const int> iter1(kArray1, kArray1 + 5);
- constexpr CheckedContiguousIterator<const int> iter2(kArray2, kArray2 + 5);
- constexpr auto difference = iter1 - iter2;
- }
- #elif defined(NCTEST_CHECKED_ITERATORS_STAR_END) // [r"constexpr variable 'ref' must be initialized by a constant expression"]
- constexpr int kArray[] = {1, 2, 3, 4, 5};
- void WontCompile() {
- // Can't dereference the end iterator by star.
- constexpr CheckedContiguousIterator<const int> end_iter(kArray, kArray + 5, kArray + 5);
- constexpr auto& ref = *end_iter;
- }
- #elif defined(NCTEST_CHECKED_ITERATORS_ARROW_END) // [r"constexpr variable 'ptr' must be initialized by a constant expression"]
- constexpr int kArray[] = {1, 2, 3, 4, 5};
- void WontCompile() {
- // Can't dereference the end iterator by arrow.
- constexpr CheckedContiguousIterator<const int> end_iter(kArray, kArray + 5, kArray + 5);
- constexpr auto* ptr = end_iter.operator->();
- }
- #elif defined(NCTEST_CHECKED_ITERATORS_NEGATIVE_OPERATOR_AT) // [r"constexpr variable 'ref' must be initialized by a constant expression"]
- constexpr int kArray[] = {1, 2, 3, 4, 5};
- void WontCompile() {
- // Can't use a negative index in operator[].
- constexpr CheckedContiguousIterator<const int> iter(kArray, kArray + 5);
- constexpr auto& ref = iter[-1];
- }
- #elif defined(NCTEST_CHECKED_ITERATORS_OPERATOR_AT_END) // [r"constexpr variable 'ref' must be initialized by a constant expression"]
- constexpr int kArray[] = {1, 2, 3, 4, 5};
- void WontCompile() {
- // Can't use a operator[] to deref the end.
- constexpr CheckedContiguousIterator<const int> iter(kArray, kArray + 5);
- constexpr auto& ref = iter[5];
- }
- #endif
- } // namespace base
|