diff --git a/CHANGES.current b/CHANGES.current index 35ce98b3e..a3b03b07a 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,13 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.6 (in progress) =========================== +2015-05-01: wsfulton + Fix handling of conversion operators where the operator is split over multiple + lines or has comments within the operator type. Fixes #401. + + Also fix similar problem with normal operators which gave a syntax error if split over + multiple lines or had a comment within the operator declaration. + 2015-04-30: olly Ignore unknown preprocessor directives which are inside an inactive conditional (github issue #394, reported by Dan Wilcox). diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 6376bc79d..e2ab8ed3f 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -156,6 +156,7 @@ CPP_TEST_CASES += \ conversion \ conversion_namespace \ conversion_ns_template \ + conversion_operators \ cplusplus_throw \ cpp_basic \ cpp_enum \ diff --git a/Examples/test-suite/conversion_operators.i b/Examples/test-suite/conversion_operators.i new file mode 100644 index 000000000..fa9e52cac --- /dev/null +++ b/Examples/test-suite/conversion_operators.i @@ -0,0 +1,55 @@ +%module conversion_operators + +// Test bug #401 where the conversion operator name incorrectly included the newline character +// Also test comments around conversion operators due to special handling in the scanner for conversion operators + +// These one line ignores should match the conversion operator names to suppress Warning 503 - SWIGWARN_LANG_IDENTIFIER +%ignore operator const EcReal; +%ignore operator EcImaginary const; +%ignore operator EcComplex const; + +%inline %{ + +struct EcReal {}; +struct EcImaginary {}; +struct EcComplex {}; + +struct EcAngle { + operator const EcReal + ( + ) const; + operator EcImaginary +const ( + ) const; + operator +EcComplex + const ( + ) const; +}; + +struct EcAngle2 { + operator const EcReal/* C comment */ + ( + ) const; + operator EcImaginary/* C comment */ +const ( + ) const; + operator/* C comment */ +EcComplex + const ( + ) const; +}; + +struct EcAngle3 { + operator const EcReal // C++ comment + ( + ) const; + operator EcImaginary // C++ comment +const ( + ) const; + operator // C++ comment +EcComplex + const ( + ) const; +}; +%} diff --git a/Examples/test-suite/operator_overload_break.i b/Examples/test-suite/operator_overload_break.i index f5f3c1a46..cad19a71e 100644 --- a/Examples/test-suite/operator_overload_break.i +++ b/Examples/test-suite/operator_overload_break.i @@ -12,6 +12,10 @@ %rename(PlusPlusPostfix) operator++(int); #endif +%ignore operator new (size_t); +%ignore operator delete (void *); +%ignore operator delete[] (void *); + %{ #include using namespace std; @@ -58,6 +62,11 @@ public: void PrintK() {std::cerr << k << std::endl;} int k; + void *operator new + (size_t); // definition split over two lines was giving syntax error + void operator delete /* comment here did not work */ (void *); + void operator + delete[] (void *); }; %} diff --git a/Source/CParse/cscanner.c b/Source/CParse/cscanner.c index a33a81062..788445d88 100644 --- a/Source/CParse/cscanner.c +++ b/Source/CParse/cscanner.c @@ -610,7 +610,10 @@ int yylex(void) { */ - nexttok = Scanner_token(scan); + do { + nexttok = Scanner_token(scan); + } while (nexttok == SWIG_TOKEN_ENDLINE || nexttok == SWIG_TOKEN_COMMENT); + if (Scanner_isoperator(nexttok)) { /* One of the standard C/C++ symbolic operators */ Append(s,Scanner_text(scan)); @@ -681,6 +684,8 @@ int yylex(void) { Append(s," "); } Append(s,Scanner_text(scan)); + } else if (nexttok == SWIG_TOKEN_ENDLINE) { + } else if (nexttok == SWIG_TOKEN_COMMENT) { } else { Append(s,Scanner_text(scan)); needspace = 0;