Skip to content

Error parsing CXXDeductionGuide #1791

@deadlocklogic

Description

@deadlocklogic

Consider:

using CppSharp;
using CppSharp.AST;
using CppSharp.Parser;

class Program
{
    class TestLibrary : ILibrary
    {
        public void SetupPasses(Driver driver)
        {
        }

        public void Preprocess(Driver driver, ASTContext ctx)
        {
        }

        public void Postprocess(Driver driver, ASTContext ctx)
        {
        }

        public void Setup(Driver driver)
        {
            DriverOptions driverOptions = driver.Options;
            ParserOptions parserOptions = driver.ParserOptions;

            parserOptions.LanguageVersion = LanguageVersion.CPP17;
            parserOptions.AddCompilationOptions("-frtti");

            driverOptions.Quiet = false;
            driverOptions.DryRun = true;
            driverOptions.OutputDir = Directory.GetCurrentDirectory();

            var module = driverOptions.AddModule("test");

            string temp = Path.GetTempFileName();
            File.WriteAllText(temp, @"
template<class T>
struct container
{
    container(T t) {}
 
    template<class Iter>
    container(Iter beg, Iter end);
};
 
// additional deduction guide
template<class Iter>
container(Iter b, Iter e) -> container<typename std::iterator_traits<Iter>::value_type>;
");

            module.Headers.Add(temp);

        }
    }

    static void Main(string[] args)
    {
        ConsoleDriver.Run(new TestLibrary());
    }
}

Output:

Parsing libraries...
Parsing code...
Unhandled declaration kind: CXXDeductionGuide
  C:\Users\user\AppData\Local\Temp\tmp6CC2.tmp (line 5)
Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Repeat 2 times:
--------------------------------
   at CppSharp.Parser.ClangParser+__Internal.ParseHeader(IntPtr)
--------------------------------
   at CppSharp.Parser.ClangParser.ParseHeader(CppSharp.Parser.CppParserOptions)
   at CppSharp.ClangParser.ParseSourceFiles(System.Collections.Generic.IEnumerable`1<System.String>, CppSharp.Parser.ParserOptions)
   at CppSharp.Driver.ParseCode()
   at CppSharp.ConsoleDriver.Run(CppSharp.ILibrary)
   at Program.Main(System.String[])

Second question:

How to include a precompiled header?
Because when <cassert> is included in a precompiled header I am getting:

error: use of undeclared identifier 'assert'
CppSharp has encountered an error while parsing code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions