aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2016-05-13 22:35:39 +0100
committerJoseph Myers <jsm28@gcc.gnu.org>2016-05-13 22:35:39 +0100
commitaa4b467b680f230ab11922d1e29695e1eaba12af (patch)
tree67890b5377876cd47fa3c7b49af6bf90643bad65 /gcc/testsuite
parent653fb4a289f340c37c18432ae50971b0be7f5ed8 (diff)
downloadgcc-aa4b467b680f230ab11922d1e29695e1eaba12af.zip
gcc-aa4b467b680f230ab11922d1e29695e1eaba12af.tar.gz
gcc-aa4b467b680f230ab11922d1e29695e1eaba12af.tar.bz2
Implement C11 DR#423 resolution (ignore function return type qualifiers).
The resolution of C11 DR#423, apart from doing things with the types of expressions cast to qualified types which are only in standard terms observable with _Generic and which agree with how GCC has implemented _Generic all along, also specifies that qualifiers are discarded from function return types: "derived-declarator-type-list function returning T" becomes "derived-declarator-type-list function returning the unqualified version of T" in the rules giving types for function declarators. This means that declarations of a function with both qualified and unqualified return types are now compatible, similar to how different declarations can vary in whether a function argument is declared with a qualifier or unqualified type. This patch implements this resolution. Since the motivation for the change was _Generic, the resolution is restricted to C11 mode; there's no reason to consider there to be a defect in this regard in older standard versions. Some less-obvious issues are handled as follows: * As usual, and as with function arguments, _Atomic is not considered a qualifier for this purpose; that is, function declarations must agree regarding whether the return type is atomic. * By 6.9.1#2, a function definition cannot return qualified void. But with this change, specifying "const void" in the declaration produces the type "function returning void", which is perfectly valid, so "const void f (void) {}" is no longer an error. * The application to restrict is less clear. The way I am interpreting it in this patch is that "unqualified version of T" is not valid if T is not valid, as in the case where T is a restrict-qualified version of a type that cannot be restrict qualified (non-pointer, or pointer-to-function). But it's possible to argue the other way from the wording. Bootstrapped with no regressions on x86_64-pc-linux-gnu. gcc/c: * c-decl.c (grokdeclarator): For C11, discard qualifiers on function return type. gcc/testsuite: * gcc.dg/qual-return-5.c, gcc.dg/qual-return-6.c: New tests. * gcc.dg/call-diag-2.c, gcc.dg/qual-return-2.c , gcc.dg/qual-return-3.c, gcc.dg/qual-return-4.c: Use -std=gnu99. From-SVN: r236231
Diffstat (limited to 'gcc/testsuite')
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/gcc.dg/call-diag-2.c2
-rw-r--r--gcc/testsuite/gcc.dg/qual-return-2.c2
-rw-r--r--gcc/testsuite/gcc.dg/qual-return-3.c2
-rw-r--r--gcc/testsuite/gcc.dg/qual-return-4.c2
-rw-r--r--gcc/testsuite/gcc.dg/qual-return-5.c32
-rw-r--r--gcc/testsuite/gcc.dg/qual-return-6.c12
7 files changed, 54 insertions, 4 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 7ef0797..9a8cd75 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2016-05-13 Joseph Myers <joseph@codesourcery.com>
+
+ * gcc.dg/qual-return-5.c, gcc.dg/qual-return-6.c: New tests.
+ * gcc.dg/call-diag-2.c, gcc.dg/qual-return-2.c ,
+ gcc.dg/qual-return-3.c, gcc.dg/qual-return-4.c: Use -std=gnu99.
+
2016-05-13 Martin Sebor <msebor@redhat.com>
PR c++/60049
diff --git a/gcc/testsuite/gcc.dg/call-diag-2.c b/gcc/testsuite/gcc.dg/call-diag-2.c
index c34252c..b998ea9d 100644
--- a/gcc/testsuite/gcc.dg/call-diag-2.c
+++ b/gcc/testsuite/gcc.dg/call-diag-2.c
@@ -1,7 +1,7 @@
/* Test diagnostics for calling function returning qualified void or
other incomplete type other than void. PR 35210. */
/* { dg-do compile } */
-/* { dg-options "-pedantic-errors" } */
+/* { dg-options "-std=gnu99 -pedantic-errors" } */
const void f_cv (void);
struct s f_s (void);
diff --git a/gcc/testsuite/gcc.dg/qual-return-2.c b/gcc/testsuite/gcc.dg/qual-return-2.c
index 22a1946..1cd1253 100644
--- a/gcc/testsuite/gcc.dg/qual-return-2.c
+++ b/gcc/testsuite/gcc.dg/qual-return-2.c
@@ -1,7 +1,7 @@
/* Test for warnings for qualified function return types. -pedantic test. */
/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
/* { dg-do compile } */
-/* { dg-options "-pedantic" } */
+/* { dg-options "-pedantic -std=gnu99" } */
/* Qualifying a function return type makes no sense. */
diff --git a/gcc/testsuite/gcc.dg/qual-return-3.c b/gcc/testsuite/gcc.dg/qual-return-3.c
index e65f86d..bd76079 100644
--- a/gcc/testsuite/gcc.dg/qual-return-3.c
+++ b/gcc/testsuite/gcc.dg/qual-return-3.c
@@ -4,7 +4,7 @@
/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
/* { dg-do compile } */
-/* { dg-options "" } */
+/* { dg-options "-std=gnu99" } */
int foo (); /* { dg-message "note: previous declaration" "different qualifiers" } */
const int foo () { return 0; } /* { dg-error "conflicting types" "different qualifiers" } */
diff --git a/gcc/testsuite/gcc.dg/qual-return-4.c b/gcc/testsuite/gcc.dg/qual-return-4.c
index 9b61cfe..7bb5b69 100644
--- a/gcc/testsuite/gcc.dg/qual-return-4.c
+++ b/gcc/testsuite/gcc.dg/qual-return-4.c
@@ -3,7 +3,7 @@
types, not other such types within the definition. */
/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
/* { dg-do compile } */
-/* { dg-options "-pedantic" } */
+/* { dg-options "-pedantic -std=gnu99" } */
volatile void (*y)(int);
diff --git a/gcc/testsuite/gcc.dg/qual-return-5.c b/gcc/testsuite/gcc.dg/qual-return-5.c
new file mode 100644
index 0000000..32a08f2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/qual-return-5.c
@@ -0,0 +1,32 @@
+/* Test qualifiers on function return types after DR#423: those
+ qualifiers are now ignored for all purposes (but _Atomic is not,
+ for this purpose, a qualifier). */
+/* { dg-do compile } */
+/* { dg-options "-std=c11 -pedantic-errors" } */
+
+int f1 (void);
+const int f1 (void);
+volatile int f1 (void) { return 0; }
+
+int *restrict f2 (void) { return 0; }
+int *f2 (void);
+
+const volatile long f3 (void);
+long f3 (void);
+
+const volatile void f4 (void) { }
+void f4 (void);
+
+_Atomic int f5 (void); /* { dg-message "previous declaration" } */
+int f5 (void); /* { dg-error "conflicting" } */
+
+int f6 (void); /* { dg-message "previous declaration" } */
+_Atomic int f6 (void) { return 0; } /* { dg-error "conflicting" } */
+
+/* The standard seems unclear regarding the case where restrict is
+ applied to a function return type that may not be
+ restrict-qualified; assume here that it is disallowed. */
+restrict int f7 (void); /* { dg-error "restrict" } */
+
+typedef void FT (void);
+FT *restrict f8 (void); /* { dg-error "restrict" } */
diff --git a/gcc/testsuite/gcc.dg/qual-return-6.c b/gcc/testsuite/gcc.dg/qual-return-6.c
new file mode 100644
index 0000000..5b3ded0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/qual-return-6.c
@@ -0,0 +1,12 @@
+/* Test qualifiers on function return types after DR#423: those
+ qualifiers are now ignored for all purposes (except that _Atomic
+ still affects the type), but should still get warnings. */
+/* { dg-do compile } */
+/* { dg-options "-std=c11 -Wignored-qualifiers" } */
+
+const int f1 (void); /* { dg-warning "qualifiers ignored" } */
+volatile int f2 (void) { return 0; } /* { dg-warning "qualifiers ignored" } */
+const volatile void f3 (void) { } /* { dg-warning "qualifiers ignored" } */
+const void f4 (void); /* { dg-warning "qualifiers ignored" } */
+_Atomic int f5 (void); /* { dg-warning "qualifiers ignored" } */
+_Atomic int f6 (void) { return 0; } /* { dg-warning "qualifiers ignored" } */