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++/28981] g++ -pedantic issues error array bound not integer although it is a constant



------- Comment #1 from bangerth at dealii dot org  2006-10-12 00:39 -------
> int array3[(const unsigned short) (20.5 * 3)];
> 
> error message from compiler is:
> "error: array bound is not an integer constant"
> 
> to me this is wrong because the expression "(const unsigned short) (20.5 * 3)"
> is an integer constant

It's actually not:
--------------------
  5.19  Constant expressions                                [expr.const]

1 In several places,  C++  requires  expressions  that  evaluate  to  an
  integral  or  enumeration  constant:  as  array  bounds  (_dcl.array_,
  _expr.new_), as case expressions (_stmt.switch_), as bit-field lengths
  (_class.bit_),  as  enumerator  initializers  (_dcl.enum_),  as static
  member  initializers  (_class.static.data_),  and   as   integral   or
  enumeration non-type template arguments (_temp.arg_).

     constant-expression:
             conditional-expression

  An    integral   constant-expression   can   involve   only   literals
  (_lex.literal_), enumerators, const variables or static  data  members
  of integral or enumeration types initialized with constant expressions
  (_dcl.init_), non-type template parameters of integral or  enumeration
  types,  and  sizeof  expressions.   Floating literals (_lex.fcon_) can
  appear only if they are cast to integral or enumeration  types.   Only
  type  conversions  to  integral  or enumeration types can be used.  In
  particular, except in sizeof expressions,  functions,  class  objects,
  pointers,  or references shall not be used, and assignment, increment,
  decrement, function-call, or comma operators shall not be used.
------------------------
Note that floating literals are only allowed if immediately cast to integral
or enumeration types. No arithmetic on them is allowed.

W.


-- 

bangerth at dealii dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bangerth at dealii dot org
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


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