Details

[Home]

Issue of the Implementation # S0730

Brief

messages::do_get always returns an empty string

Detailed Description

The description of the function messages<>::do_get states (22.2.7.1.2):

string_type do_get(catalog cat, int set, int msgid, const string_type& dfault) const

Returns: A message identified by arguments set, msgid, and dfault, according to an implementation-defined mapping. If no such message can be found, returns dfault.


System locales (unlike libstdc++ locales) usually do not have a category that offers functionality corresponding to that of messages facet in libstdc++. The implementation of this facet's methods can be arbitrary. It is possible for the the implementation to be just a stub that does little or nothing. This is the case for the actual implementation of messages<wchar_t> facet: do_open() method can 'open' a message catalog with any name. And do_get() method returns an empty string each time it is used to read messages with arbitrary identifiers from this catalog.
So, it looks like each message corresponds to an empty string in this catalog which does not seem very reasonable.

On the other hand, do_get() method of messages<char> facet is implemented in a different way: while do_open() still opens a catalog with any name, do_get() returns the default string as if the catalog opened with do_open was empty.

It would be more consistent if the methods of messages<wchar_t> facet were implemented the similar way.

The behaviour of messages<wchar_t>::do_get is demonstrated in the sample program below.

Problem location(s) in the standard

Linux Standard Base C++ Specification 3.2, Chapter 9. Libraries, 9.1. Interfaces for libstdcxx that refers ISO/IEC 14882: 2003 Programming languages --C++, section 22.2.7.1.2

Example

#include <iostream>
#include <locale>
using namespace std;

int main()
{
    locale loc;
    
    const messages<wchar_t>& ms = use_facet<messages<wchar_t> >(loc);
    messages_base::catalog cat = ms.open("*", loc);
    if(cat < 0)
    {
        cout << "Cannot open catalog.\n";
        return 0;
    }    
    wstring dfault = L"yes";
    wstring translation = ms.get(cat, 10, 210, dfault);

    if(translation == dfault)
    {
        cout << "get() returns default string.\n";
    }
    else
    {
        cout << "get() returns a string that differs from the default one.\n";
        cout << "Length of the returned string is "
            << translation.size() << ".\n";
    }
    ms.close(cat);
    return 0;
}

Component

libstdc++

Accepted

GCC Bugzilla 13631

[Home]