Summary: | g++ -pedantic issues error array bound not integer although it is a constant | ||
---|---|---|---|
Product: | gcc | Reporter: | Frank Brase <brase> |
Component: | c++ | Assignee: | Not yet assigned to anyone <unassigned> |
Status: | RESOLVED INVALID | ||
Severity: | normal | CC: | bangerth, gcc-bugs |
Priority: | P3 | ||
Version: | 4.1.1 | ||
Target Milestone: | --- | ||
Host: | Target: | ||
Build: | Known to work: | ||
Known to fail: | Last reconfirmed: |
Description
Frank Brase
2006-09-08 08:28:00 UTC
> 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.
|