We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 1590

Summary: assignment and increment of SDL_Scancode broken for g++, but not gcc
Product: SDL Reporter: automata
Component: *don't know*Assignee: Ryan C. Gordon <icculus>
Status: RESOLVED INVALID QA Contact: Sam Lantinga <slouken>
Severity: minor    
Priority: P2 CC: john
Version: HG 2.0   
Hardware: x86_64   
OS: Mac OS X 10.6   
Attachments: a small program demonstrating the error

Description automata 2012-09-01 22:00:09 UTC
Created attachment 942 [details]
a small program demonstrating the error

Hello!

While trying out SDL2 from HG (August 13th snapshot) on OSX, I discovered that g++ gives a compilation error when attempting to assign an int value to SDL_Scancode or to increment it with the ++ operator, as is done in the testkeys.c file. The same code compiles without complaint in gcc. This is, it seems, actually the correct behavior for both C and C++ according to their respective standards.

While somewhat of a minor issue, it would probably be good to find a way to make the behavior of SDL_Scancode variables (and other enum type variables in the codebase) identical whether the code they are used in is compiled with a C or C++ compiler.

-

I have attached a small example file demonstrating the problem. Attempt to compile it with:

g++ main.cpp `sdl2-config --cflags --libs`

It should fail with errors like these:

main.cpp:16:17: error: invalid conversion from 'int' to 'SDL_Scancode' [-fpermissive]
main.cpp:16:52: error: no match for 'operator++' in '++scancode'

If you change the name of the file to main.c and compile with gcc, the file should compile without issue.
Comment 1 john 2013-02-18 14:45:31 UTC
Not a bug. C++ is more strict than C about implicit conversions between enum types and intghers.