Skip to content

TestExternal.test_c_unit_test fails on FreeBSD #12634

Open

Description

@AMDmi3

Bug Report

On FreeBSD where clang is the default compiler, one test from mypy testsuite fails: TestExternal.test_c_unit_test, because -std=c++11 flag is set for both C and CXX compilers, but it only applies to C++, and clang refuses to compile C code with it.

=================================== FAILURES ===================================
________________________ TestExternal.test_c_unit_test _________________________

self = <mypyc.test.test_external.TestExternal testMethod=test_c_unit_test>

    @unittest.skipIf(sys.platform.startswith("win"), "rt tests don't work on windows")
    def test_c_unit_test(self) -> None:
        """Run C unit tests in a subprocess."""
        # Build Google Test, the C++ framework we use for testing C code.
        # The source code for Google Test is copied to this repository.
        cppflags: List[str] = []
        env = os.environ.copy()
        if sys.platform == 'darwin':
            cppflags += ['-mmacosx-version-min=10.10', '-stdlib=libc++']
        env['CPPFLAGS'] = ' '.join(cppflags)
        subprocess.check_call(
            ['make', 'libgtest.a'],
            env=env,
            cwd=os.path.join(base_dir, 'mypyc', 'external', 'googletest', 'make'))
        # Build Python wrapper for C unit tests.
        env = os.environ.copy()
        env['CPPFLAGS'] = ' '.join(cppflags)
>       status = subprocess.check_call(
            [sys.executable, 'setup.py', 'build_ext', '--inplace'],
            env=env,
            cwd=os.path.join(base_dir, 'mypyc', 'lib-rt'))

mypyc/test/test_external.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

popenargs = (['/usr/local/bin/python3.8', 'setup.py', 'build_ext', '--inplace'],)
kwargs = {'cwd': '/work/usr/ports/devel/py-mypy/work-py38/mypy-0.940/mypyc/test/../../mypyc/lib-rt', 'env': {'ARCH': 'amd64', 'BATCH': '1', 'BLOCKSIZE': 'K', 'BSD_INSTALL_DATA': 'install  -m 0644', ...}}
retcode = 1
cmd = ['/usr/local/bin/python3.8', 'setup.py', 'build_ext', '--inplace']

    def check_call(*popenargs, **kwargs):
        """Run command with arguments.  Wait for command to complete.  If
        the exit code was zero then return, otherwise raise
        CalledProcessError.  The CalledProcessError object will have the
        return code in the returncode attribute.

        The arguments are the same as for the call function.  Example:

        check_call(["ls", "-l"])
        """
        retcode = call(*popenargs, **kwargs)
        if retcode:
            cmd = kwargs.get("args")
            if cmd is None:
                cmd = popenargs[0]
>           raise CalledProcessError(retcode, cmd)
E           subprocess.CalledProcessError: Command '['/usr/local/bin/python3.8', 'setup.py', 'build_ext', '--inplace']' returned non-zero exit status 1.

/usr/local/lib/python3.8/subprocess.py:364: CalledProcessError
----------------------------- Captured stdout call -----------------------------
c++  -isystem ../include -I.. -O2 -pipe -fstack-protector-strong -fno-strict-aliasing   -g -Wall -Wextra -pthread -fPIC -c  ../src/gtest-all.cc
ar -crsD libgtest.a
running build_ext
building 'test_capi' extension
creating build
creating build/temp.freebsd-13.0-RELEASE-amd64-3.8
cc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -O2 -pipe -fstack-protector-strong -fno-strict-aliasing -O2 -pipe -fstack-protector-strong -fno-strict-aliasing -fPIC -I../external/googletest -I../external/googletest/include -I/usr/local/include/python3.8 -c test_capi.cc -o build/temp.freebsd-13.0-RELEASE-amd64-3.8/test_capi.o -Wno-unused-function -Wno-sign-compare --std=c++11
cc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -O2 -pipe -fstack-protector-strong -fno-strict-aliasing -O2 -pipe -fstack-protector-strong -fno-strict-aliasing -fPIC -I../external/googletest -I../external/googletest/include -I/usr/local/include/python3.8 -c init.c -o build/temp.freebsd-13.0-RELEASE-amd64-3.8/init.o -Wno-unused-function -Wno-sign-compare --std=c++11
----------------------------- Captured stderr call -----------------------------
error: invalid argument '--std=c++11' not allowed with 'C'
error: command 'cc' failed with exit status 1

Full log: https://gist.github.com/7b5fb7d6e43d83e9ccdacf34cddc2dec

To Reproduce

Run tests when clang compiler.

Expected Behavior

Tests pass

Actual Behavior

Tests fail

Your Environment

  • Mypy version used: 0.940
  • Python version used: 3.8
  • Operating system and version: FreeBSD 13.0 amd64, clang 11.0.1

