Skip to content

Commit aae2b89

Browse files
authored
[libc++] Replace a few .compile.fail.cpp tests by proper clang-verify tests (#167346)
We want to eliminate all .compile.fail.cpp tests since they are brittle: these tests pass regardless of the specific compilation error, which means that e.g. a mising include will render the test null. This is not an exhaustive pass, just a few tests I stumbled upon.
1 parent 24c524d commit aae2b89

File tree

6 files changed

+75
-161
lines changed

6 files changed

+75
-161
lines changed

libcxx/test/std/input.output/file.streams/c.files/gets.compile.fail.cpp renamed to libcxx/test/std/input.output/file.streams/c.files/gets-removed.verify.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,11 @@
77
//===----------------------------------------------------------------------===//
88

99
// UNSUPPORTED: c++03, c++11
10-
// test <cstdio>
1110

12-
// gets
11+
// Verify that std::gets has been removed in C++14 and later
1312

1413
#include <cstdio>
1514

16-
int main(int, char**)
17-
{
18-
(void) std::gets((char *) NULL);
19-
20-
return 0;
15+
void f(char const* str) {
16+
(void)std::gets(str); // expected-error {{no member named 'gets' in namespace 'std'}}
2117
}

libcxx/test/std/re/re.iter/re.tokiter/re.tokiter.cnstr/array.compile.fail.cpp

Lines changed: 0 additions & 40 deletions
This file was deleted.

libcxx/test/std/re/re.iter/re.tokiter/re.tokiter.cnstr/init.compile.fail.cpp

Lines changed: 0 additions & 37 deletions
This file was deleted.

libcxx/test/std/re/re.iter/re.tokiter/re.tokiter.cnstr/int.compile.fail.cpp

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// UNSUPPORTED: c++03, c++11
10+
11+
// Ensure that we don't allow iterators into temporary std::regex objects.
12+
13+
// <regex>
14+
//
15+
// class regex_iterator<BidirectionalIterator, charT, traits>
16+
//
17+
// regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
18+
// const regex_type&& re, int submatch = 0,
19+
// regex_constants::match_flag_type m =
20+
// regex_constants::match_default);
21+
//
22+
// template <size_t N>
23+
// regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
24+
// const regex_type&& re,
25+
// const int (&submatches)[N],
26+
// regex_constants::match_flag_type m =
27+
// regex_constants::match_default);
28+
//
29+
// regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
30+
// const regex_type&& re,
31+
// initializer_list<int> submatches,
32+
// regex_constants::match_flag_type m =
33+
// regex_constants::match_default);
34+
//
35+
// template <std::size_t N>
36+
// regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
37+
// const regex_type&& re,
38+
// const std::vector<int>& submatches,
39+
// regex_constants::match_flag_type m =
40+
// regex_constants::match_default);
41+
42+
#include <iterator>
43+
#include <regex>
44+
#include <vector>
45+
46+
void f() {
47+
std::regex phone_numbers("\\d{3}-\\d{4}");
48+
const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
49+
50+
{ // int submatch
51+
std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book) - 1, std::regex("\\d{3}-\\d{4}"), -1);
52+
// expected-error@-1 {{call to deleted constructor of 'std::cregex_token_iterator'}}
53+
}
54+
{ // const int (&submatches)[N]
55+
const int indices[] = {-1, 0, 1};
56+
std::cregex_token_iterator i(
57+
std::begin(phone_book), std::end(phone_book) - 1, std::regex("\\d{3}-\\d{4}"), indices);
58+
// expected-error@-2 {{call to deleted constructor of 'std::cregex_token_iterator'}}
59+
}
60+
{ // initializer_list<int> submatches
61+
std::cregex_token_iterator i(
62+
std::begin(phone_book), std::end(phone_book) - 1, std::regex("\\d{3}-\\d{4}"), {-1, 0, 1});
63+
// expected-error@-2 {{call to deleted constructor of 'std::cregex_token_iterator'}}
64+
}
65+
{ // const std::vector<int>& submatches
66+
std::vector<int> v;
67+
v.push_back(-1);
68+
v.push_back(-1);
69+
std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book) - 1, std::regex("\\d{3}-\\d{4}"), v);
70+
// expected-error@-1 {{call to deleted constructor of 'std::cregex_token_iterator'}}
71+
}
72+
}

libcxx/test/std/re/re.iter/re.tokiter/re.tokiter.cnstr/vector.compile.fail.cpp

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)