This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

string is const char [] ?



Hello,

we found following problem with egcs (egcs-2.90.23 980102 (egcs-1.0.1
release)), but we are not sure if it is a bug or not :

following program outputs 

this is f(char*) test not const
this is f(const char*) test const 1
this is f(char*) test should be const

instead of

this is f(char*) test not const
this is f(const char*) test const 1
this is f(const char*) test should be const

what we would expect after checking the c++ draft :

from the  1997 C++ Public Review Document :

2.13.4  String literals                                   [lex.string]
[..]
1 A  string  literal  is  a  sequence  of  characters  (as  defined   in
  _lex.ccon_) surrounded by double quotes, optionally beginning with the
  letter L, as in "..." or L"...".  A string literal that does not begin
  with  L  is  an  ordinary string literal, also referred to as a narrow
  string literal.  An ordinary string literal has type "array of n __const__
  char"  and  static storage duration
[..]

Is this a bug ?


/* begin */
#include <iostream.h>

void 
f(char *i)
{
  cout << "this is f(char*) " << i << endl;
}

void 
f(const char* i)
{
  cout << "this is f(const char*) " << i << endl;
}



int
main(int argc, char *argv[])
{
  char a1[] = "test not const";
  const char a2[] = "test const 1";
  
  f(a1);
  f(a2);
  f("test should be const");
}
/* end */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]