diff --git a/src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/Std-symbols.cpp b/src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/Std-symbols.cpp index afec4971..53a66148 100644 --- a/src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/Std-symbols.cpp +++ b/src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/Std-symbols.cpp @@ -4,7 +4,7 @@ #include template __declspec(dllexport) std::allocator::allocator() noexcept; -template __declspec(dllexport) std::basic_string, std::allocator>::basic_string() noexcept; +template __declspec(dllexport) std::basic_string, std::allocator>::basic_string() noexcept(true); template __declspec(dllexport) std::basic_string, std::allocator>::~basic_string() noexcept; template __declspec(dllexport) std::basic_string, std::allocator>& std::basic_string, std::allocator>::assign(const char* const); template __declspec(dllexport) const char* std::basic_string, std::allocator>::data() const noexcept; diff --git a/src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/Std-symbols.cpp b/src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/Std-symbols.cpp index afec4971..53a66148 100644 --- a/src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/Std-symbols.cpp +++ b/src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/Std-symbols.cpp @@ -4,7 +4,7 @@ #include template __declspec(dllexport) std::allocator::allocator() noexcept; -template __declspec(dllexport) std::basic_string, std::allocator>::basic_string() noexcept; +template __declspec(dllexport) std::basic_string, std::allocator>::basic_string() noexcept(true); template __declspec(dllexport) std::basic_string, std::allocator>::~basic_string() noexcept; template __declspec(dllexport) std::basic_string, std::allocator>& std::basic_string, std::allocator>::assign(const char* const); template __declspec(dllexport) const char* std::basic_string, std::allocator>::data() const noexcept; diff --git a/src/Generator.Tests/AST/TestAST.cs b/src/Generator.Tests/AST/TestAST.cs index c2c2b05d..4bdac838 100644 --- a/src/Generator.Tests/AST/TestAST.cs +++ b/src/Generator.Tests/AST/TestAST.cs @@ -495,12 +495,21 @@ namespace CppSharp.Generator.Tests.AST [Test] public void TestFunctionSpecifications() { - var constExprNoExcept = AstContext.FindFunction("constExprNoExcept").First(); - Assert.IsTrue(constExprNoExcept.IsConstExpr); - var functionType = (FunctionType) constExprNoExcept.FunctionType.Type; - Assert.That(functionType.ExceptionSpecType, + var constExpr = AstContext.FindFunction("constExpr").First(); + Assert.IsTrue(constExpr.IsConstExpr); + + var noExcept = AstContext.FindFunction("noExcept").First(); + Assert.That(((FunctionType) noExcept.FunctionType.Type).ExceptionSpecType, Is.EqualTo(ExceptionSpecType.BasicNoexcept)); + var noExceptTrue = AstContext.FindFunction("noExceptTrue").First(); + Assert.That(((FunctionType) noExcept.FunctionType.Type).ExceptionSpecType, + Is.EqualTo(ExceptionSpecType.NoexceptTrue).Or.EqualTo(ExceptionSpecType.BasicNoexcept)); + + var noExceptFalse = AstContext.FindFunction("noExceptFalse").First(); + Assert.That(((FunctionType) noExcept.FunctionType.Type).ExceptionSpecType, + Is.EqualTo(ExceptionSpecType.NoexceptFalse).Or.EqualTo(ExceptionSpecType.BasicNoexcept)); + var regular = AstContext.FindFunction("testSignature").First(); Assert.IsFalse(regular.IsConstExpr); var regularFunctionType = (FunctionType) regular.FunctionType.Type; diff --git a/src/Generator/Generators/C/CppTypePrinter.cs b/src/Generator/Generators/C/CppTypePrinter.cs index 310989a9..c63cfa71 100644 --- a/src/Generator/Generators/C/CppTypePrinter.cs +++ b/src/Generator/Generators/C/CppTypePrinter.cs @@ -423,10 +423,24 @@ namespace CppSharp.Generators.C method.OperatorKind == CXXOperatorKind.ExplicitConversion ? $"operator {method.OriginalReturnType.Visit(this)}" : method.OriginalName; - var exceptionType = - functionType.ExceptionSpecType == ExceptionSpecType.BasicNoexcept || - functionType.ExceptionSpecType == ExceptionSpecType.NoexceptTrue ? - " noexcept" : string.Empty; + + string exceptionType; + switch (functionType.ExceptionSpecType) + { + case ExceptionSpecType.BasicNoexcept: + exceptionType = " noexcept"; + break; + case ExceptionSpecType.NoexceptFalse: + exceptionType = " noexcept(false)"; + break; + case ExceptionSpecType.NoexceptTrue: + exceptionType = " noexcept(true)"; + break; + // TODO: research and handle the remaining cases + default: + exceptionType = string.Empty; + break; + } return $"{returnType}{@class}::{name}({@params}){@const}{exceptionType}"; } diff --git a/tests/Native/AST.h b/tests/Native/AST.h index 41dc2db2..57a19339 100644 --- a/tests/Native/AST.h +++ b/tests/Native/AST.h @@ -204,7 +204,10 @@ typedef ForwardedTemplate l; template class TestSpecializationArguments; -constexpr void constExprNoExcept() noexcept; +constexpr void constExpr(); +void noExcept() noexcept; +void noExceptTrue() noexcept(true); +void noExceptFalse() noexcept(false); template bool functionWithSpecInfo(const T1& t11, const T1& t12, const T2& t2);