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

            Bug ID: 125969
           Summary: Explicit instantiations for std::string are disabled
                    by -D_GLIBCXX_ASSERTIONS
           Product: gcc
           Version: 16.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

The libstdc++ c++config.h does this:

// Disable std::string explicit instantiation declarations in order to assert.
#ifdef _GLIBCXX_ASSERTIONS
# undef _GLIBCXX_EXTERN_TEMPLATE
# define _GLIBCXX_EXTERN_TEMPLATE -1
#endif

This ensures that hardened preconditions are checked, because otherwise we use
the explicit instantiations of std::string, which are typically compiled
without assertions.

But since r15-4208-g361d230fd7800a we define _GLIBCXX_ASSERTIONS by default at
-O0, which means that we disable the explicit instantiations by default. This
makes compilation slower.

It's unfortunate that you have to choose between two good things: safer code
due to precondition checks, and faster compilations due to explicit
instantiations.

We should at least document this interaction.

Reply via email to