This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of CD1 status.

### 228. Incorrect specification of "..._byname" facets

Section: 28.4 [locale.categories] Status: CD1 Submitter: Dietmar Kühl Opened: 2000-04-20 Last modified: 2018-08-10

Priority: Not Prioritized

View all other issues in [locale.categories].

View all issues with CD1 status.

Discussion:

The sections 28.4.2.3 [locale.ctype.byname], 28.4.2.6 [locale.codecvt.byname], 28.4.4.2 [locale.numpunct.byname], 28.4.5.2 [locale.collate.byname], 28.4.6.5 [locale.time.put.byname], 28.4.7.5 [locale.moneypunct.byname], and 28.4.8.3 [locale.messages.byname] overspecify the definitions of the "..._byname" classes by listing a bunch of virtual functions. At the same time, no semantics of these functions are defined. Real implementations do not define these functions because the functional part of the facets is actually implemented in the corresponding base classes and the constructor of the "..._byname" version just provides suitable date used by these implementations. For example, the 'numpunct' methods just return values from a struct. The base class uses a statically initialized struct while the derived version reads the contents of this struct from a table. However, no virtual function is defined in 'numpunct_byname'.

For most classes this does not impose a problem but specifically for 'ctype' it does: The specialization for 'ctype_byname<char>' is required because otherwise the semantics would change due to the virtual functions defined in the general version for 'ctype_byname': In 'ctype<char>' the method 'do_is()' is not virtual but it is made virtual in both 'ctype<cT>' and 'ctype_byname<cT>'. Thus, a class derived from 'ctype_byname<char>' can tell whether this class is specialized or not under the current specification: Without the specialization, 'do_is()' is virtual while with specialization it is not virtual.

Proposed resolution:

Change section 22.2.1.2 (lib.locale.ctype.byname) to become:

         namespace std {
           template <class charT>
           class ctype_byname : public ctype<charT> {
           public:
             typedef ctype<charT>::mask mask;
             explicit ctype_byname(const char*, size_t refs = 0);
           protected:
            ~ctype_byname();             //  virtual
           };
         }

Change section 22.2.1.6 (lib.locale.codecvt.byname) to become:

        namespace std {
          template <class internT, class externT, class stateT>
          class codecvt_byname : public codecvt<internT, externT, stateT> {
          public:
           explicit codecvt_byname(const char*, size_t refs = 0);
          protected:
          ~codecvt_byname();             //  virtual
           };
         }

Change section 22.2.3.2 (lib.locale.numpunct.byname) to become:

         namespace std {
           template <class charT>
           class numpunct_byname : public numpunct<charT> {
         //  this class is specialized for  char  and  wchar_t.
           public:
             typedef charT                char_type;
             typedef basic_string<charT>  string_type;
             explicit numpunct_byname(const char*, size_t refs = 0);
           protected:
            ~numpunct_byname();          //  virtual
           };
         }

Change section 22.2.4.2 (lib.locale.collate.byname) to become:

         namespace std {
           template <class charT>
           class collate_byname : public collate<charT> {
           public:
             typedef basic_string<charT> string_type;
             explicit collate_byname(const char*, size_t refs = 0);
           protected:
            ~collate_byname();           //  virtual
           };
         }

Change section 22.2.5.2 (lib.locale.time.get.byname) to become:

         namespace std {
           template <class charT, class InputIterator = istreambuf_iterator<charT> >
           class time_get_byname : public time_get<charT, InputIterator> {
           public:
             typedef time_base::dateorder dateorder;
             typedef InputIterator        iter_type

             explicit time_get_byname(const char*, size_t refs = 0);
           protected:
            ~time_get_byname();          //  virtual
           };
         }

Change section 22.2.5.4 (lib.locale.time.put.byname) to become:

         namespace std {
           template <class charT, class OutputIterator = ostreambuf_iterator<charT> >
           class time_put_byname : public time_put<charT, OutputIterator>
           {
           public:
             typedef charT          char_type;
             typedef OutputIterator iter_type;

             explicit time_put_byname(const char*, size_t refs = 0);
           protected:
            ~time_put_byname();          //  virtual
           };
         }"

Change section 22.2.6.4 (lib.locale.moneypunct.byname) to become:

         namespace std {
           template <class charT, bool Intl = false>
           class moneypunct_byname : public moneypunct<charT, Intl> {
           public:
             typedef money_base::pattern pattern;
             typedef basic_string<charT> string_type;

             explicit moneypunct_byname(const char*, size_t refs = 0);
           protected:
            ~moneypunct_byname();        //  virtual
           };
         }

Change section 22.2.7.2 (lib.locale.messages.byname) to become:

         namespace std {
           template <class charT>
           class messages_byname : public messages<charT> {
           public:
             typedef messages_base::catalog catalog;
             typedef basic_string<charT>    string_type;

             explicit messages_byname(const char*, size_t refs = 0);
           protected:
            ~messages_byname();          //  virtual
           };
         }

Remove section 28.4.2.5 [locale.codecvt] completely (because in this case only those members are defined to be virtual which are defined to be virtual in 'ctype<cT>'.)

[Post-Tokyo: Dietmar Kühl submitted this issue at the request of the LWG to solve the underlying problems raised by issue 138.]

[Copenhagen: proposed resolution was revised slightly, to remove three last virtual functions from `messages_byname`.]