mirror of https://github.com/swig/swig.git
A character constant containing more than one character, e.g. 'ab', has type int per both the C standard (6.4.4.4p10) and the C++ standard ([lex.ccon], which describes it as a "multicharacter literal"). SWIG previously classified every character constant as char regardless of length, which caused the generated wrapper accessor for a constant such as #define X 'ab' to be declared char instead of int, silently truncating the value. The literal text is left untouched (SWIG does not evaluate constant expressions), only the internal type tag changes, so the real compiler that builds the generated wrapper still computes the (implementation defined) value, exactly as it would for hand written C/C++ code. Add a new C-only multichar_constant.i test case with per-language runme files, and keep the new csharp/java char_constant runme files (which had no coverage before) for the existing, unrelated character constant checks. Compiling a real multicharacter constant always triggers GCC's -Wmultichar warning. #pragma GCC diagnostic ignored "-Wmultichar" does not suppress it: this is a known, longstanding GCC C++ front-end bug (gcc.gnu.org PR57241/PR53431, fixed in GCC 13) - verified locally that it fails identically on GCC 11 and 12 regardless of file- or function-level pragma scope, while working fine in C or with GCC 13+ or Clang (which also defines __GNUC__ but doesn't have this bug). The new testcase avoids the warning entirely, with no build system changes needed: - The %inline global variable imulti_ab uses the real literal (guarded by the pragma) wherever that's known to work, and otherwise falls back to reconstructing the identical value GCC's own packing of 'ab' produces (most significant byte first) without writing a multicharacter literal at all - the same symbol name and type either way, so the generated accessor links correctly regardless of which branch was compiled. - The #define-driven MULTICHAR_AB constant (whose registration code is auto-generated per target language, so a similar fallback isn't portable to hand-write once for every language) is skipped entirely for octave and javascript's node/napi/v8 engines, the only configurations that always compile the generated wrapper as C++ regardless of SWIG's own -c/-c++ mode (their runtime APIs require it) and so would otherwise still hit the GCC bug above. Verified against both GCC 13 (default) and GCC 11 (matching the actual CI toolchain that originally failed) across all configured languages. Assisted-by: Claude Code (Sonnet 5) |
||
|---|---|---|
| .. | ||
| Makefile.in | ||
| README | ||
| aggregate_runme.cs | ||
| allprotected_runme.cs | ||
| apply_strings_runme.cs | ||
| argcargvtest_runme.cs | ||
| bools_runme.cs | ||
| catches_runme.cs | ||
| catches_strings_runme.cs | ||
| char_binary_rev_len_runme.cs | ||
| char_binary_runme.cs | ||
| char_constant_runme.cs | ||
| char_strings_runme.cs | ||
| complextest_runme.cs | ||
| constover_runme.cs | ||
| cpp11_constexpr_friend_runme.cs | ||
| cpp11_move_only_runme.cs | ||
| cpp11_move_only_valuewrapper_runme.cs | ||
| cpp11_move_typemaps_runme.cs | ||
| cpp11_rvalue_reference_move_runme.cs | ||
| cpp11_shared_ptr_template_upcast_runme.cs | ||
| cpp11_std_array_runme.cs | ||
| cpp11_std_unique_ptr_runme.cs | ||
| cpp11_std_unordered_map_runme.cs | ||
| cpp11_std_unordered_set_runme.cs | ||
| cpp11_strongly_typed_enumerations_runme.cs | ||
| cpp17_director_string_view_runme.cs | ||
| cpp17_nested_namespaces_runme.cs | ||
| cpp17_nspace_nested_namespaces_runme.cs | ||
| cpp17_string_view_runme.cs | ||
| csharp_argument_defaults_feature_runme.cs | ||
| csharp_attributes_runme.cs | ||
| csharp_director_typemaps_runme.cs | ||
| csharp_exceptions_runme.cs | ||
| csharp_lib_arrays_bool_runme.cs | ||
| csharp_lib_arrays_runme.cs | ||
| csharp_prepost_runme.cs | ||
| csharp_typemaps_runme.cs | ||
| default_args_runme.cs | ||
| default_constructor_runme.cs | ||
| director_alternating_runme.cs | ||
| director_basic_runme.cs | ||
| director_binary_string_rev_len_runme.cs | ||
| director_binary_string_runme.cs | ||
| director_classes_runme.cs | ||
| director_classic_runme.cs | ||
| director_default_runme.cs | ||
| director_ignore_runme.cs | ||
| director_minimal_runme.cs | ||
| director_nspace_runme.cs | ||
| director_pass_by_value_runme.cs | ||
| director_primitives_runme.cs | ||
| director_property_runme.cs | ||
| director_protected_runme.cs | ||
| director_shared_ptr_runme.cs | ||
| director_string_runme.cs | ||
| director_using_member_scopes_runme.cs | ||
| director_void_runme.cs | ||
| director_wstring_runme.cs | ||
| doxygen_basic_translate_runme.cs | ||
| doxygen_checker.cs | ||
| doxygen_interface_runme.cs | ||
| doxygen_nested_class_runme.cs | ||
| doxygen_translate_runme.cs | ||
| enum_forward_runme.cs | ||
| enum_thorough_runme.cs | ||
| enum_thorough_simple_runme.cs | ||
| enum_thorough_typesafe_runme.cs | ||
| exception_order_runme.cs | ||
| friends_runme.cs | ||
| imports_runme.cs | ||
| inherit_target_language_runme.cs | ||
| intermediary_classname_runme.cs | ||
| li_attribute_runme.cs | ||
| li_boost_shared_ptr_bits_runme.cs | ||
| li_boost_shared_ptr_director_runme.cs | ||
| li_boost_shared_ptr_runme.cs | ||
| li_cdata_bytes_cpp_runme.cs | ||
| li_cdata_bytes_runme.cs | ||
| li_cdata_cpp_runme.cs | ||
| li_cdata_runme.cs | ||
| li_constraints_runme.cs | ||
| li_std_auto_ptr_runme.cs | ||
| li_std_combinations_runme.cs | ||
| li_std_except_runme.cs | ||
| li_std_list_runme.cs | ||
| li_std_map_runme.cs | ||
| li_std_set_runme.cs | ||
| li_std_string_runme.cs | ||
| li_std_vector_enum_runme.cs | ||
| li_std_vector_runme.cs | ||
| li_std_wstring_runme.cs | ||
| li_swigtype_inout_runme.cs | ||
| li_typemaps_runme.cs | ||
| long_long_runme.cs | ||
| member_pointer_runme.cs | ||
| multichar_constant_runme.cs | ||
| multiple_inheritance_abstract_runme.cs | ||
| multiple_inheritance_interfaces_runme.cs | ||
| multiple_inheritance_nspace_runme.cs | ||
| multiple_inheritance_overload_runme.cs | ||
| multiple_inheritance_shared_ptr_runme.cs | ||
| nested_class_runme.cs | ||
| nested_directors_runme.cs | ||
| nested_in_template_runme.cs | ||
| nested_inheritance_interface_runme.cs | ||
| nested_structs_runme.cs | ||
| nested_workaround_runme.cs | ||
| nspace_extend_runme.cs | ||
| nspace_interface_runme.cs | ||
| nspace_runme.cs | ||
| nspacemove_nested_runme.cs | ||
| nspacemove_runme.cs | ||
| nspacemove_stl_runme.cs | ||
| operator_overload_runme.cs | ||
| overload_complicated_runme.cs | ||
| overload_template_runme.cs | ||
| pointer_reference_runme.cs | ||
| preproc_constants_c_runme.cs | ||
| preproc_constants_runme.cs | ||
| proxycode_runme.cs | ||
| rename_pcre_encoder_runme.cs | ||
| rename_pcre_enum_runme.cs | ||
| rename_simple_runme.cs | ||
| sizet_runme.cs | ||
| sneaky1_runme.cs | ||
| special_variable_attributes_runme.cs | ||
| special_variable_macros_runme.cs | ||
| string_constants_runme.cs | ||
| template_nested_flat_runme.cs | ||
| template_nested_runme.cs | ||
| threads_runme.cs | ||
| throw_exception_runme.cs | ||
| typemap_namespace_runme.cs | ||
| typemap_out_optimal_runme.cs | ||
| varargs_runme.cs | ||
| virtual_poly_runme.cs | ||
README
SWIG testsuite README file -------------------------- This testsuite is here to ensure SWIG can handle a wide range of c/c++ syntax. The testsuite comprises many testcases in this directory. Each test case is tested under each of the language modules thereby thoroughly testing all of SWIG. It ensures that each of the language modules are at a similar standard. Those modules that support shadow classes run the tests producing shadow classes to test the full language module functionality. Some test cases need a runtime test. These need implementing in each of the language modules. The language modules look for a file in the language specific test-suite directory which has _runme appended after the testcase name. If one is found it will be run as part of the test. Some language modules add to this common set of test cases for language specific tests. These can be found in the appropriate language test-suite directory. There is also a README in each of the language module directories. For each testcase a message showing which testcase is being tested is displayed. Nothing else is printed unless the test fails. Some Developer Guidelines ------------------------- Note that the whole test suite need not be run each time a testcase is modified. An individual testcase may be run by going to the language module test-suite directory and using make testcasename.xxx where xxx is the type of test (eg cpptest). See common.mk. make -s doesn't print any junk on the screen and is useful for emulating the way make check works from the SWIG root directory. If there are runtime tests needed, don't print anything unless there is an error in which case stderr is suggested. Please set the name of the module to the same name as the testcase, otherwise modules will not be found.