Experience with g++ 4.8 and -frepo?

David Kastrup dak@gnu.org
Wed Aug 27 12:54:00 GMT 2014


Jonathan Wakely <jwakely@redhat.com> writes:

> On 27/08/14 14:18 +0200, David Kastrup wrote:
>> At any rate, I need to tell all compilation units that a specialization
>>exists, and of course I can only define it in one compilation unit.
>
> So declare it wherever needed (e.g. by putting it in a header):
>
> template <> const char * Smob_base<Grob>::type_p_name;
>
> And define it exactly once:
>
> template <> const char * Smob_base<Grob>::type_p_name = "ly:grob?";

I'm pretty sure that that's just what I did last iteration around and it
got me into more problems, consequently my question here.

I am basically converting a code base implementing some quasi-template
mechanism via the C preprocessor into C++ templates by shell-script/sed.

The respective passage currently looks like

git grep '^IMPLEMENT_TYPE_P' lily|sed -n 's/^\([^:]\+\):IMPLEMENT_TYPE_P (\([^,]*\), \("[^"]*"\));\s*/\1 \2 \3/p'|
    while read file class pred
    do
	echo "Implement predicate $pred for $class in $file" >&2
	sed -i '/^IMPLEMENT_TYPE_P/c\
template <> const char * Smob_base<'"$class"'>::type_p_name = '"$pred"';' "$file"
# 	for i in $(git grep -l '^\(class\|struct\)\s\+'"$class"'\s' lily)
# 	do
# 	    sed -i -n '1h
# 1!H
# ${g
#   s/^\(class\|struct\)\s\+'"$class"'\s\([^}].*\n\+\)\+};$/&\n\ntemplate <> extern const char * Smob_base<'"$class"'>::type_p_name;\n/gm
#   p
#   d}' "$i"
# 	done
    done

and the outcommented passage adding a declaration to the class
definition itself went through a number of different iterations with
different bad results.  I'm pretty sure I had your suggestion in it as
well but I definitely will give it another round.

That's just for information.

>> And I was surprised that the respective incantations appear to exist
>>only starting with C++11, with GCC providing them in C++98 mode
>>already.  I mean, template specializations are in C++ how long now?
>>20 years or so?  How did people manage before C++11?
>
> I assume you're talking about the "extern template" syntax?

I think so...

> Every major compiler implemented that more than a decade ago, it just
> didn't make it into a standard until 2011.

Ok.

> But that syntax is for declaring explicit instantiations, not
> specializations. What you need is valid in C++98.

Ok.  Once I get this thing through _without_ const, I'll try the version
_with_ const and see whether this indeed gets me rid of the optimization
problem too.  After all, it's quite plausible that the optimizer might
confuse const on a generic definition with a promise that the value will
not get switched for a different constant by a specialization when the
actual specialization is only visible in a different compilation unit.

>>At any rate, g++ -frepo appears to get me rid of that inconsistent
>>specialization problem at the cost of tripping up libstdc++ usage
>>(which never was problematic without -frepo).  Sometimes I wonder
>>whether I am the only one using some software...  But maybe -frepo was
>>pretty new in g++-4.8.
>
> No, -frepo is ancient and bit-rotted and noone uses it now.

Ah, good to know.  So there is no point in working towards getting the
project codebase to work with -frepo.  That's definitely useful
information that I was lacking before, and that was not to be gleaned
from the GCC info page.

Thanks!

-- 
David Kastrup



More information about the Libstdc++ mailing list