Activity

  1. mcepl commented on Jun 28, 2026

    @mcepl

    I have something similar even with GCC on openSUSE/Factory:

    [ 2566s] gcc -fno-strict-overflow -Wsign-compare -DNDEBUG -fcf-protection -O2 -Wall -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -g -DOPENSSL_LOAD_CONF -fwrapv -fno-semantic-interposition -fcf-protection -O2 -Wall -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -g -IVendor/ -fcf-protection -O2 -Wall -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -g -IVendor/ -O0 -shared -O0 /tmp/tmp98lqky8r/exc_ops.o /tmp/tmp98lqky8r/float_ops.o /tmp/tmp98lqky8r/generic_ops.o /tmp/tmp98lqky8r/init.o /tmp/tmp98lqky8r/int_ops.o /tmp/tmp98lqky8r/list_ops.o /tmp/tmp98lqky8r/pythonsupport.o /tmp/tmp98lqky8r/test_capi.o -L/tmp/tmp98lqky8r -lgtest -o /tmp/tmp98lqky8r/test_capi.cpython-314-x86_64-linux-gnu.so
    [ 2566s] ----------------------------- Captured stderr call -----------------------------
    [ 2566s] In file included from /home/abuild/rpmbuild/BUILD/python-mypy-2.1.0-build/mypy-2.1.0/mypyc/external/googletest/src/gtest-all.cc:43:
    [ 2566s] /home/abuild/rpmbuild/BUILD/python-mypy-2.1.0-build/mypy-2.1.0/mypyc/external/googletest/src/gtest-death-test.cc: In function ‘bool testing::internal::StackGrowsDown()’:
    [ 2566s] /home/abuild/rpmbuild/BUILD/python-mypy-2.1.0-build/mypy-2.1.0/mypyc/external/googletest/src/gtest-death-test.cc:1009:24: warning: ‘dummy’ may be used uninitialized [-Wmaybe-uninitialized]
    [ 2566s]  1009 |   StackLowerThanAddress(&dummy, &result);
    [ 2566s]       |   ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
    [ 2566s] /home/abuild/rpmbuild/BUILD/python-mypy-2.1.0-build/mypy-2.1.0/mypyc/external/googletest/src/gtest-death-test.cc:999:6: note: by argument 1 of type ‘const void*’ to ‘void testing::internal::StackLowerThanAddress(const void*, bool*)’ declared here
    [ 2566s]   999 | void StackLowerThanAddress(const void* ptr, bool* result) {
    [ 2566s]       |      ^~~~~~~~~~~~~~~~~~~~~
    [ 2566s] /home/abuild/rpmbuild/BUILD/python-mypy-2.1.0-build/mypy-2.1.0/mypyc/external/googletest/src/gtest-death-test.cc:1007:7: note: ‘dummy’ declared here
    [ 2566s]  1007 |   int dummy;
    [ 2566s]       |       ^~~~~
    [ 2566s] ar: creating libgtest.a
    [ 2566s] ar: creating libgtest_main.a
    [ 2566s] cc1: warning: command-line option ‘-std=c++11’ is valid for C++/ObjC++ but not for C
    [ 2566s] In file included from /usr/include/assert.h:35,
    [ 2566s]                  from /usr/include/python3.14/Python.h:20,
    [ 2566s]                  from pythoncapi_compat.h:21,
    [ 2566s]                  from exc_ops.c:1:
    [ 2566s] /usr/include/features.h:451:4: warning: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Wcpp]
    [ 2566s]   451 | #  warning _FORTIFY_SOURCE requires compiling with optimization (-O)
    [ 2566s]       |    ^~~~~~~
    [ 2566s] cc1: warning: command-line option ‘-std=c++11’ is valid for C++/ObjC++ but not for C
    [ 2566s] In file included from /usr/include/assert.h:35,
    [ 2566s]                  from /usr/include/python3.14/Python.h:20,
    [ 2566s]                  from float_ops.c:5:
    [ 2566s] /usr/include/features.h:451:4: warning: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Wcpp]
    [ 2566s]   451 | #  warning _FORTIFY_SOURCE requires compiling with optimization (-O)
    [ 2566s]       |    ^~~~~~~
    [ 2566s] cc1: warning: command-line option ‘-std=c++11’ is valid for C++/ObjC++ but not for C
    [ 2566s] In file included from /usr/include/assert.h:35,
    [ 2566s]                  from /usr/include/python3.14/Python.h:20,
    [ 2566s]                  from generic_ops.c:5:
    [ 2566s] /usr/include/features.h:451:4: warning: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Wcpp]
    [ 2566s]   451 | #  warning _FORTIFY_SOURCE requires compiling with optimization (-O)
    [ 2566s]       |    ^~~~~~~
    [ 2566s] cc1: warning: command-line option ‘-std=c++11’ is valid for C++/ObjC++ but not for C
    [ 2566s] In file included from /usr/include/assert.h:35,
    [ 2566s]                  from /usr/include/python3.14/Python.h:20,
    [ 2566s]                  from init.c:1:
    [ 2566s] /usr/include/features.h:451:4: warning: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Wcpp]
    [ 2566s]   451 | #  warning _FORTIFY_SOURCE requires compiling with optimization (-O)
    [ 2566s]       |    ^~~~~~~
    [ 2566s] cc1: warning: command-line option ‘-std=c++11’ is valid for C++/ObjC++ but not for C
    [ 2566s] In file included from /usr/include/assert.h:35,
    [ 2566s]                  from /usr/include/python3.14/Python.h:20,
    [ 2566s]                  from int_ops.c:5:
    [ 2566s] /usr/include/features.h:451:4: warning: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Wcpp]
    [ 2566s]   451 | #  warning _FORTIFY_SOURCE requires compiling with optimization (-O)
    [ 2566s]       |    ^~~~~~~
    [ 2566s] cc1: warning: command-line option ‘-std=c++11’ is valid for C++/ObjC++ but not for C
    [ 2566s] In file included from /usr/include/assert.h:35,
    [ 2566s]                  from /usr/include/python3.14/Python.h:20,
    [ 2566s]                  from list_ops.c:5:
    [ 2566s] /usr/include/features.h:451:4: warning: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Wcpp]
    [ 2566s]   451 | #  warning _FORTIFY_SOURCE requires compiling with optimization (-O)
    [ 2566s]       |    ^~~~~~~
    [ 2566s] cc1: warning: command-line option ‘-std=c++11’ is valid for C++/ObjC++ but not for C
    [ 2566s] In file included from /usr/include/assert.h:35,
    [ 2566s]                  from /usr/include/python3.14/Python.h:20,
    [ 2566s]                  from pythonsupport.h:10,
    [ 2566s]                  from pythonsupport.c:6:
    [ 2566s] /usr/include/features.h:451:4: warning: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Wcpp]
    [ 2566s]   451 | #  warning _FORTIFY_SOURCE requires compiling with optimization (-O)
    [ 2566s]       |    ^~~~~~~
    [ 2566s] In file included from /usr/include/c++/15/x86_64-suse-linux/bits/os_defines.h:39,
    [ 2566s]                  from /usr/include/c++/15/x86_64-suse-linux/bits/c++config.h:2641,
    [ 2566s]                  from /usr/include/c++/15/limits:49,
    [ 2566s]                  from ../external/googletest/include/gtest/gtest.h:54,
    [ 2566s]                  from test_capi.cc:3:
    [ 2566s] /usr/include/features.h:451:4: warning: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Wcpp]
    [ 2566s]   451 | #  warning _FORTIFY_SOURCE requires compiling with optimization (-O)
    [ 2566s]       |    ^~~~~~~
    [ 2566s] In file included from /usr/include/python3.14/Python.h:14,
    [ 2566s]                  from test_capi.cc:4:
    [ 2566s] /usr/include/python3.14/pyconfig.h:2011:9: warning: ‘_POSIX_C_SOURCE’ redefined
    [ 2566s]  2011 | #define _POSIX_C_SOURCE 200809L
    [ 2566s]       |         ^~~~~~~~~~~~~~~
    [ 2566s] /usr/include/features.h:319:10: note: this is the location of the previous definition
    [ 2566s]   319 | # define _POSIX_C_SOURCE        202405L
    [ 2566s]       |          ^~~~~~~~~~~~~~~
    [ 2566s] /usr/include/python3.14/pyconfig.h:2047:9: warning: ‘_XOPEN_SOURCE’ redefined
    [ 2566s]  2047 | #define _XOPEN_SOURCE 700
    [ 2566s]       |         ^~~~~~~~~~~~~
    [ 2566s] /usr/include/features.h:234:10: note: this is the location of the previous definition
    [ 2566s]   234 | # define _XOPEN_SOURCE  800
    [ 2566s]       |          ^~~~~~~~~~~~~
    [ 2566s] Traceback (most recent call last):
    [ 2566s]   File "<string>", line 1, in <module>
    [ 2566s]     import sys, test_capi; sys.exit(test_capi.run_tests())
    [ 2566s]     ^^^^^^^^^^^^^^^^^^^^^
    [ 2566s] ImportError: /tmp/tmp98lqky8r/test_capi.cpython-314-x86_64-linux-gnu.so: undefined symbol: _ZTVN10__cxxabiv120__si_class_type_infoE
    
  2. changed the title [-]Test [/-] [+]TestExternal.test_c_unit_test fails on FreeBSD[/+] on Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions