diff --git a/src/pygccxml/parser/source_reader.py b/src/pygccxml/parser/source_reader.py index d864554b..f64ae4e1 100644 --- a/src/pygccxml/parser/source_reader.py +++ b/src/pygccxml/parser/source_reader.py @@ -121,6 +121,7 @@ def __create_command_line_castxml(self, source_file, xmlfile): "your xml_generator_configuration_t(), or add it to your " + "pygccxml configuration file.")) + stdcxx_switch = self.__cxx_std.stdcxx # Platform specific options if platform.system() == 'Windows': compilers = ("mingw", "g++", "gcc") @@ -132,29 +133,30 @@ def __create_command_line_castxml(self, source_file, xmlfile): cmd.append('--castxml-cc-gnu ' + self.__config.compiler_path) else: # We are using msvc - cmd.append('--castxml-cc-msvc ' + - '"%s"' % self.__config.compiler_path) if self.__config.compiler == 'msvc9': cmd.append('"-D_HAS_TR1=0"') + cmd.append('--castxml-cc-msvc ') + # msvc uses std:c++XX format instead of std=c++XX + stdcxx_switch = stdcxx_switch.replace('=', ':') else: # On mac or linux, use gcc or clang (the flag is the same) cmd.append('--castxml-cc-gnu ') - if self.__cxx_std.is_implicit: - std_flag = '' - else: - std_flag = ' ' + self.__cxx_std.stdcxx + ' ' + if self.__cxx_std.is_implicit: + std_flag = '' + else: + std_flag = ' ' + stdcxx_switch + ' ' - ccflags = self.__config.ccflags - if std_flag: - ccflags += std_flag + ccflags = self.__config.ccflags + if std_flag: + ccflags += std_flag - if ccflags: - all_cc_opts = self.__config.compiler_path + ' ' + ccflags - cmd.append( - '"(" ' + all_cc_opts + ' ")"') - else: - cmd.append(self.__config.compiler_path) + if ccflags: + all_cc_opts = f'"{self.__config.compiler_path}"' + ' ' + ccflags + cmd.append( + '"(" ' + all_cc_opts + ' ")"') + else: + cmd.append(f'"{self.__config.compiler_path}"') if self.__config.castxml_epic_version is not None: if self.__config.castxml_epic_version != 1: diff --git a/unittests/data/cpp_standard_17.hpp b/unittests/data/cpp_standard_17.hpp new file mode 100644 index 00000000..b336a9aa --- /dev/null +++ b/unittests/data/cpp_standard_17.hpp @@ -0,0 +1,9 @@ +// Copyright 2014-2017 Insight Software Consortium. +// Copyright 2004-2009 Roman Yakovenko. +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// See https://github.com/CastXML/pygccxml/issues/180 +// variant introduced in C++17 +#include +std::variant value; diff --git a/unittests/test_cpp_standards.py b/unittests/test_cpp_standards.py index 1eb5a3fb..711922fa 100644 --- a/unittests/test_cpp_standards.py +++ b/unittests/test_cpp_standards.py @@ -48,6 +48,15 @@ def test(self): RuntimeError, lambda: parser.parse(["cpp_standards.hpp"], self.config)) + def test_cpp17(self): + """ + Test c++17 by setting cflags. + + """ + + self.config.cflags = "-std=c++17" + parser.parse(["cpp_standard_17.hpp"], self.config) + def create_suite(): suite = unittest.TestSuite()