Skip to content

C++ STL backend: compilation error because of std::to_string #534

Closed

Description

@Commelina

Issue info

It seems that the code generated by the --cpp backend does not compile:

test.y: In function ‘void test_error(YYLTYPE*, yyscan_t, YYSTYPE*, const char*)’:
test.y:224:37: error: ‘to_string’ is not a member of ‘std’
  224 |     error_msg += " at line " + std::to_string(loc->first_line) +
      |                                     ^~~~~~~~~
test.y:224:37: note: ‘std::to_string’ is only available from C++17 onwards
test.y:225:37: error: ‘to_string’ is not a member of ‘std’
  225 |                  ", column " + std::to_string(loc->first_column);
      |                                     ^~~~~~~~~
test.y:225:37: note: ‘std::to_string’ is only available from C++17 onwards

This problem only appears on BNFC 2.9.6.2 and earlier versions work normally.

Reproduction

Using BNFC 2.9.6.2, pick any valid test.cf definition and run

bnfc --cpp -m test.cf && make

Misc

The Makefile generated by the C++ backend uses --ansi for compilation, and std::to_string is invalid with it. And it seems to be introduced by #494 .

Also, I found the issue when I was running the bnfc-system-tests. It seems that this test is not enabled by default and lacks up-to-date running scripts. I am doing some minor improvements on it (still WIP), see Commelina@24acb54.

Activity

  1. added 3 commits that reference this issue on Mar 5, 2026
    d6fac94
    1cda0f1
    492cd95
  2. added a commit that references this issue on Mar 12, 2026
    c2a4003
  3. added this to the 2.9.6.3 milestone on Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions