diff --git a/tccgen.c b/tccgen.c index ab04f30a..4364ede4 100644 --- a/tccgen.c +++ b/tccgen.c @@ -5119,9 +5119,9 @@ static int post_type(CType *type, AttributeDef *ad, int storage, int td) /* if no parameters, then old type prototype */ l = FUNC_OLD; skip(')'); - /* NOTE: const is ignored in returned type as it has a special - meaning in gcc / C++ */ - type->t &= ~VT_CONSTANT; + /* A function return value has the unqualified version of its + declared type. */ + type->t &= ~(VT_CONSTANT | VT_VOLATILE); /* some ancient pre-K&R C allows a function to return an array and the array brackets to be put after the arguments, such that "int c()[]" means something like "int[] c()" */ diff --git a/tests/tests2/150_return_qualifiers.c b/tests/tests2/150_return_qualifiers.c new file mode 100644 index 00000000..b8a06f5b --- /dev/null +++ b/tests/tests2/150_return_qualifiers.c @@ -0,0 +1,30 @@ +const int const_return(void); +volatile int volatile_return(void); +int *restrict restrict_return(void); + +_Static_assert(__builtin_types_compatible_p(__typeof__(const_return()) *, int *), + "const is removed from a return type"); +_Static_assert(__builtin_types_compatible_p(__typeof__(volatile_return()) *, int *), + "volatile is removed from a return type"); +_Static_assert(__builtin_types_compatible_p(__typeof__(restrict_return()) *, int **), + "restrict is removed from a return type"); + +int const_return(void) +{ + return 0; +} + +int volatile_return(void) +{ + return 0; +} + +int *restrict_return(void) +{ + return 0; +} + +int main(void) +{ + return 0; +} diff --git a/tests/tests2/150_return_qualifiers.expect b/tests/tests2/150_return_qualifiers.expect new file mode 100644 index 00000000..e69de29b