antlr4: C++ runtime demo fails to build

In the current state of the master branch (dd623ec), the C++ runtime demo fails to build:

$ cd <snip>/runtime/Cpp
$ mkdir build && mkdir run && cd build
$ cmake .. -DANTLR_JAR_LOCATION=<snip>/antlr-4.9.3-complete.jar -DWITH_DEMO=True
$ make
...
[ 97%] Building CXX object demo/CMakeFiles/antlr4-demo.dir/Linux/main.cpp.o
In file included from /home/felix/src/antlr4/runtime/Cpp/demo/Linux/main.cpp:16:
/home/felix/src/antlr4/runtime/Cpp/demo/generated/TLexer.h:57:43: error: ‘virtual const std::vector<std::__cxx11::basic_string<char> >& antlrcpptest::TLexer::getTokenNames() const’ marked ‘override’, but does not override
   57 |   virtual const std::vector<std::string>& getTokenNames() const override; // deprecated, use vocabulary instead
      |                                           ^~~~~~~~~~~~~
In file included from /home/felix/src/antlr4/runtime/Cpp/demo/Linux/main.cpp:17:
/home/felix/src/antlr4/runtime/Cpp/demo/generated/TParser.h:44:43: error: ‘virtual const std::vector<std::__cxx11::basic_string<char> >& antlrcpptest::TParser::getTokenNames() const’ marked ‘override’, but does not override
   44 |   virtual const std::vector<std::string>& getTokenNames() const override { return _tokenNames; }; // deprecated: use vocabulary instead.
      |                                           ^~~~~~~~~~~~~
make[2]: *** [demo/CMakeFiles/antlr4-demo.dir/build.make:97: demo/CMakeFiles/antlr4-demo.dir/Linux/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:414: demo/CMakeFiles/antlr4-demo.dir/all] Error 2
make: *** [Makefile:166: all] Error 2

There’s also a new warning:

[ 12%] Building CXX object runtime/CMakeFiles/antlr4_shared.dir/src/Vocabulary.cpp.o
/home/felix/src/antlr4/runtime/Cpp/runtime/src/Vocabulary.cpp: In static member function ‘static void antlr4::dfa::Vocabulary::__static_initialization_and_destruction_0(int, int)’:
/home/felix/src/antlr4/runtime/Cpp/runtime/src/Vocabulary.cpp:12:18: warning: ‘antlr4::dfa::Vocabulary::EMPTY_VOCABULARY’ is deprecated: Use the default constructor of Vocabulary instead. [-Wdeprecated-declarations]
   12 | const Vocabulary Vocabulary::EMPTY_VOCABULARY;
      |                  ^~~~~~~~~~
/home/felix/src/antlr4/runtime/Cpp/runtime/src/Vocabulary.cpp:12:18: note: declared here

@jcking / @mike-lischke - I’m naively assuming this is related to one of your recent PRs. Could you please take a look? I haven’t spent the time to narrow down when exactly the error was introduced, but I can if you want me to.

Versions:

-- The C compiler identification is GNU 11.2.1
-- The CXX compiler identification is GNU 11.2.1

$ gcc --version
gcc (GCC) 11.2.1 20211203 (Red Hat 11.2.1-7)

$ java --version
openjdk 11.0.13 2021-10-19
OpenJDK Runtime Environment 18.9 (build 11.0.13+8)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.13+8, mixed mode, sharing)

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 1
  • Comments: 15 (7 by maintainers)

Commits related to this issue

Most upvoted comments

Probably not related, but I got this error when running with the CMakeLists.txt in the README:

terminate called after throwing an instance of 'std::system_error'
  what():  Unknown error -1
Aborted

I had to add:

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
...
target_link_libraries(demo Threads::Threads)

@jepperaskdk Thanks for the info. I have a ton of those errors while updating the build for 4.10 in github.com/antlr/grammars-v4.

I was only able to find that because I enabled debugging with set(CMAKE_CXX_FLAGS "-g") and stepped through the code. So I guess that’s also useful to include - but this is also my first CPP project.

Set ANTLR4_TAG to e4c1a74c66bd5290364ea2b36c97cd724b247357, which is the latest stable release 4.9.3.