From 2bef458dc1d46f2d773d952462095b0d5162d210 Mon Sep 17 00:00:00 2001 From: Daniel Gerlanc Date: Wed, 11 May 2022 16:17:26 -0400 Subject: [PATCH] Fix C++11 narrowing error on MacOS Resolves #127 --- aesara/link/c/cmodule.py | 6 ++++++ tests/link/c/test_cmodule.py | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/aesara/link/c/cmodule.py b/aesara/link/c/cmodule.py index 02b4e0f11b..cd8531be52 100644 --- a/aesara/link/c/cmodule.py +++ b/aesara/link/c/cmodule.py @@ -2363,6 +2363,12 @@ def join_options(init_part): # Use the already-loaded python symbols. cxxflags.extend(["-undefined", "dynamic_lookup"]) + # Resolves C++11 narrowing error on Mac OS + # https://github.com/aesara-devs/aesara/issues/127 + no_cpp_narrowing_flag = "-Wno-c++11-narrowing" + if no_cpp_narrowing_flag not in cxxflags: + cxxflags.append(no_cpp_narrowing_flag) + if sys.platform == "win32": # Workaround for https://github.com/Theano/Theano/issues/4926. # https://github.com/python/cpython/pull/11283/ removed the "hypot" diff --git a/tests/link/c/test_cmodule.py b/tests/link/c/test_cmodule.py index 6fef007537..5187530e65 100644 --- a/tests/link/c/test_cmodule.py +++ b/tests/link/c/test_cmodule.py @@ -263,3 +263,19 @@ def f_build(factor): assert not any( exit_code != 0 for exit_code in [proc.exitcode for proc in procs] ) + + +@patch("sys.platform", "darwin") +def test_osx_narrowing_compile_args(): + no_narrowing_flag = "-Wno-c++11-narrowing" + assert no_narrowing_flag in GCC_compiler.compile_args() + + cxxflags = f"{aesara.config.gcc__cxxflags} {no_narrowing_flag}" + with aesara.config.change_flags(gcc__cxxflags=cxxflags): + print(cxxflags) + res = GCC_compiler.compile_args() + print(res) + flag_idx = res.index(no_narrowing_flag) + # Make sure it's not in there twice + with pytest.raises(ValueError): + res.index(no_narrowing_flag, flag_idx + 1)