Bug 25801 - bad diagnostic for increment/decrement of pointer to incomplete array
bad diagnostic for increment/decrement of pointer to incomplete array
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: c
4.2.0
: P3 minor
: ---
Assigned To: Marek Polacek
: diagnostic
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2006-01-16 00:28 UTC by Joseph S. Myers
Modified: 2014-05-02 18:15 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 2.95.3, 3.0.4, 3.3.1, 3.4.0, 4.0.0, 4.1.0, 4.2.0
Last reconfirmed: 2012-01-19 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joseph S. Myers 2006-01-16 00:28:27 UTC
extern int (*a)[];
void g(void) { a++; }

yields the diagnostics

t2.c: In function 'g':
t2.c:2: error: increment of pointer to unknown structure
t2.c:2: error: arithmetic on pointer to an incomplete type

This isn't a pointer to a structure, it's one to an array; and after giving the first diagnostic, it's useless to go on and give the second as well.
Comment 1 Andrew Pinski 2006-01-16 01:25:15 UTC
The problem with the first error message is obvious where it goes wrong (in c-typeck.c):
            if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (result_type)))
              {
                if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
                  error ("increment of pointer to unknown structure");
                else
                  error ("decrement of pointer to unknown structure");

The second one comes from calling c_size_in_bytes.  It seems like we can remove the error call from c_size_in_bytes as the other place were we call it, we check for a imcomplete type right before calling it.
Oh and the second error message also happens with the struct case too.

Both are these problems are not a regression as far as I can tell as both wrong error messages are in 2.95.3.
Comment 2 Marek Polacek 2014-04-18 17:04:11 UTC
I'm testing a patch.
Comment 3 Marek Polacek 2014-05-02 18:14:15 UTC
Author: mpolacek
Date: Fri May  2 18:13:43 2014
New Revision: 210013

URL: http://gcc.gnu.org/viewcvs?rev=210013&root=gcc&view=rev
Log:
	PR c/25801
	* c-typeck.c (c_size_in_bytes): Update comment.  Don't call error.
	Return size_one_node when the type is not complete.
	(pointer_diff): Remove comment.
	(build_unary_op): Improve error messages.

	* gcc.dg/pr25801.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/pr25801.c
Modified:
    trunk/gcc/c/ChangeLog
    trunk/gcc/c/c-typeck.c
    trunk/gcc/testsuite/ChangeLog
Comment 4 Marek Polacek 2014-05-02 18:15:20 UTC
Fixed.