Bug 15236 - pedantic switch modifies treatment of non-ISO compliant enumerations
pedantic switch modifies treatment of non-ISO compliant enumerations
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: c
3.3.3
: P2 normal
: tree-ssa
Assigned To: Not yet assigned to anyone
: FIXME, wrong-code
: 35129 (view as bug list)
Depends on:
Blocks: 4.4pending
  Show dependency treegraph
 
Reported: 2004-04-30 20:17 UTC by Kevin Hall
Modified: 2008-08-13 10:27 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 3.3.1 3.3.3 3.4.0 4.0.0 3.2.3
Last reconfirmed: 2005-12-18 00:39:33


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kevin Hall 2004-04-30 20:17:07 UTC
The GNU compiler treats some non-ISO compliant enumerations as being 64 bit 
enumerations rather than 32-bit enumerations.  Specifying the "-pedantic" 
command line switch not only warns about the enumeration being non-ISO 
compliant, but it also forces those enumerations to be treated as 32-bit 
enumerations.  Being a switch to generate warnings about non-ISO compliance, 
it should do just that -- warn the user.  It should not change the behavior of 
the compiler.

I have generated the .i and .s files, but do not see a way to attach them to 
this report.  No matter, the program to reproduce the problem is only 12 lines 
long.

The problem exhibits itself with:
 - gcc 3.3.3 on Fedora Core 2 Linux
 - gcc 3.3.1 on Cygwin

The command line for default behavior of gcc is:
  gcc enum.c -o enum

The command line for exhibiting the problem is:
  gcc -pedantic enum.c -o enum

The source file enum.c is:

#include <stdio.h>

typedef enum MyEnum
{
  A = -1,
  B = 0xFFFFFFFF
} MyEnum;

int main()
{
  printf("sizeof(MyEnum) = %d\n", sizeof(MyEnum));
}
Comment 1 Wolfgang Bangerth 2004-04-30 20:38:19 UTC
Confirmed with 3.4.0 and 3.5.0. -pedantic should indeed not change the 
generated code. 
 
W. 
Comment 2 Wolfgang Bangerth 2004-04-30 20:40:40 UTC
As an aside: the fact that we widen the integer type (without -pedantic) 
to an 8-byte type is something that changed between 2.95 and 3.2: 
 
g/x> /home/bangerth/bin/gcc-3.4-pre/bin/gcc x.c 
g/x> ./a.out  
sizeof(MyEnum) = 8 
g/x> /home/bangerth/bin/gcc-3.3.4-pre/bin/gcc x.c 
g/x> ./a.out  
sizeof(MyEnum) = 8 
g/x> /home/bangerth/bin/gcc-3.2*/bin/gcc x.c 
g/x> ./a.out  
sizeof(MyEnum) = 8 
g/x> /home/bangerth/bin/gcc-2*/bin/gcc x.c 
g/x> ./a.out  
sizeof(MyEnum) = 4 
 
I don't know, though, whether that was a conscious decision or just by 
accident. 
 
W. 
Comment 3 Andrew Pinski 2004-04-30 21:21:31 UTC
Confirmed, in fact there is an XXX in the code now:
      pedwarn ("ISO C restricts enumerator values to range of `int'");
      /* XXX This causes -pedantic to change the meaning of the program.
         Remove?  -zw 2004-03-15  */
      value = convert (integer_type_node, value);


1.133        (aoliva   26-Jul-00):       value = convert (integer_type_node, value);


1.1          (law      11-Aug-97):       pedwarn ("ANSI C restricts enumerator values to range of `int'");
1.1          (law      11-Aug-97):       value = integer_zero_node;

revision 1.133
date: 2000/07/26 03:50:56;  author: aoliva;  state: Exp;  lines: +19 -3
* c-decl.c (finish_enum): Convert enumerations that fit in an
`int' to `int'.
(build_enumerator): In pedantic mode, cast to `int' those that
don't.


The patch which caused part of the regression: <http://gcc.gnu.org/ml/gcc-patches/2000-07/
msg00993.html>, there might be another which caused the regression which this patch is fixing.
Comment 4 Andrew Pinski 2008-02-07 20:34:05 UTC
*** Bug 35129 has been marked as a duplicate of this bug. ***
Comment 5 Manuel López-Ibáñez 2008-02-07 20:56:34 UTC
Cachis, I didn't find this when searching. Anyway, there is a patch that fixes this in PR35129.
Comment 6 Manuel López-Ibáñez 2008-08-13 10:20:26 UTC
Subject: Bug 15236

Author: manu
Date: Wed Aug 13 10:19:03 2008
New Revision: 139050

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=139050
Log:
2008-08-13  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

	PR c/15236
	* diagnostic.c (pedwarn_at): New.
	* toplev.h (pedwarn_at): Declare.
	* c-tree.h (build_enumerator): Update declaration.
	* c-decl.c (finish_enum): Update comment.
	(build_enumerator): Take a location parameter. Give a pedwarn but do
	not perform any conversion.
	* c-parser.c (c_parser_enum_specifier): Set correct location for
	enumerator.
testsuite/
	* gcc.dg/pr15236.c: New.
	* gcc.dg/torture/pr25183.c: Update.

Added:
    trunk/gcc/testsuite/gcc.dg/pr15236.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-decl.c
    trunk/gcc/c-parser.c
    trunk/gcc/c-tree.h
    trunk/gcc/diagnostic.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.dg/torture/pr25183.c
    trunk/gcc/toplev.h

Comment 7 Manuel López-Ibáñez 2008-08-13 10:27:20 UTC
FIXED in GCC 4.4.