Skip to content

Commit e980523

Browse files
authored
[libc++] Move libcxx/test/libcxx/extensions to libcxx/test/extensions and update the tests (#145476)
This patch adds a separate `extensions` directory, since there are quite a few extensions in libc++ that aren't necessarily libc++-specific. For example, the tests currently in `libcxx/test/libcxx/extensions` should also pass with libstdc++, since they originally added the extension. This also "documents" what users are allowed to rely on and what parts are just libc++ tests to make sure our implementation is behaving as we expect, which may be subject to change. This patch also formats the tests and refactors `.fail.cpp` tests to `.verify.cpp` tests.
1 parent 5fdcb35 commit e980523

File tree

5 files changed

+47
-45
lines changed

5 files changed

+47
-45
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
// Prevent <ext/hash_set> from generating deprecated warnings for this test.
10+
// ADDITIONAL_COMPILE_FLAGS: -Wno-deprecated
11+
12+
#include <cassert>
13+
#include <ext/hash_map>
14+
#include <string>
15+
16+
int main(int, char**) {
17+
char str[] = "test";
18+
assert(__gnu_cxx::hash<const char*>()("test") == std::hash<std::string>()("test"));
19+
assert(__gnu_cxx::hash<char*>()(str) == std::hash<std::string>()("test"));
20+
assert(__gnu_cxx::hash<char>()(42) == 42);
21+
assert(__gnu_cxx::hash<signed char>()(42) == 42);
22+
assert(__gnu_cxx::hash<unsigned char>()(42) == 42);
23+
assert(__gnu_cxx::hash<short>()(42) == 42);
24+
assert(__gnu_cxx::hash<unsigned short>()(42) == 42);
25+
assert(__gnu_cxx::hash<int>()(42) == 42);
26+
assert(__gnu_cxx::hash<unsigned int>()(42) == 42);
27+
assert(__gnu_cxx::hash<long>()(42) == 42);
28+
assert(__gnu_cxx::hash<unsigned long>()(42) == 42);
29+
30+
return 0;
31+
}

libcxx/test/libcxx/extensions/hash/specializations.compile.fail.cpp renamed to libcxx/test/extensions/gnu/hash/specializations.verify.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
// ADDITIONAL_COMPILE_FLAGS: -Wno-deprecated
10+
911
#include <assert.h>
1012
#include <ext/hash_map>
1113
#include <string>
1214

13-
int main(int, char**)
14-
{
15-
assert(__gnu_cxx::hash<std::string>()(std::string()) == 0); // error
15+
int main(int, char**) {
16+
assert(__gnu_cxx::hash<std::string>()(std::string()) == 0); // expected-error {{does not provide a call operator}}
1617

1718
return 0;
1819
}

libcxx/test/libcxx/extensions/hash_map/const_iterator.compile.fail.cpp renamed to libcxx/test/extensions/gnu/hash_map/const_iterator.verify.cpp

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

9+
// ADDITIONAL_COMPILE_FLAGS: -Wno-deprecated
10+
911
#include <ext/hash_map>
1012

11-
int main(int, char**)
12-
{
13-
__gnu_cxx::hash_map<int, int> m;
14-
m[1] = 1;
15-
const __gnu_cxx::hash_map<int, int> &cm = m;
16-
cm.find(1)->second = 2; // error
13+
int main(int, char**) {
14+
__gnu_cxx::hash_map<int, int> m;
15+
m[1] = 1;
16+
const __gnu_cxx::hash_map<int, int>& cm = m;
17+
cm.find(1)->second = 2; // expected-error {{cannot assign to return value because function 'operator->' returns a const value}}
1718

1819
return 0;
1920
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
# Only libc++ and libstdc++ have any gnu extensions
3+
if ("stdlib=libc++" not in config.available_features and
4+
"stdlib=libstdc++" not in config.available_features):
5+
config.unsupported = True

libcxx/test/libcxx/extensions/hash/specializations.pass.cpp

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

0 commit comments

Comments
 (0)