Error parsing CXXDeductionGuide

Open
#1,791 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
cpp, csharp
Domain
compilers, tooling

Research direction

Start with the C++17 reproduction in the issue, focusing on the CXXDeductionGuide diagnostic and the resulting parser crash. Then investigate the separate precompiled-header case involving and the undeclared assert error. Done means the deduction-guide input no longer crashes parsing and the precompiled-header behavior is understood or corrected.

Written by the indexing model from the issue text.

Description

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.
Dominant language
C#
Stars
3.4k
Forks
541
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from mono/CppSharp

All issues in mono/CppSharp

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.