public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/28981] New: g++ -pedantic issues error array bound not integer although it is a constant
@ 2006-09-08 8:28 brase at lucent dot com
2006-10-12 0:39 ` [Bug c++/28981] " bangerth at dealii dot org
0 siblings, 1 reply; 2+ messages in thread
From: brase at lucent dot com @ 2006-09-08 8:28 UTC (permalink / raw)
To: gcc-bugs
g++ version: 4.1.1
target platform: linux kernel 2.6.13-15
with option "pedantic" the following line does not compile outside main:
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
Note: within main the same expression does compile with pedantic option
Here is a sample program:
// Begin of sample program
//
// Question: Why does array3 not compile ?
// this file demonstrates a problem in compilation with the pedantic option
//
// btspc21 > g++ -pedantic -c compiler_fail.cc
// compiler_fail.cc:18: error: array bound is not an integer constant
// float conversion alone compiles
int array1[(const unsigned short) (20.5)];
// calculation compiles
int array2[(const unsigned short) (20 * 45)];
// combination does not compile
int array3[(const unsigned short) (20.5 * 3)];
int main()
{
// combination in main does compile
int array4[(unsigned short) (20.5*3)];
}
// End of sample program
--
Summary: g++ -pedantic issues error array bound not integer
although it is a constant
Product: gcc
Version: 4.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: brase at lucent dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28981
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug c++/28981] g++ -pedantic issues error array bound not integer although it is a constant
2006-09-08 8:28 [Bug c++/28981] New: g++ -pedantic issues error array bound not integer although it is a constant brase at lucent dot com
@ 2006-10-12 0:39 ` bangerth at dealii dot org
0 siblings, 0 replies; 2+ messages in thread
From: bangerth at dealii dot org @ 2006-10-12 0:39 UTC (permalink / raw)
To: gcc-bugs
------- 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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2006-10-12 0:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-09-08 8:28 [Bug c++/28981] New: g++ -pedantic issues error array bound not integer although it is a constant brase at lucent dot com
2006-10-12 0:39 ` [Bug c++/28981] " bangerth at dealii dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).