Bug 44322 - Bogus warning when assigning pointer-to-array with both "const" and "restrict"
Summary: Bogus warning when assigning pointer-to-array with both "const" and "restrict"
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: 4.6.0
Assignee: Joseph S. Myers
URL:
Keywords: diagnostic
Depends on:
Blocks: 16989
  Show dependency treegraph
 
Reported: 2010-05-29 13:23 UTC by Raphael 'kena' Poss
Modified: 2010-06-05 12:57 UTC (History)
2 users (show)

See Also:
Host: x86_64-apple-darwin10
Target: x86_64-apple-darwin10
Build: x86_64-apple-darwin10
Known to work: 4.6.0
Known to fail:
Last reconfirmed: 2010-06-05 10:10:33


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Raphael 'kena' Poss 2010-05-29 13:23:58 UTC
The following code is valid according to C99:

void * restrict const a[2];
void * restrict const (*p2)[2];

void foo(void) {
   p2 = &a;
}

However GCC complains with:

a.c: In function 'foo':
a.c:14:7: warning: assignment from incompatible pointer type

If either "const" or "restrict" (or both) is omitted from the declaration of 
"a" and "p", no warning is generated.

Despite the warning, code generation and optimization behave properly.

FYI, Clang 1.0.2 accepts this code without warning.
Comment 1 Joseph S. Myers 2010-06-05 10:10:33 UTC
Confirmed.  Testing a patch.
Comment 2 Joseph S. Myers 2010-06-05 12:54:58 UTC
Subject: Bug 44322

Author: jsm28
Date: Sat Jun  5 12:54:41 2010
New Revision: 160312

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=160312
Log:
	PR c/44322
	* c-typeck.c (build_unary_op): Merge qualifiers into pointer
	target type for ADDR_EXPR; require no changes to qualifiers except
	for function types.
	* c-tree.h (c_build_type_variant): Remove.

testsuite:
	* gcc.dg/c99-restrict-4.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/c99-restrict-4.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-tree.h
    trunk/gcc/c-typeck.c
    trunk/gcc/testsuite/ChangeLog

Comment 3 Joseph S. Myers 2010-06-05 12:57:22 UTC
Fixed for 4.6.