Merge branch 'ZackerySpytz-cpp11_u_U_char_encoding_prefixes'

* ZackerySpytz-cpp11_u_U_char_encoding_prefixes:
  Document C++11 UCS-2 UCS-4 and C++17 UTF8 character literals support
  c++17 u8 character literals testcase
  C++17 u8 character literals fix
  C++17 u8 character literals testcase
  Fix the Java tests
  Add support for the C++11 u and U encoding prefixes for char literals
This commit is contained in:
William S Fulton 2019-02-10 17:39:03 +00:00
commit 80b79fc583
8 changed files with 85 additions and 3 deletions

View file

@ -7,6 +7,10 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 4.0.0 (in progress)
===========================
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.
2019-02-10: wsfulton
[MzScheme] #1437 MzScheme/Racket is now an 'Experimental' language. The examples work
and a large portion of the test-suite is also working.

View file

@ -714,6 +714,22 @@ const int SIZE = sizeof...(ClassName<int, int>);
In the above example <tt>SIZE</tt> is of course wrapped as a constant.
</p>
<H3><a name="CPlusPlus11_new_char_literals">7.2.19 New character literals</a></H3>
<p>
C++11 adds support for UCS-2 and UCS-4 character literals.
These character literals are preceded by either 'u' or 'U'.
</p>
<div class="code"><pre>
char16_t a = u'a';
char32_t b = U'b';
</pre></div>
<p>
<b>Compatibility note:</b> SWIG-4.0.0 was the first version to support these Universal Coded Character Set (UCS) character literals.
</p>
<H3><a name="CPlusPlus11_new_string_literals">7.2.19 New string literals</a></H3>

View file

@ -32,6 +32,10 @@ There isn't much in C++17 that affects SWIG, however, work has only just begun o
C++17 support.
</p>
<p>
<b>Compatibility note:</b> SWIG-4.0.0 is the first version to support any C++17 features.
</p>
<H2><a name="CPlusPlus17_core_language_changes">8.2 Core language changes</a></H2>
@ -67,10 +71,20 @@ namespace A {
</pre>
</div>
<H3><a name="CPlusPlus17_u8_char_literals">8.2.2 UTF-8 character literals</a></H3>
<p>
<b>Compatibility note:</b> SWIG-4.0.0 was the first version to support nested namespace definitions.
C++17 added UTF-8 (u8) character literals.
These are of type char.
Example:
</p>
<div class="code">
<pre>
char a = u8'a';
</pre>
</div>
<H2><a name="CPlusPlus17_standard_library_changes">8.3 Standard library changes</a></H2>

View file

@ -164,6 +164,7 @@ CPP_TEST_CASES += \
cpp_typedef \
cpp17_nested_namespaces \
cpp17_nspace_nested_namespaces \
cpp17_u8_char_literals \
curiously_recurring_template_pattern \
default_args \
default_arg_expressions \

View file

@ -47,6 +47,9 @@ wstring aa = L"Wide string";
const char *bb = u8"UTF-8 string";
const char16_t *cc = u"UTF-16 string";
const char32_t *dd = U"UTF-32 string";
// New char literals
char16_t char16_t_char = u'a';
char32_t char32_t_char = U'b';
%}
/* Raw string literals */

View file

@ -0,0 +1,26 @@
%module cpp17_u8_char_literals
// Tests are designed so that code compiles with C++98 compilers
%{
#if __cplusplus >= 201703L
#define CPP17 1
#endif
%}
// UTF-8 character literals will (apparently) have type char8_t in C++20.
char a = u8'a';
char u = u8'u';
char u8 = u8'8';
%{
#if defined(CPP17)
char a = u8'a';
char u = u8'u';
char u8 = u8'8';
#else
char a = 'a';
char u = 'u';
char u8 = '8';
#endif
%}

View file

@ -0,0 +1,10 @@
from cpp17_u8_char_literals import *
if cvar.a != 'a':
raise RuntimeError
if cvar.u != 'u':
raise RuntimeError
if cvar.u8 != '8':
raise RuntimeError

View file

@ -938,10 +938,14 @@ static int look(Scanner *s) {
retract(s, 1);
state = 1000;
}
else if (c == '\'') { /* Definitely u, U or L char */
retract(s, 1);
state = 77;
}
else if (c == 'R') { /* Possibly CUSTOM DELIMITER u, U, L string */
state = 73;
}
else if (c == '8') { /* Possibly u8 string */
else if (c == '8') { /* Possibly u8 string/char */
state = 71;
}
else {
@ -961,7 +965,7 @@ static int look(Scanner *s) {
}
break;
case 71: /* Possibly u8 string */
case 71: /* Possibly u8 string/char */
if ((c = nextchar(s)) == 0) {
state = 76;
}
@ -969,6 +973,10 @@ static int look(Scanner *s) {
retract(s, 1); /* Definitely u8 string */
state = 1000;
}
else if (c=='\'') {
retract(s, 1); /* Definitely u8 char */
state = 77;
}
else if (c=='R') {
state = 74; /* Possibly CUSTOM DELIMITER u8 string */
}