[C++11] Allow static_assert at the top level

And disallow it right after template<T>).

Fixes https://github.com/swig/swig/issues/1031 reported by Artem V L.
This commit is contained in:
Olly Betts 2017-08-04 14:09:30 +12:00
parent 46f7217c50
commit a92137a708
4 changed files with 24 additions and 8 deletions

View File

@ -7,6 +7,11 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 4.0.0 (in progress)
===========================
2017-08-05: olly
[C++11] Allow static_assert at the top level (and disallow it right
after template<T>). Fixes https://github.com/swig/swig/issues/1031
reported by Artem V L.
2017-07-17: fflexo
[Java] #674 Add std_list.i to add support for std::list containers. The Java proxy
extends java.util.AbstractSequentialList and makes the C++ std::list container look

View File

@ -877,7 +877,8 @@ so in this case it is entirely possible to pass an int instead of a double to <t
<p>
SWIG correctly parses the new <tt>static_assert</tt> declarations.
SWIG correctly parses the new <tt>static_assert</tt> declarations (though 3.0.12 and earlier
had a bug which meant this wasn't accepted at file scope).
This is a C++ compile time directive so there isn't anything useful that SWIG can do with it.
</p>

View File

@ -1,12 +1,22 @@
/* This test case checks whether SWIG correctly parses and ignores the
keywords "static_assert()" inside the class or struct.
/* This test case checks whether SWIG correctly parses and ignores
"static_assert()" in various places.
*/
%module cpp11_static_assert
%inline %{
static_assert(sizeof(int) >= 2, "What? int size is invalid!");
namespace dummy {
// C++17 allows the message to be omitted, so check that works too.
static_assert(sizeof(int) >= sizeof(short));
}
template <typename T>
struct Check1 {
static_assert(sizeof(int) <= sizeof(T), "not big enough");
Check1() {
static_assert(true);
}
};
template <typename T>

View File

@ -2991,6 +2991,9 @@ c_declaration : c_decl {
SetFlag($$,"aliastemplate");
add_symbols($$);
}
| cpp_static_assert {
$$ = $1;
}
;
/* ------------------------------------------------------------
@ -4209,9 +4212,6 @@ cpp_temp_possible: c_decl {
| cpp_constructor_decl {
$$ = $1;
}
| cpp_static_assert {
$$ = $1;
}
| cpp_template_decl {
$$ = 0;
}
@ -4469,7 +4469,6 @@ cpp_member : c_declaration { $$ = $1; }
default_arguments($$);
}
| cpp_destructor_decl { $$ = $1; }
| cpp_static_assert { $$ = $1; }
| cpp_protection_decl { $$ = $1; }
| cpp_swig_directive { $$ = $1; }
| cpp_conversion_operator { $$ = $1; }
@ -4673,7 +4672,8 @@ cpp_catch_decl : CATCH LPAREN parms RPAREN LBRACE {
}
;
/* static_assert(bool, const char*); */
/* static_assert(bool, const char*); (C++11)
* static_assert(bool); (C++17) */
cpp_static_assert : STATIC_ASSERT LPAREN {
skip_balanced('(',')');
$$ = 0;