Bug 15624 - Defined types lose const qualifiers in certain method signatures.
Summary: Defined types lose const qualifiers in certain method signatures.
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.3.2
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-05-24 01:03 UTC by Steve Brenneis
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

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


Attachments
Test case. (269 bytes, application/x-gzip)
2004-05-24 01:05 UTC, Steve Brenneis
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Steve Brenneis 2004-05-24 01:03:18 UTC
Invalid method signatures are generated where parameter types are defined,
particularly inside namespaces (namespace, struct, class).
Comment 1 Steve Brenneis 2004-05-24 01:05:47 UTC
Created attachment 6366 [details]
Test case.

Test case reproduces the bug.
Comment 2 Steve Brenneis 2004-05-24 01:08:10 UTC
Command line: g++ gcctest.cc

Compiler output:

gcctest.cc: In function `int main(int, char**)':
gcctest.cc:28: error: invalid conversion from `const char*' to `char*'
gcctest.cc:28: error:   initializing argument 1 of `void ScopeTest::test(char*)
   '
Comment 3 Andrew Pinski 2004-05-24 01:33:11 UTC
Here is a smaller example:
typedef char* CharPtr;
void t(const CharPtr);
void f(const char *t1)
{
  t(t1);
}

But I think this is invalid.
Comment 4 Wolfgang Bangerth 2004-05-24 13:47:17 UTC
'const CharPtr' is a constant pointer to a character. 
'const char *' is a pointer to a constant character. 
The testcase is therefore invalid code, and gcc is correct 
in reporting an error. 
 
W. 
Comment 5 Steve Brenneis 2004-05-24 17:46:41 UTC
The error message from gcc, then, is misleading. It fails to indicate any const
qualifier in the method signature. Should this be filed as a separate bug?
Comment 6 Wolfgang Bangerth 2004-05-24 17:49:08 UTC
Um, why do you say that? The error message is 
  invalid conversion from `const char*' to `char*' 
which is about as clear as it can be, no? 
 
W. 
Comment 7 Steve Brenneis 2004-05-24 23:10:28 UTC
gcctest.cc:28: error:   initializing argument 1 of `void ScopeTest::test(char*)
   '

Argument 1 of ScopeTest::test is "const TestTraits::CharPtr". The error message
indicates a misleading error and an invalid method signature, hence the bug
report. As you are technically correct about the error report, gcc should report
"error: invalid conversion from `const char*' to `char const*'" and "error:
initializing argument 1 of void ScopeTest::test(char const*)." While the fact of
the error is correct, the report of the error generated by gcc is incorrect and
misleading.
Comment 8 Wolfgang Bangerth 2004-05-25 00:09:25 UTC
No, gcc is still correct since from a language viewpoint, the 
following two declarations are exactly identical: 
  void f(char *); 
  void f(char *const); 
For the argument signature, the const in the second case is irrelevant, 
and is thus dropped. You can see this by simply compiling these two 
lines above (as a C file; remember that C does not have function 
overloading) -- the compiler accepts this as a duplicate declaration,  
whereas it does not accept these two lines: 
  void f(char *); 
  void f(const char*); 
generating an error about conflicting declarations. 
 
W. 
Comment 9 Steve Brenneis 2004-05-25 13:08:51 UTC
Right you are. I re-read ISO/IEC 14882:1998(E)-8.3.5(3). Thanks for your time
and the discussion.