Bug 46765 - Superfluous 'const' declaration does not generate error or warning
Summary: Superfluous 'const' declaration does not generate error or warning
Status: RESOLVED DUPLICATE of bug 43651
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.5.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-12-02 13:33 UTC by Fredrik Hederstierna
Modified: 2010-12-02 16:57 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
example file for const. (425 bytes, text/x-csrc)
2010-12-02 13:34 UTC, Fredrik Hederstierna
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Fredrik Hederstierna 2010-12-02 13:33:50 UTC
Assume we want to declare a pointer to constant data.
This can be done by e.g.

  int const *       ptrToConst1;

But C/C++ also accepts:

  //identical to: int const *       ptrToConst,
  const int *       ptrToConst2;

But GCC also accept a double-const declation:

  //identical to ??: const int *       ptrToConst2;
  //superfluous const? No warning nor error.
  const int const * ptrToConst3;

The superfluous 'const' declaration does not generate error or warning.
It's obvious that the programmer most likely wanted to declare
"constant pointer to constant data", but he only gets
"pointer to constant data". He should get a warning or parse error for this.
It's no meaning to declare 'constant data' twice.
The second const-declaration does not have any effect.

I'm compiling with GCC-4.5.1 and having all possible warning flags:
"-W -Wall -Wextra".

I also attach small example file with test of various const-declarations.
Comment 1 Fredrik Hederstierna 2010-12-02 13:34:26 UTC
Created attachment 22602 [details]
example file for const.
Comment 2 Joseph S. Myers 2010-12-02 16:57:02 UTC
See bug 43651.

*** This bug has been marked as a duplicate of bug 43651 ***