Bug 1126043

Summary: GCC 9: yast2-ruby-bindings build fails
Product: [openSUSE] openSUSE Tumbleweed Reporter: Martin Liška <martin.liska>
Component: YaST2Assignee: E-mail List <yast2-maintainers>
Status: RESOLVED FIXED QA Contact: Jiri Srain <jsrain>
Severity: Normal    
Priority: P5 - None CC: aschnell, jreidinger
Version: Current   
Target Milestone: ---   
Hardware: Other   
OS: Other   
Whiteboard:
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---
Bug Depends on:    
Bug Blocks: 1120754    

Description Martin Liška 2019-02-20 08:50:00 UTC
As seen here:
https://build.opensuse.org/package/live_build_log/openSUSE:Factory:Staging:Gcc7/yast2-ruby-bindings/standard/x86_64

there's a test failure:
[   69s] 2:   Float.tolstring
[   69s] 2:     works as expected (FAILED - 1)
[   69s] 2:   toterm
[   69s] 2:     works as expected
[   69s] 2: 
[   69s] 2: Failures:
[   70s] 2: 
[   70s] 2:   1) Yast::Builtins type casting methods Float.tolstring works as expected
[   70s] 2:      Failure/Error: expect(ret).to eq("0,5")
[   70s] 2: 
[   70s] 2:        expected: "0,5"
[   70s] 2:             got: ""
[   70s] 2: 
[   70s] 2:        (compared using ==)
[   70s] 2:      # /home/abuild/rpmbuild/BUILD/yast2-ruby-bindings-4.1.2/tests/builtins_casts_spec.rb:142:in `block (3 levels) in <top (required)>'

One can reproduce that with:
$ osc co openSUSE:Factory/yast2-ruby-bindings
$ osc build  --alternative-project=openSUSE:Factory:Staging:Gcc7

I analyzed that a bit, it started with GCC revision 269004:
https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=269004

which is about a char8_t support in libstdc++.
Comment 1 Steffen Winterfeldt 2019-02-20 15:48:57 UTC
Josef, any idea?
Comment 2 Josef Reidinger 2019-02-20 15:55:07 UTC
affected method is https://github.com/yast/yast-ruby-bindings/blob/master/src/binary/Builtin.cc#L165

Maybe some gcc/glibc guy can check if it is reasonable what we are doing with new gcc. The goal of method is to get localized format of float.
Comment 3 Martin Liška 2019-02-20 20:19:25 UTC
There's some strangeness with the locale. If I replace float_to_lstring with:

  static VALUE
  float_to_lstring(VALUE self, VALUE rfloat, VALUE rprecision)
  {
    std::wostringstream ss; // bnc#683881#c12: need wide chars
    try
    {
	    std::locale l ("cs_CZ.utf-8");
	    cout << "locale is: " << l.name() << endl;
	    ss.imbue (l);
    }
    catch (const std::runtime_error &error)
    {
	    __builtin_abort();
    }

    ss.precision (1);
    ss << 0.1234f;
    std::wstring res = ss.str();
std::wcerr << L"res:" << res << std::endl;
__builtin_abort();

I get:

[100%] Built target py2lang_ruby
.......locale is: cs_CZ.utf-8
res:
F.

So empty string. While a standalone program does  (with latest GCC):

$ cat repro.cc && g++ repro.cc -g && LANG="cs_CZ.utf-8" LANG="cs_CZ.utf-8" ./a.out
#include <sstream>
#include <iostream>

using namespace std;

int main()
{
    std::wostringstream ss; // bnc#683881#c12: need wide chars
    try
    {
	    std::locale l ("cs_CZ.utf-8");
	    cout << "locale is: " << l.name() << endl;
	    ss.imbue (l);
    }
    catch (const std::runtime_error &error)
    {
	    __builtin_abort();
    }

    ss.precision (1);
    ss << 0.1234f;
    std::wstring res = ss.str();
std::wcerr << L"res:" << res << std::endl;


    return 0;
}
locale is: cs_CZ.utf-8
res:0,1
Comment 4 Martin Liška 2019-02-20 20:30:08 UTC
I would simply use:
http://www.cplusplus.com/reference/string/to_wstring/
Comment 5 Arvin Schnell 2019-02-20 21:47:40 UTC
AFAIR the global C++ locale is not set in YaST so to_wstring does not
return the localized string. Setting the global C++ locale is something
that likely needs a lot of testing to avoid regressions.
Comment 6 Josef Reidinger 2019-02-21 08:09:23 UTC
Question is why it works before and start failing now. What changed in gcc?
Comment 7 Josef Reidinger 2019-02-21 08:30:26 UTC
Martin: also in your test example you have fixed locale and also fixed input. I have no idea what can affect it to write no string. I worry we need our gcc experts as for me it looks like bug in gcc that some side effect break owstringstream.
Comment 8 Martin Liška 2019-02-21 09:57:32 UTC
Fixed as I had wrongly:
Ignore: libstdc++6

in project config.