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

            Bug ID: 67565
           Summary: [concepts] Very slow compile time and high memory
                    usage with complex concept definitions, even if unused
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: adrian.wielgosik at gmail dot com
  Target Milestone: ---

Example:

template <class T>
concept bool Constructible() {
        return false ||
                requires (T t) {
                        { t.~T() } noexcept;
                };
}

template <class T>
concept bool Semiregular() {
        return
                Constructible<T>() &&
                Constructible<T>() &&
                Constructible<T>() &&
                Constructible<T>() &&
                Constructible<T>() &&
                Constructible<T>() &&
                Constructible<T>();
}

template <class T, class I>
concept bool Sentinel() {
        return Semiregular<T>() && Semiregular<I>();
}

template<Semiregular I, Sentinel<I> S>
void func(I first, S last) { }

int main(){}


time ./g++trunk -std=c++1z main.cpp

real    0m8.855s
user    0m7.887s
sys     0m0.896s

It also consumed over 2GB of RAM at peak. Note that the function which checks
for concepts wasn't even called, so no actual concept checks were done.

Simplifying this case any more, like removing "false ||", fixes the problem.

A big chain of "Constructible<T>() &&" may look strange, but it's just a
simplified case - originally I tried to rewrite concepts from Eric Niebler's
Ranges proposal, which could check the same concept multiple times.

Reply via email to