taocpp / PEGTL

Parsing Expression Grammar Template Library
Boost Software License 1.0
1.95k stars 228 forks source link

[>=3.2.1] Compile error with GCC 9.2 — error: must '#include <typeinfo>' before using 'typeid' #303

Closed hartwork closed 2 years ago

hartwork commented 2 years ago

Hi!

There is a compile error with GCC 9.2 for versions 3.2.1 to 3.2.3 (which happens to break LGTM CI integration for USBGuard). Here's a minimal Dockerfile to reproduce the error:

FROM gcc:9.2
SHELL ["/bin/bash", "-c"]
RUN git clone --branch 3.2.3 https://github.com/taocpp/PEGTL/ &>/dev/null \
        && \
    echo $'#include <tao/pegtl.hpp>\nint main() { return 0; }' | tee main.cxx \
        && \
    g++ -std=c++17 -I PEGTL/include/ main.cxx

Full build log:

# docker build .
Sending build context to Docker daemon  2.048kB
Step 1/3 : FROM gcc:9.2
 ---> 8ecca286b8b8
Step 2/3 : SHELL ["/bin/bash", "-c"]
 ---> Using cache
 ---> 406783aaf129
Step 3/3 : RUN git clone --branch 3.2.3 https://github.com/taocpp/PEGTL/ &>/dev/null         &&     echo $'#include <tao/pegtl.hpp>\nint main() { return 0; }' | tee main.cxx         &&     g++ -std=c++17 -I PEGTL/include/ main.cxx
 ---> Running in d70891f8ae49
#include <tao/pegtl.hpp>
int main() { return 0; }
In file included from PEGTL/include/tao/pegtl.hpp:8,
                 from main.cxx:1:
PEGTL/include/tao/pegtl/demangle.hpp: In function 'constexpr std::string_view tao::pegtl::demangle()':
PEGTL/include/tao/pegtl/demangle.hpp:80:24: error: must '#include <typeinfo>' before using 'typeid'
   12 | #include "internal/dependent_true.hpp"
  +++ |+#include <typeinfo>
   13 | 
......
   80 |       return typeid( T ).name();
      |                        ^
The command '/bin/bash -c git clone --branch 3.2.3 https://github.com/taocpp/PEGTL/ &>/dev/null         &&     echo $'#include <tao/pegtl.hpp>\nint main() { return 0; }' | tee main.cxx         &&     g++ -std=c++17 -I PEGTL/include/ main.cxx' returned a non-zero code: 1

Best, Sebastian

ColinH commented 2 years ago

We could fix the include, however there is a bug in GCC 9.1 and 9.2 that breaks the demangle() function wherefore it simply returns the mangled name. We strongly suggest updating to at least GCC 9.3 to prevent finding mangled class names in error messages generated by the PEGTL.

ColinH commented 2 years ago

@d-frey What do you think, should we add the include -- or "fail early" and #error with GCC 9.1 and 9.2?

d-frey commented 2 years ago

@ColinH I can add it (only when needed and also clean up some other things, like the pessimization of non-MSVC code). How should I proceed? 3.x and main, you take care of evolution?

ColinH commented 2 years ago

OK

d-frey commented 2 years ago

Done. Version 3.2.5 should work as expected.

hartwork commented 2 years ago

Done. Version 3.2.5 should work as expected.

I confirm that 3.2.5 no longer shows this behavior. Thank you! :pray: