https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86441

            Bug ID: 86441
           Summary: instantiate_class_template() unable to re-execute
                    constexpr function
           Product: gcc
           Version: 8.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: boris at kolpackov dot net
  Target Milestone: ---

I have a GCC plugin (ODB) that calls instantiate_class_template() to
"post-instantiate" some types that haven't been instantiated during parsing.
The code is pretty much identical to what complete_type() does to class
templates. This has been working pretty well since the GCC 4.5 days.

This also generally works in GCC 8 except it seems when the instantiation
requires re-execution of a constexpr function. Below are the details of a
specific example of this situation.

The plugin tries to instantiate a type that is declared like this:


#include <map>
#include <string>

using strmap = std::map<std::string, std::string>;


This works fine unless I have a different instantiation of std::map:


#include <map>
#include <string>

using intmap = std::map<int, int>;

struct foo
{
  intmap m;
};

using strmap = std::map<std::string, std::string>;


In this case I get (during the call to instantiate_class_template(strmap)):

/usr/include/c++/8/bits/stl_tree.h: In instantiation of ‘class
std::_Rb_tree<std::__cxx11::basic_string<char>, std::pair<const
std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >,
std::_Select1st<std::pair<const std::__cxx11::basic_string<char>,
std::__cxx11::basic_string<char> > >,
std::less<std::__cxx11::basic_string<char> >, std::allocator<std::pair<const
std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> > > >’:
/usr/include/c++/8/bits/stl_map.h:151:17:   required from ‘class
std::map<std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >’
test.hxx:11:16:   required from here
/usr/include/c++/8/bits/stl_tree.h:452:21: error: non-constant condition for
static assertion
       static_assert(__is_invocable<_Compare&, const _Key&, const _Key&>{},
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/8/bits/stl_tree.h:452: confused by earlier errors, bailing out

If I change stl_tree.h:452 from '__is_invocable<_Compare&, const _Key&, const
_Key&>{}' to '__is_invocable<_Compare&, const _Key&, const _Key&>::value', then
the error goes away. To me this suggests it has something to do we re-executing
(it has already been executed when instantiating intmap) of a constexpr
function (operator bool() in true_type).

Providing a reproducer is challenging since the instantiation is triggered by a
plugin. But let me know if I need to provide any additional information or
test/verify a fix.

Reply via email to