diff --git a/CHANGES.current b/CHANGES.current index 455f79128..5bc2b4982 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -11,6 +11,9 @@ Version 4.0.0 (in progress) [OCaml] #1437 OCaml has been give the 'Experimental' language status. The examples work and most of the test-suite is also working, so it is quite close to being a 'Supported' language. +2019-02-10: ZackerySpytz + #1464 Add support for C++14 binary integer literals. + 2019-02-10: ZackerySpytz #1450 Add support for C++11 UCS-2 and UCS-4 character literals. Also add support for C++17 UTF8 character literals. diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 50a52441f..e7e3dd07b 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -162,6 +162,7 @@ CPP_TEST_CASES += \ cpp_nodefault \ cpp_static \ cpp_typedef \ + cpp14_binary_integer_literals \ cpp17_nested_namespaces \ cpp17_nspace_nested_namespaces \ cpp17_u8_char_literals \ diff --git a/Examples/test-suite/cpp14_binary_integer_literals.i b/Examples/test-suite/cpp14_binary_integer_literals.i new file mode 100644 index 000000000..9c696b5a5 --- /dev/null +++ b/Examples/test-suite/cpp14_binary_integer_literals.i @@ -0,0 +1,31 @@ +%module cpp14_binary_integer_literals + +// Tests are designed so that code compiles with C++98 compilers + +%{ +#if __cplusplus >= 201402L +#define CPP14 1 +#endif +%} + +int b1 = 0b1; +int b2 = 0b10; +long b3 = 0b11l; +unsigned long b4 = 0b100ul; +unsigned long b5 = 0B101UL; + +%{ +#if defined(CPP14) +int b1 = 0b1; +int b2 = 0b10; +long b3 = 0b11l; +unsigned long b4 = 0b100ul; +unsigned long b5 = 0B101UL; +#else +int b1 = 1; +int b2 = 2; +long b3 = 3; +unsigned long b4 = 4; +unsigned long b5 = 5; +#endif +%} diff --git a/Examples/test-suite/python/cpp14_binary_integer_literals_runme.py b/Examples/test-suite/python/cpp14_binary_integer_literals_runme.py new file mode 100644 index 000000000..8274ec6b5 --- /dev/null +++ b/Examples/test-suite/python/cpp14_binary_integer_literals_runme.py @@ -0,0 +1,16 @@ +from cpp14_binary_integer_literals import * + +if cvar.b1 != 1: + raise RuntimeError + +if cvar.b2 != 2: + raise RuntimeError + +if cvar.b3 != 3: + raise RuntimeError + +if cvar.b4 != 4: + raise RuntimeError + +if cvar.b5 != 5: + raise RuntimeError diff --git a/Source/Swig/scanner.c b/Source/Swig/scanner.c index f141037dd..24a07e68b 100644 --- a/Source/Swig/scanner.c +++ b/Source/Swig/scanner.c @@ -1162,6 +1162,8 @@ static int look(Scanner *s) { state = 84; else if ((c == 'x') || (c == 'X')) state = 85; + else if ((c == 'b') || (c == 'B')) + state = 850; else if (c == '.') state = 81; else if ((c == 'l') || (c == 'L')) { @@ -1203,6 +1205,21 @@ static int look(Scanner *s) { return SWIG_TOKEN_INT; } break; + case 850: + /* This is a binary number */ + if ((c = nextchar(s)) == 0) + return SWIG_TOKEN_INT; + if ((c == '0') || (c == '1')) + state = 850; + else if ((c == 'l') || (c == 'L')) { + state = 87; + } else if ((c == 'u') || (c == 'U')) { + state = 88; + } else { + retract(s, 1); + return SWIG_TOKEN_INT; + } + break; case 86: /* Rest of floating point number */