Bug 16307 - -Wchar-subscripts does not warn on pointers
Summary: -Wchar-subscripts does not warn on pointers
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.0
: P2 enhancement
Target Milestone: 4.3.0
Assignee: Dirk Mueller
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2004-07-01 00:57 UTC by Martin Sebor
Modified: 2006-10-29 19:13 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-02-26 19:28:06


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Sebor 2004-07-01 00:57:36 UTC
The -Wchar-subscripts option doesn't seem to have any effect. IIRC,
it used to work at some point in the past but this test case doesn't
seem to trigger it in any compiler between 2.95 and 3.4 regardless
of whether char is signed or unsigned.

$ cat t.cpp && g++ --version && g++ -Wchar-subscripts t.cpp
char foo (const char *s)
{
    return s [s ['\x80']];
}

int main ()
{
    foo ("\x80");
}

g++ (GCC) 3.4.0
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Comment 1 Andrew Pinski 2004-07-01 05:00:58 UTC
Confirmed, it only ever worked on a really arrays and not pointers.
Comment 2 Andrew Pinski 2004-11-20 20:42:14 UTC
Fixed on the mainline by:
2004-11-20  Joseph S. Myers  <joseph@codesourcery.com>

	* c-typeck.c (build_array_ref): Don't check for index == 0.  Make
	checks for neither argument being an array or pointer (swapping
	the arguments if necessary), the array argument being a pointer to
	or array of functions and for -Wchar-subscripts warnings upfront.
Comment 3 Andrew Pinski 2004-11-20 20:48:24 UTC
Oh, it is not fixed by that patch.
Comment 4 Dirk Mueller 2006-10-28 23:22:58 UTC
Testing patch.
Comment 5 Dirk Mueller 2006-10-29 18:38:39 UTC
Subject: Bug 16307

Author: mueller
Date: Sun Oct 29 18:38:26 2006
New Revision: 118154

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=118154
Log:
2006-10-29  Dirk Mueller  <dmueller@suse.de>

        PR c++/16307
        * typeck.c (build_array_ref): Warn for char subscriptions
        on pointers.

        * g++.dg/warn/Wchar-subscripts-2.C: New testcase.


Added:
    trunk/gcc/testsuite/g++.dg/warn/Wchar-subscripts-2.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/typeck.c
    trunk/gcc/testsuite/ChangeLog

Comment 6 Dirk Mueller 2006-10-29 19:13:21 UTC
Fixed in 4.3