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]
Other format: [Raw text]

[Bug c++/12615] [3.3 Regression] initializer syntax for POD structs gives parse error


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12615



------- Additional Comments From bruno at clisp dot org  2003-10-15 18:43 -------
Gabriel dos Reis writes: 
>   object a = { 0, 0 }; // for initialization. 
>   object a; a = (object) { 0, 0 }; 
 
This recommendation, to use different syntax for initialization than for 
assignment, goes against the ISO C++ grammar. The allowed syntax 
for initializers is: 
 
  initializer: 
          = initializer-clause 
          ( expression-list ) 
  initializer-clause: 
          assignment-expression 
          { initializer-list ,opt } 
          { } 
  expression-list: 
          assignment-expression 
          expression-list , assignment-expression 
 
This means that g++ should grok any "assignment-expression" as initializer. 
"assignment-expression" occurs in a few other places in the grammar as 
well: throw statements, default values for optional parameters of functions, 
general expressions. In all these cases, the GNU "Compound Literal" extension 
      ((object) { 0, 0 }) 
is supported. In the initializer case, g++ 3.3.1 gives an error. Which means, 
g++ 3.3.1 has an inconsistent definition of what is an "assignment-expression". 
 
Look here: func1, func2, func3 are accepted without error. func4 gives an error. 
======================================================= 
struct object 
{ 
  unsigned long one_o; 
  unsigned int allocstamp; 
}; 
typedef struct object object; 
 
//#define NULL_OBJECT ((object) { .one_o = 0, .allocstamp = 0 }) 
//#define NULL_OBJECT ((object) { one_o: 0, allocstamp: 0 }) 
#define NULL_OBJECT ((object) { 0, 0 }) 
 
// throw-expression: 
//       throw assignment-expression_opt 
void func1 () { throw NULL_OBJECT; } 
 
// expression: 
//       assignment-expression 
void func2 (object a) { a = NULL_OBJECT; } 
 
// parameter-declaration: 
//       decl-specifier-seq declarator = assignment-expression 
void func3 (object a = NULL_OBJECT) {} 
 
// initializer: 
//       = initializer-clause 
//       ( expression-list ) 
// initializer-clause: 
//       assignment-expression 
void func4 () { object a = NULL_OBJECT; } 
=======================================================


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