summaryrefslogtreecommitdiff
path: root/tests/tests2/94_generic.c
diff options
context:
space:
mode:
authorThomas Preud'homme <robotux@celest.fr>2020-08-14 23:04:13 +0100
committerThomas Preud'homme <robotux@celest.fr>2020-08-14 23:04:13 +0100
commitafd09586d7ead4f146ad7a7a471be34196b3c6bc (patch)
tree87854be29fb4264b979b700fa45445f58faa4c26 /tests/tests2/94_generic.c
parente2ccf3981d78dfeb390d22c74625b60310100abb (diff)
New upstream version 0.9.27+git20200814.62c30a4a
Diffstat (limited to 'tests/tests2/94_generic.c')
-rw-r--r--tests/tests2/94_generic.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/tests2/94_generic.c b/tests/tests2/94_generic.c
index d7fb5fc..6e85c02 100644
--- a/tests/tests2/94_generic.c
+++ b/tests/tests2/94_generic.c
@@ -20,6 +20,12 @@ int b_f()
return 10;
}
+typedef int (*fptr)(int);
+int foo(int i)
+{
+ return i;
+}
+
typedef int int_type1;
#define gen_sw(a) _Generic(a, const char *: 1, default: 8, int: 123);
@@ -60,5 +66,50 @@ int main()
long long: "long long"));
i = _Generic(l, long: 1, int: 2);
printf("%d\n", i);
+ i = _Generic(foo, fptr: 3, int: 4);
+ printf("%d\n", i);
+
+ (void)_Generic((int(*)[2]){0}, int(*)[2]:0, int(*)[4]:0); //shouldn't match twice
+
+ //should accept ({ }) in the controlling expr of _Generic even in const_wanted contexts
+ struct { _Bool x_0: _Generic(({0;}),default:1); } my_x;
+
+ _Generic((__typeof((float const)((float const){42}))*){0}, float*: 0); //casts lose top-level qualifiers
+ int const x = 42; __typeof((__typeof(x))x) *xp = 0; (void)_Generic(xp, int*: 0); //casts lose top-level qualifiers
+
+ //TEST TERNARY:
+ //Same type
+ _Generic( 0?(long*)0:(long*)0, long*: (void)0);
+ //combining of qualifiers
+ _Generic( 0?(long volatile*)0:(long const*)0, long const volatile*: (void)0);
+ //nul-ptr constant selects other type
+ _Generic( 0?(long*)0:0, long*: (void)0);
+ _Generic( 0?(long*)0:(void*)0, long*: (void)0);
+
+ //void ptrs get chosen preferentially; qualifs still combine
+ _Generic( 0?(int volatile*)0: (void const*)1, void volatile const*: (void)0);
+ //like gcc but not clang, don't treat (void* const as the null-ptr constant)
+ _Generic( 0?(int volatile*)0: (void const*)0, void volatile const*: (void)0);
+
+ //ptrs to incomplete types get completed
+ (void)(sizeof(struct { int x:_Generic( 0?(int (*)[4])0 : (int (*)[])0, int (*)[4]:+1, int (*)[5]:(void)0); }));
+ (void)(sizeof(struct { int x:_Generic( 0?(int (*)[])0 : (int (*)[4])0, int (*)[4]:+1, int (*)[5]:(void)0); }));
+
+ {
+ /* completion shouldn't affect the type of decl */
+ char **argv;
+ _Generic(argv, char**: (void)0);
+ _Generic(0?(char const*)0:argv[0], char const*: (void)0);
+ _Generic(argv, char**: (void)0);
+ }
+ {
+ extern int (*ar)[];
+ (void)(sizeof(struct { int x:_Generic( 0?(int (*)[4])0 : (int (*)[])0, int (*)[4]:+1, int (*)[5]:(void)0); }));
+ (void)(sizeof(struct { int x:_Generic( 0?(int (*)[])0 : (int (*)[4])0, int (*)[4]:+1, int (*)[5]:(void)0); }));
+ (void)(sizeof(struct { int x:_Generic( 0?ar : (int (*)[4])0, int (*)[4]:+1, int (*)[5]:(void)0); }));
+ (void)(sizeof(struct { int x:_Generic( 0?(int (*)[4])0 : ar, int (*)[4]:+1, int (*)[5]:(void)0); }));
+ (void)(sizeof(struct { int x:_Generic( 0?(int (*)[5])0 : ar, int (*)[5]:+1, int (*)[4]:(void)0); }));
+ }
+
return 0;
}