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]

possible pedantic bug


The following code:

enum { FOO = 3 };
int main()
{
   int* arr = new int[FOO];
   return 0;
}

when compiled with the "-pedantic" option will produce the warning

    "warning: size in array new must have integral type"

This has been tested with version 2.95 under Solaris 2.6, and also with the 
nightly snapshot validator at http://www.codesourcery.com/gcc-compile.html.

Replacing FOO with a number (such as 3) in the first line of main() will 
compile without warnings.

It is complaining that FOO is not an integral type.  While that is true, the 
Standard C++ specification seems clear that a conversion from the 
enumeration to an integral type should happen automatically and implicitly 
[cf. sections 4 (especially 4.3 and 4.5) and 7.2].  For example, the line
    int bar = FOO;
compiles without any warnings.  The warning above only occurs when 
allocating a dynamic array, yet after a careful reading of section 5.3.4 I 
cannot find any reason that the implicit conversion/promotion should not 
occur when using new.

Thanks for your time.

Jeff Bouis

________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com


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