Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Cpp23 #4777

Open
Gashmob opened this issue Feb 18, 2025 · 1 comment
Open

Support for Cpp23 #4777

Gashmob opened this issue Feb 18, 2025 · 1 comment

Comments

@Gashmob
Copy link

Gashmob commented Feb 18, 2025

Hi, I use antlr4 cpp target in a project currently with cpp17. There is some features of cpp23 such as https://en.cppreference.com/w/cpp/utility/expected that I want to use which are not available in 17. So I planned to update all my dependencies to meet the requirements and went the turn of antlr. I was already on version 4.13.2 so nothing to except finally upgrading set(CMAKE_CXX_STANDARD 23)

When regenerating then build the parser I got an error:

FilParser.cpp:1064:113: error: non-pointer operand type 'std::string' (aka 'basic_string<char>') incompatible with nullptr
 1064 |               type_name = (antlrcpp::downCast<Variable_declarationContext *>(_localctx)->typeContext != nullptr ? _input->getText(antlrcpp::downCast<Variable_declarationContext *>(_localctx)->typeContext->start, antlrcpp::downCast<Variable_declarationContext *>(_localctx)->typeContext->stop) : nullptr);
      |                                                                                                                 ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This code is in generated parser from this g4 file:

variable_declaration returns[std::shared_ptr<filc::VariableDeclaration> tree]
@init {
    bool is_constant = true;
    std::string type_name;
    std::shared_ptr<filc::Expression> value = nullptr;
}
@after {
    $tree = std::make_shared<filc::VariableDeclaration>(is_constant, $name.text, type_name, value);
}
    : (VAL | VAR {
        is_constant = false;
    }) name=IDENTIFIER (COLON type {
        type_name = $type.text;
    })? (EQ value=expression {
        value = $value.tree;
    })?;

type : IDENTIFIER (STAR | LBRACK INTEGER RBRACK)?;

I don't know if there is a simple way to fix this. If not, is it planned to fully support cpp23 for the generated code?

@kaby76
Copy link
Contributor

kaby76 commented Feb 18, 2025

Hi @Gashmob Yeah there is no easy fix. My plan is to scape the grammar from the spec which I have a copy of. I have a program that scapes the C++ spec pdfs and outputs a grammar. Not sure when I'll get the time to fix it though. Ken

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants