Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/usr.bin/xlint/lint1 tests/lint: add test for _Generic ...



details:   https://anonhg.NetBSD.org/src/rev/2d80e26b4a8c
branches:  trunk
changeset: 1021959:2d80e26b4a8c
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jun 27 19:59:23 2021 +0000

description:
tests/lint: add test for _Generic with incompatible return types

diffstat:

 tests/usr.bin/xlint/lint1/c11_generic_expression.c   |  19 ++++++++++++++++---
 tests/usr.bin/xlint/lint1/c11_generic_expression.exp |   5 +++--
 2 files changed, 19 insertions(+), 5 deletions(-)

diffs (55 lines):

diff -r 2614314c610e -r 2d80e26b4a8c tests/usr.bin/xlint/lint1/c11_generic_expression.c
--- a/tests/usr.bin/xlint/lint1/c11_generic_expression.c        Sun Jun 27 19:41:15 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/c11_generic_expression.c        Sun Jun 27 19:59:23 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: c11_generic_expression.c,v 1.1 2021/06/27 18:48:45 rillig Exp $        */
+/*     $NetBSD: c11_generic_expression.c,v 1.2 2021/06/27 19:59:23 rillig Exp $        */
 # 3 "c11_generic_expression.c"
 
 /*
@@ -18,7 +18,7 @@
  * generic-association.  This is a compile-time error.
  */
 const char *
-classify_integer_without_default(double var)
+classify_type_without_default(double var)
 {
        return _Generic(var,
            long double: "long double",
@@ -33,7 +33,7 @@
  * In this case, the 'default' expression is selected.
  */
 const char *
-classify_integer_with_default(double var)
+classify_type_with_default(double var)
 {
        return _Generic(var,
            long double: "long double",
@@ -44,3 +44,16 @@
        /* expect-8: argument 'var' unused */
        /* expect-2: type mismatch (pointer to const char) and (double) *//* FIXME */
 }
+
+/*
+ * The type of a _Generic expression is the one from the selected association.
+ */
+const char *
+classify_char(char c)
+{
+       return _Generic(c,
+           char: "yes",
+           default: 0.0
+       );
+       /* expect-1: (pointer to const char) and integer (char) [183] */
+}
diff -r 2614314c610e -r 2d80e26b4a8c tests/usr.bin/xlint/lint1/c11_generic_expression.exp
--- a/tests/usr.bin/xlint/lint1/c11_generic_expression.exp      Sun Jun 27 19:41:15 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/c11_generic_expression.exp      Sun Jun 27 19:59:23 2021 +0000
@@ -1,4 +1,5 @@
 c11_generic_expression.c(27): error: return value type mismatch (pointer to const char) and (double) [211]
-c11_generic_expression.c(21): warning: argument 'var' unused in function 'classify_integer_without_default' [231]
+c11_generic_expression.c(21): warning: argument 'var' unused in function 'classify_type_without_default' [231]
 c11_generic_expression.c(43): error: return value type mismatch (pointer to const char) and (double) [211]
-c11_generic_expression.c(36): warning: argument 'var' unused in function 'classify_integer_with_default' [231]
+c11_generic_expression.c(36): warning: argument 'var' unused in function 'classify_type_with_default' [231]
+c11_generic_expression.c(57): warning: illegal combination of pointer (pointer to const char) and integer (char) [183]



Home | Main Index | Thread Index | Old Index