+2016-05-13 Joseph Myers <joseph@codesourcery.com>
+
+ * c-decl.c (grokdeclarator): For C11, discard qualifiers on
+ function return type.
+
2016-05-12 Marek Polacek <polacek@redhat.com>
PR c/70756
qualify the return type, not the function type. */
if (type_quals)
{
+ int quals_used = type_quals;
/* Type qualifiers on a function return type are
normally permitted by the standard but have no
effect, so give a warning at -Wreturn-type.
Qualifiers on a void return type are banned on
function definitions in ISO C; GCC used to used
- them for noreturn functions. */
- if (VOID_TYPE_P (type) && really_funcdef)
+ them for noreturn functions. The resolution of C11
+ DR#423 means qualifiers (other than _Atomic) are
+ actually removed from the return type when
+ determining the function type. */
+ if (flag_isoc11)
+ quals_used &= TYPE_QUAL_ATOMIC;
+ if (quals_used && VOID_TYPE_P (type) && really_funcdef)
pedwarn (loc, 0,
"function definition has qualified void return type");
else
warning_at (loc, OPT_Wignored_qualifiers,
"type qualifiers ignored on function return type");
- type = c_build_qualified_type (type, type_quals);
+ /* Ensure an error for restrict on invalid types; the
+ DR#423 resolution is not entirely clear about
+ this. */
+ if (flag_isoc11
+ && (type_quals & TYPE_QUAL_RESTRICT)
+ && (!POINTER_TYPE_P (type)
+ || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type))))
+ error_at (loc, "invalid use of %<restrict%>");
+ if (quals_used)
+ type = c_build_qualified_type (type, quals_used);
}
type_quals = TYPE_UNQUALIFIED;
+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
/* 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);
/* 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. */
/* 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" } */
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);
--- /dev/null
+/* 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" } */
--- /dev/null
+/* 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" } */