Add missing explicit instantiation for std::lower_bound template

Message ID 20130211165525.7e2a9fd0@oakwood
State New
Headers show

Commit Message

Benjamin Kosnik Feb. 12, 2013, 12:55 a.m.
> >> Since commit r195676[1], it looks like
> >> libstdc++-v3/src/c++11/ is missing an explicit
> >> instantiation for std::lower_bound. 
it's missing an implicit instantiation of std::lower_bound.

>>This leads to
> >> having the symbol for that (missing) instantiation be undefined,
> >> thus preventing executables from being linked with libstdc++.
> > Note that I can confirm this only if I build with less optimization
> > than the default -O2, say -O. That may explain why nobody noticed
> > earlier.

Yes, indeed.

Certainly, the explicit instantiation is ok for this non-usual -O
compile. The full instantiation set depends on specific flag and
perhaps platform. Let's not special case all of these, and instead just
allow implicit template instantiations via -fimplicit-templates. 

Thus, what is really needed (and also in cases like PR52887)
is to just allow implicit template instantiations. Done as attached.


tested x86/linux
tested x86/linux -O0
tested x86/linux -O


2013-02-11  Benjamin Kosnik  <>

	    * src/c++11/ (hashtable_c++0x.lo, hashtable_c++0x.o):
	    Use -fimplicit-templates.
	    * src/c++11/ Regenerate.
	    * src/c++11/ Remove instantiation for
	    std::lower_bound template.

diff --git a/libstdc++-v3/src/c++11/ b/libstdc++-v3/src/c++11/
index 89ee335..e7b48ac 100644
--- a/libstdc++-v3/src/c++11/
+++ b/libstdc++-v3/src/c++11/
@@ -60,6 +60,13 @@  vpath % $(top_srcdir)/src/c++11
 libc__11convenience_la_SOURCES = $(sources)  $(inst_sources)
+# Use special rules for the file so that all
+# the generated template functions are also instantiated. 
+	$(LTCXXCOMPILE) -fimplicit-templates -c $<
+	$(CXXCOMPILE) -fimplicit-templates -c $<
 # AM_CXXFLAGS needs to be in each subdirectory so that it can be
 # modified in a per-library or per-sub-library way.  Need to manually
 # set this option because CONFIG_CXXFLAGS has to be after
diff --git a/libstdc++-v3/src/c++11/ b/libstdc++-v3/src/c++11/
index b6a56bc..7617c58 100644
--- a/libstdc++-v3/src/c++11/
+++ b/libstdc++-v3/src/c++11/
@@ -94,11 +94,4 @@  namespace __detail
 } // namespace __detail
- // Instantiations.
- template
- const unsigned long*
- lower_bound<const unsigned long*, size_t>(const unsigned long*,
-					   const unsigned long*,
-					   const size_t&);
 } // namespace std