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 - assignment and increment of SDL_Scancode broken for g++, but not gcc
Summary: assignment and increment of SDL_Scancode broken for g++, but not gcc
Status: RESOLVED INVALID
Alias: None
Product: SDL
Classification: Unclassified
Component: *don't know* (show other bugs)
Version: HG 2.0
Hardware: x86_64 Mac OS X 10.6
: P2 minor
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-09-01 22:00 UTC by automata
Modified: 2013-02-18 14:45 UTC (History)
1 user (show)

See Also:


Attachments
a small program demonstrating the error (444 bytes, application/octet-stream)
2012-09-01 22:00 UTC, automata
Details

Note You need to log in before you can comment on or make changes to this bug.
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.