[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#34789: Scan of regexp mistakes

From: Davis Herring
Subject: bug#34789: Scan of regexp mistakes
Date: Fri, 8 Mar 2019 13:46:38 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0

But I'd like first to hear in more detail why "C++ compilers haven't
worked that way for any standard library type (and most user-defined
types) in a very long time."  We should at least have this information
recorded here for posterity.

The situation in question (based on the comments in mantemp.el) concerns code like

  int main() {
    std::vector<double> v(1);
    return *v.begin();  // 0

where, once upon a time, the compiler would emit undefined references to functions like "std::vector<double>::begin()" that had to be explicitly instantiated (in a single translation unit chosen by the user). (The age of this era is indicated by the missing "std::" in the example error messages.)

In all compilers newer than about 2003, such functions are automatically _generated_ when used, so that there are no undefined references (and no need to manually request instantiation). It is still _possible_ to instantiate things this way for performance reasons in certain complicated cases, but you have to ask for it:

  // foo.hxx
  #ifndef FOO_HXX
  #define FOO_HXX
  struct A {};    // a user-defined type must be involved
  extern template class std::vector<A>;  // block implicit instantiation

  // templates.cxx
  // The one shared instantiation, as mantemp.el could generate:
  template class std::vector<A>;

  // client.cxx
  vector<A> gv;       // relies on templates.cxx

  // possibly more clients...

  // main.cxx
  int main() {
    vector<A> v;      // relies on templates.cxx
    return v.size();

(This is C++11 code; in C++03, only user-defined types can be made to behave this way, and it's harder.)

This style of code is rare, and will if anything become rarer still in C++20, when code in a header file that uses a particular specialization (e.g., std::vector<A>) can be put into a module that is compiled only once. Even if someone were doing this, mantemp.el could at most generate the one indicated line in templates.cxx _after_ the very similar line in foo.hxx was added in some other fashion.

Hope this helps clarify,

This product is sold by volume, not by mass. If it appears too dense or too sparse, it is because mass-energy conversion has occurred during shipping.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]